プロジェクトで目的のzipを使用して、ファイルを解凍してドキュメントディレクトリに保存しています。iOS 5.0 以下のバージョンで正常に動作します。5.1 シミュレーターで正常に動作します。ただし、5.1 デバイスで作業している場合、解凍されるファイルはわずかです。フォルダには他に何も表示されません。以下は、解凍と保存に使用されるコードです。
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;
}
助けてください !! !
前もって感謝します