Zip库问题

时间:2013-06-16 06:34:46

标签: ios zip warnings dropbox

所以我使用的是这个库:https://github.com/flyingdolphinstudio/Objective-Zip

我实现了它,并尝试使用UIImage和NSString,并分别在.zip文件中将其设为.png和.txt。

现在这些是我的两个问题,我正在尝试将* zipFile保存到文档目录下面。

  1. 现在使用Dropbox API,为什么我不能只提供文件本身并跳过路径。看来我首先要将.zip保存到文档目录然后获取路径,然后我可以将其上传到dropbox。我必须这样做吗?

  2. 在... writeToFile行中,我收到一条警告,ZipFile可能无法响应writeToFile,那么如何将其正确保存到文档目录?

  3. 无论如何这是我到目前为止的代码:

            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];
    

    那我在这里做错了什么?

    谢谢!

1 个答案:

答案 0 :(得分:1)

我认为ZipFile已经写入文件,所以不需要writeToFile之类的东西。只需使用您想要的路径初始化zipFile,请务必在结尾处关闭文件([zipFile close]),然后像上传任何其他文件一样上传到Dropbox。