[UIDocument saveToURL:forSaveOperation:completionHandler:]
调用时的行为是什么UIDocumentSaveForCreating
?
方法#1 - saveToURL:保存后关闭文档
然后无需关闭文档。
MYDocument *document = [[MYDocument alloc] initWithFileURL:fileURL];
[document saveToURL:fileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL saveSuccess) {
if (!saveSuccess) {
ALog(@"Failed to create file at %@", fileURL);
failureBlock();
return;
}
successBlock(fileURL);
}];
方法#2 - saveToURL:保存后不关闭文档
然后我必须自己关闭文档,如下所示:
MYDocument *document = [[MYDocument alloc] initWithFileURL:fileURL];
[document saveToURL:fileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL saveSuccess) {
if (!saveSuccess) {
ALog(@"Failed to create file at %@", fileURL);
failureBlock();
return;
}
[document closeWithCompletionHandler:^(BOOL closeSuccess) {
if(!closeSuccess) {
ALog(@"Error during close after creating %@", fileURL);
failureBlock();
return;
}
successBlock(fileURL);
}];
}];