所以我正在使用这个库:https ://github.com/flyingdolphinstudio/Objective-Zip
我实现了它,并尝试获取 UIImage 和 NSString 并将其分别设为 .zip 文件中的 .png 和 .txt 。
现在这些是我的两个问题,我正在尝试将下面的 *zipFile 保存到文档目录中。
现在有了 Dropbox API,为什么我不能只提供文件本身并跳过路径。似乎我必须先将 .zip 保存到文档目录,然后获取路径,然后我才能将其上传到保管箱。我必须这样做吗?
在 ...writeToFile 行中,我收到一条警告说 ZipFile 可能无法响应 writeToFile 那么我该如何正确地将其保存到文档目录中?
无论如何,这是我到目前为止的代码:
NSString *filename = [NSString stringWithFormat:@"%@.zip", textField.text];
ZipFile *zipFile= [[ZipFile alloc] initWithFileName:filename mode:ZipFileModeCreate];
//Image
NSString *nameImage = @"Image.png";
NSMutableDictionary *theDictionary = [Singleton sharedSingleton].dictionary;
NSData *data = [theDictionary objectForKey:@"image"];
ZipWriteStream *writeImage = [zipFile writeFileInZipWithName:nameImage compressionLevel:ZipCompressionLevelBest];
[writeImage writeData:data];
[writeImage finishedWriting];
//Text
NSString *nameText = @"Text.txt";
NSData *dataText = [textView.text dataUsingEncoding:NSUTF8StringEncoding];
ZipWriteStream *writeText = [zipFile writeFileInZipWithName:nameText compressionLevel:ZipCompressionLevelBest];
[writeText writeData:dataText];
[writeText finishedWriting];
//Now we HAVE to save it to the documents directory to get it to work with dropbox
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
NSString *filePath = [documentsPath stringByAppendingPathComponent:filename]; //Add the file name
[zipFile writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:NULL];
//Save to Dropbox
NSString *zipPath = [[NSBundle mainBundle] pathForResource:textField.text ofType:@"zip"];
[[self restClient] uploadFile:filename toPath:@"/" withParentRev:nil fromPath:zipPath];
那么我在这里做错了什么?
谢谢!