0
你好,这里是我创建来处理我的UIManagedDocument在JIPManagedDocument.m代码:UIManagedDocument:传递给完成处理程序块不会被调用
+(JIPManagedDocument *)sharedManagedDocument
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
url = [url URLByAppendingPathComponent:@"DemoDocument"];
_sharedManagedDocument = [[JIPManagedDocument alloc] initWithFileURL:url];
});
return _sharedManagedDocument;
}
-(void)performBlockWithDocument:(void (^)(JIPManagedDocument * managedDocument))block
{
void (^completionBlock) (BOOL) = ^(BOOL success)
{
if (success)
{
block(self);
NSLog(@"COULD PERFORM BLOCK WITH ManagedDocument");
}
else
{
NSLog(@"COULDNT PERFORM BLOCK WITH ManagedDocument");
}
self.openingDocument = NO;
};
if (self.documentState == UIDocumentStateNormal)
{
completionBlock(YES);
}
else if (! self.openingDocument)
{
self.openingDocument = YES;
if (! [[NSFileManager defaultManager] fileExistsAtPath:[self.fileURL path]])
{
[self saveToURL:self.fileURL
forSaveOperation:UIDocumentSaveForCreating
completionHandler:completionBlock];
}
else if (self.documentState == UIDocumentStateClosed)
{
[self openWithCompletionHandler:completionBlock];
}
}
}
,然后当我尝试调用的方法是这样的:
[[JIPManagedDocument sharedManagedDocument] performBlockWithDocument:^(JIPManagedDocument *managedDocument)
{
//Do something
}];
//Do something
部分从未得到执行。
任何帮助将非常感激,非常感谢!
那么在什么情况下,openwithcompletionhandler可能会失败? ------这是我在same.m文件中的单例方法:+(JIPManagedDocument *)sharedManagedDocument { static dispatch_once_t onceToken; dispatch_once(&onceToken,^ { NSURL * URL = [[[的NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; URL = [URL URLByAppendingPathComponent:@ “DemoDocument”]; _sharedManagedDocument = [[JIPManagedDocument的alloc] initWithFileURL :url]; }); return _sharedManagedDocument; } – Dontfearmistakes