简体   繁体   English

Objective Zip无法与iOS5.1设备一起使用,无法正确解压缩

[英]Objective Zip not working with iOS5.1 devices, not properly unzipping

I am using objective zip in a project to unzip and store files to documents directory. 我在项目中使用目标zip解压缩并将文件存储到文档目录。 Its working fine with iOS 5.0 and below versions. 它可以在iOS 5.0及以下版本上正常工作。 Working fine with 5.1 Simulator. 使用5.1 Simulator可以正常工作。 But when working on 5.1 device, only a few files are unzipped. 但是在5.1设备上工作时,仅解压缩了几个文件。 Nothing else is shown in the folder. 文件夹中没有其他内容。 below is the code used for unzipping and storage. 以下是用于解压缩和存储的代码。

for (NSString *file in fileArray) {

        // Get the file info/name, prepare the target name/path
        ZipReadStream *readStream = [unzipFile readCurrentFileInZip];
        FileInZipInfo *fileInfo = [unzipFile getCurrentFileInZipInfo];
        fileNameString = [NSString stringWithFormat:@"%@",[fileInfo name]];

        NSLog(@"fileNameString %@",fileNameString);

        NSString *DirName = [targetFolder stringByAppendingPathComponent:moduleName];
        NSLog(@"targetFolder %@",targetFolder);
        NSLog(@"DirName %@",DirName);

        NSLog(@"fileNameString %@",fileNameString);

        if (![fileManager fileExistsAtPath:DirName isDirectory:nil]) {
            [fileManager createDirectoryAtPath:DirName attributes:nil];
            NSLog(@"created directory %@", DirName);
        }

        NSLog(@"fileNameString %@",fileNameString);

        NSString *unzipFilePath = [DirName stringByAppendingPathComponent:fileNameString];

        NSLog(@"unzipFilePath-- %@",unzipFilePath);

        // Create a file handle for writing the unzipped file contents
        if (![fileManager fileExistsAtPath:unzipFilePath]) {

            NSString *dir = unzipFilePath;//[unzipFilePath stringByDeletingLastPathComponent];
            if ([[fileNameString pathExtension] isEqualToString:@""]) {
                [fileManager createDirectoryAtPath:dir attributes:nil];
                NSLog(@"created directory %@", dir);
            }
            [fileManager createFileAtPath:unzipFilePath contents:nil attributes:nil];
        }

        fileHandle = [NSFileHandle fileHandleForWritingAtPath:unzipFilePath];
        // Read-then-write buffered loop to conserve memory
        do {
            // Reset buffer length
            [unzipBuffer setLength:BUFFER_SIZE];
            // Expand next chunk of bytes
            int bytesRead = [readStream readDataWithBuffer:unzipBuffer];
            if (bytesRead > 0) {
                // Write what we have read
                [unzipBuffer setLength:bytesRead];
                [fileHandle writeData:unzipBuffer];
            } else
                break;
        } while (YES);

        [readStream finishedReading];

        // NOTE: Disable iCloud backup for unzipped file if applicable here!
        /*...*/


        //[fileHandle writeData:unZipped];

        [fileHandle closeFile];

        [unzipFile goToNextFileInZip];
    }

    [unzipFile close]; // Be sure to also manage your memory manually if not using ARC!

    // Also delete the zip file here to conserve disk space if applicable!
    [recievedData release];

    NSLog(@"Delete -- %@", documentsDirectory);
    [fileManager removeItemAtPath:documentsDirectory error:nil];

    return YES;

}

Please help ! 请帮忙 ! ! !

thanks in Advance 提前致谢

Use have the following method for unzipping a zip file using Objective-zip. 使用以下方法使用Objective-zip解压缩zip文件。 This works fine under iOS 4.3 through 6.0 (and probably earlier and later too). 在iOS 4.3到6.0之间(以及更早或更晚的版本)下,此方法也可以正常工作。 The 'filename' parameter is the full path to the zip file. “文件名”参数是zip文件的完整路径。

- (BOOL)unzipPath:(NSString *)filename toDirectory:(NSString *)directory error:(NSError **)error {
    if (error) {
        *error = nil;
    }

    ZipFile *unzipFile = [[ZipFile alloc] initWithFileName:filename mode:ZipFileModeUnzip];
    int cnt = [unzipFile numFilesInZip];
    [unzipFile goToFirstFileInZip];
    for (int i = 0; i < cnt; i++) {
        FileInZipInfo *info = [unzipFile getCurrentFileInZipInfo];
        NSString *name = info.name;
        if (![name hasSuffix:@"/"]) {
            NSString *filePath = [directory stringByAppendingPathComponent:name];
            NSString *basePath = [filePath stringByDeletingLastPathComponent];
            if (![[NSFileManager defaultManager] createDirectoryAtPath:basePath withIntermediateDirectories:YES attributes:nil error:error]) {
                [unzipFile close];

                return NO;
            }

            [[NSData data] writeToFile:filePath options:0 error:nil];

            NSFileHandle *handle = [NSFileHandle fileHandleForWritingAtPath:filePath];
            ZipReadStream *read = [unzipFile readCurrentFileInZip];
            NSUInteger count;
            NSMutableData *data = [NSMutableData dataWithLength:2048];
            while ((count = [read readDataWithBuffer:data])) {
                data.length = count;
                [handle writeData:data];
                data.length = 2048;
            }
            [read finishedReading];
            [handle closeFile];
        }

        [unzipFile goToNextFileInZip];
    }

    [unzipFile close];

    return YES;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS5.1:同步任务(等待完成) - iOS5.1: synchronising tasks (wait for a completion) CADisplayLink在iOS5.1上运行较低的帧速率 - CADisplayLink running lower frame rate on iOS5.1 使用Objective Zip解压缩包含子文件夹的zip文件 - Unzipping a zip file with sub folders in it using Objective Zip iOS zip文件解压缩代码问题 - iOS zip file Unzipping code issue 缩放ScrollView适用于iOS4,但在iOS5和iOS5.1中崩溃 - Zooming in ScrollView works in iOS4 but crash in iOS5 and iOS5.1 在消耗性InAppPurchase中,取消事务的委托在ios5.1中找不到,但在ios 6.1中找到 - In consumable InAppPurchase, delegate of cancel transaction not found in ios5.1 but found in ios 6.1 向自定义对象发送动作会使ios5.1,xcode 4.3.1中的应用程序崩溃 - Sending an action to a custom object is crashing the application in ios5.1, xcode 4.3.1 如何使用UIMenuController iOS5.1防止UITextView上的复制/粘贴/选择弹出框 - How do Prevent a copy/paste/select popover on a UITextView using UIMenuController iOS5.1 使用zlib解压缩zip文件会在IOS中永久返回错误 - Unzipping a zip-file with zlib returns error permanently in IOS IQkeyboardManager在iOS 11 Objective-C上无法正常工作 - IQkeyboardManager is not working properly on iOS 11 objective-c
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM