objective-c – 调用 – [NSFileManager setUbiquitous:itemAtURL:destinationURL:error:]永不返回

objective-c – 调用 – [NSFileManager setUbiquitous:itemAtURL:destinationURL:error:]永不返回,第1张

概述我有一个简单的基于NSDocument的Mac OS X应用程序,我正在尝试实现iCloud Document存储.我正在使用10.7 SDK构建. 我已经为iCloud文档存储配置了我的应用程序,并包含了必要的权利(AFAICT).该应用程序正确构建,运行和创建本地ubiquity容器文档目录(这需要一段时间,但这一切似乎都有效).我正在使用Apple推荐的NSFileCoordinator A 我有一个简单的基于NSdocument的Mac OS X应用程序,我正在尝试实现iCloud document存储.我正在使用10.7 SDK构建.

我已经为iCloud文档存储配置了我的应用程序,并包含了必要的权利(AFAICT).该应用程序正确构建,运行和创建本地ubiquity容器文档目录(这需要一段时间,但这一切似乎都有效).我正在使用Apple推荐的NSfileCoordinator API.我很确定我正在使用Apple推荐的正确的UbiquityIDentifIEr(它在下面进行了编辑).

我在此WWDC 2011视频中密切关注Apple的iCloud document存储演示说明:

会话107 lion中的自动保存和版本

我的代码看起来几乎与该演示中的代码相同.

但是,当我调用我的 *** 作将当前文档移动到云时,我在调用 – [NSfileManager setUbiquitous:itemAtURL:destinationURL:error:]方法时会遇到活动问题.它永远不会回来.

这是我的NSdocument子类的相关代码.它几乎与Apple的WWDC演示代码完全相同.由于这是一个动作,因此在主线程上调用(如Apple的演示代码所示).当调用-setUbiquitous:itemAtURL:destinationURL:error:方法时,会发生死锁.我已经尝试过移动到后台线程,但它仍然永远不会返回.

似乎信号量在等待从未到达的信号时阻塞.

在调试器中运行此代码时,我的源URL和目标URL看起来是正确的,因此我非常确定它们是否已正确计算并且我已确认磁盘上存在这些目录.

我做了什么明显错误的事情会导致-setUbiquitous永远不会回来?

- (IBAction)movetoOrFromCloud:(ID)sender {    NSURL *fileURL = [self fileURL];    if (!fileURL) return;    Nsstring *bundleID = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIDentifIEr"];    Nsstring *appID = [Nsstring stringWithFormat:@"XXXXXXX.%@.macosx",bundleID];    BOol makeUbiquitous = 1 == [sender tag];    NSURL *destURL = nil;    NSfileManager *mgr = [NSfileManager defaultManager];    if (makeUbiquitous) {        // get path to local ubiquity container documents dir        NSURL *dirURL = [[mgr URLForUbiquityContainerIDentifIEr:appID] URLByAppendingPathComponent:@"documents"];        if (!dirURL) {            NSLog(@"cannot find URLForUbiquityContainerIDentifIEr %@",appID);            return;        }        // create it if necessary        [mgr createDirectoryAtURL:dirURL withIntermediateDirectorIEs:NO attributes:nil error:nil];        // ensure it exists        BOol exists,isDir;        exists = [mgr fileExistsAtPath:[dirURL relativePath] isDirectory:&isDir];        if (!(exists && isDir)) {            NSLog(@"can't create local icloud dir");            return;        }        // append this doc's filename        destURL = [dirURL URLByAppendingPathComponent:[fileURL lastPathComponent]];    } else {        // get path to local documents folder        NSArray *dirs = [mgr URLsForDirectory:NSdocumentDirectory inDomains:NSUserDomainMask];        if (![dirs count]) return;        // append this doc's filename        destURL = [[dirs objectAtIndex:0] URLByAppendingPathComponent:[fileURL lastPathComponent]];    }    NSfileCoordinator *fc = [[[NSfileCoordinator alloc] initWithfilePresenter:self] autorelease];    [fc coordinateWritingItemAtURL:fileURL options:NSfileCoordinatorWritingForMoving writingItemAtURL:destURL options:NSfileCoordinatorWritingForReplacing error:nil byAccessor:^(NSURL *fileURL,NSURL *destURL) {        NSError *err = nil;        if ([mgr setUbiquitous:makeUbiquitous itemAtURL:fileURL destinationURL:destURL error:&err]) {            [self setfileURL:destURL];            [self setfileModificationDate:nil];            [fc itemAtURL:fileURL dIDMovetoURL:destURL];        } else {            NSWindow *win = ... // get my window            [self presentError:err modalForWindow:win delegate:nil dIDPresentSelector:nil contextInfo:NulL];        }    }];}
解决方法 只是在Twitter上与你分享这个,但我相信在使用NSdocument时你不需要做任何NSfileCoordinator的东西 – 只需使文档无处不在并保存. 总结

以上是内存溢出为你收集整理的objective-c – 调用 – [NSFileManager setUbiquitous:itemAtURL:destinationURL:error:]永不返回全部内容,希望文章能够帮你解决objective-c – 调用 – [NSFileManager setUbiquitous:itemAtURL:destinationURL:error:]永不返回所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1007502.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存