2014-05-22 3 views
1

패키지를 압축 해제하기 위해 ZipArchive를 사용할 때 주 스레드를 차단하는 것으로 보입니다. zip 파일에있는 약 283 개의 파일을 대상으로합니다. 내가 배경 스레드에 던지고 있지만 도움이 될 것 같지 않습니다. 압축 해제시ZipArchive 차단 주 스레드

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, (unsigned long) NULL), ^{ 
    [self tryUnzipFile:fileName inContentPackage:contentPackage]; 
    }); 

- (void)tryUnzipFile:(NSString*)fileName inContentPackage:(MKContentPackage*)contentPackage { 

    @synchronized (self) { 
    NSString *filePath = [contentPackage zipFilePathForFile:fileName]; 
     BOOL unzipSucceeded = [self unzipFile:filePath toFolder:contentPackage.unzipFolder]; 
     if (unzipSucceeded) { 
     [self excludeFromBackup:contentPackage.downloadFolder]; 
     NSLog(@"Content: Unzipping Content Package: %@ FileName: %@", contentPackage.identifier, fileName); 
     } 
    } 
} 

- (BOOL)unzipFile:(NSString*)zipFilePath toFolder:(NSString*)zipFolder { 
    ZipArchive *zipArchive = [[ZipArchive alloc] init]; 
    NSString* unzipPath = [NSObject documentFolderFrom:zipFolder fileName:@""]; 

    // Do the unzipping 
    [zipArchive UnzipOpenFile:zipFilePath]; 
    BOOL unzipped = [zipArchive UnzipFileTo:unzipPath overWrite:YES]; 
    [zipArchive UnzipCloseFile]; 

    if (unzipped) { 
    [self removeZipPackage:zipFilePath]; 
    } 
    return unzipped; 
} 

이 코드보다 약 5 초 동안 정지 화면. 나는 그것을 배경 스레드에 던지는 것이 도움이 될 것이라고 추측했지만 그럴 수는 없었다. 어떤 도움이 굉장 할 것입니다! 이러한 맥락에서 "자기의"보기 /의 ViewController 인 경우

+1

"@ 동기화"없이 테스트 할 수 있습니까? – delannoyk

+0

정말 도움이되지 않습니다. 여전히 UI가 얼어 붙어 있습니다. – user1179321

+0

실제로 이것은 상당히 개선 된 것 같습니다. 감사! – user1179321

답변

1
@synchronized (self) { 
    NSString *filePath = [contentPackage zipFilePathForFile:fileName]; 
     BOOL unzipSucceeded = [self unzipFile:filePath toFolder:contentPackage.unzipFolder]; 
     if (unzipSucceeded) { 
     [self excludeFromBackup:contentPackage.downloadFolder]; 
     NSLog(@"Content: Unzipping Content Package: %@ FileName: %@", contentPackage.identifier, fileName); 
     } 
    } 

, 당신은 동기화 된 블록에 또 다른 변수를 사용하는 것이 좋습니다.