0

I am using multipeer connectivity in my application. The user can send any file, such as a png or a recording to another peer. Since the transfer was slow I thought that zipping the data in a zip would speed it up as the size is reduced. I decided to use a framework for this suggested in the second answer to this question:

How can I create a zip file by using Objective C?

The problem is that I need to provide the usl of the file to send it via bluetooth, and I tried doing it in this way:

NSData *file = [NSData dataWithContentsOfURL:imageUrl];

    ZipFile *zipFile= [[ZipFile alloc] initWithFileName:@"file.zip" mode:ZipFileModeCreate];
    ZipWriteStream *stream= [zipFile writeFileInZipWithName:@"abc.txt" compressionLevel:ZipCompressionLevelBest];

    [stream writeData:file];
    [stream finishedWriting];


    NSString *docsDir;
    NSArray *dirPaths;
    dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    docsDir = [dirPaths objectAtIndex:0];
    NSString *databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent:@"file.zip"]];
    [stream writeToFile:databasePath atomically:YES];



    _progressSend = [session sendResourceAtURL: WHAT URL?? withName: info toPeer:peerID withCompletionHandler:^(NSError *error) {
        // Implement this block to know when the sending resource transfer completes and if there is an error.
        if (error) {
            NSLog(@"Send resource to peer [%@] completed with Error [%@]", peerID.displayName, error);
        }
        else {
            // Create an image transcript for this received image resource

        }
    }];

The problem is that I don't get how to get the url of the zip. I can't even save it in the documents directory...

Community
  • 1
  • 1
Alessandro
  • 4,000
  • 12
  • 63
  • 131

0 Answers0