我在我的应用程序中使用多点连接。用户可以将任何文件(例如 png 或录音)发送给其他对等方。由于传输速度很慢,我认为将数据压缩到 zip 会随着大小的减小而加快传输速度。我决定使用这个问题的第二个答案中建议的框架:
问题是我需要提供文件的usl才能通过蓝牙发送它,我尝试这样做:
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
}
}];
问题是我不知道如何获取 zip 的 url。我什至无法将其保存在文档目录中...