UIDocument的saveToURL:forSaveOperation:completionHandler:
被假設是異步的(在文檔中,它說,它將對背景隊列這個動作),但我的代碼有調用此當7-10秒落後。UIDocument saveToURL:造成嚴重滯後
下面的代碼:
NSLog(@"saving image...");
[picDoc saveToURL:[picDoc fileURL]
forSaveOperation:UIDocumentSaveForCreating
completionHandler:^(BOOL success) {
dispatch_async(dispatch_get_main_queue(), ^{
if (success) {
NSLog(@"image save successful!");
UIImage *thumbnail = [image imageByScalingAndCroppingForSize:CGSizeMake(146, 110)];
Picture *picture = [[Picture alloc] initWithThumbnail:thumbnail filename:fileName];
[[set pictures] addObject:picture];
[self setupPictures];
[scrollView scrollRectToVisible:((UIView *)[[scrollView subviews] lastObject]).frame animated:YES];
currentIndex = [[set pictures] count] - 1;
[self showPicture];
} else {
NSLog(@"failed saving image");
}
[SVProgressHUD dismiss];
});
[picDoc closeWithCompletionHandler:nil];
}];
NSLog(@"exit");
和控制檯:
2012-05-15 07:07:27.417 Picventory[5939:707] saving image...
2012-05-15 07:07:34.120 Picventory[5939:707] exit
2012-05-15 07:07:34.740 Picventory[5939:707] image save successful!
爲什麼會出現如此巨大的滯後,當調用是異步的? 感謝
你看看:http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDocument_Class/UIDocument/UIDocument.html – CarlJ