【发布时间】:2012-02-20 10:03:23
【问题描述】:
我已经看到了 iOS 的 iCloud 文档示例代码,我用它来将 uidocument 同步到 iCloud 和从 iCloud 同步,现在我正在尝试在没有 @ 的 Mac OSX 应用程序上将 iCloud 与 nsdocument 同步987654325@。
我尝试将UIDocument 更改为NSDocument,但与icloud 同步的所有方法都不同。除了来自apple 的文档之外,我没有找到任何示例代码或教程,这非常令人困惑且写得不好。
例如,下面的方法,来自 iOS 上的 UIDocument 在 OS X 上的 NSDocument 中不存在:
//doc is an instance of subclassed UIDocument
[doc openWithCompletionHandler:nil];
Apple 文档为 OS X 提供了以下代码:
- (void)checkIfCloudAvaliable {
NSURL *ubiquityContainerURL = [[[NSFileManager defaultManager]
URLForUbiquityContainerIdentifier:nil]
URLByAppendingPathComponent:@"Documents"];
if (ubiquityContainerURL == nil) {
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
NSLocalizedString(@"iCloud does not appear to be configured.", @""),
NSLocalizedFailureReasonErrorKey, nil];
NSError *error = [NSError errorWithDomain:@"Application" code:404
userInfo:dict];
[self presentError:error modalForWindow:[self windowForSheet] delegate:nil
didPresentSelector:NULL contextInfo:NULL];
return;
}
dest = [ubiquityContainerURL URLByAppendingPathComponent:
[[self fileURL] lastPathComponent]];
}
- (void)moveToOrFromCloud {
dispatch_queue_t globalQueue =
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(globalQueue, ^(void) {
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSError *error = nil;
// Move the file.
BOOL success = [fileManager setUbiquitous:YES itemAtURL:[self fileURL]
destinationURL:dest error:&error];
dispatch_async(dispatch_get_main_queue(), ^(void) {
if (! success) {
[self presentError:error modalForWindow:[self windowForSheet]
delegate:nil didPresentSelector:NULL contextInfo:NULL];
}
});
});
[self setFileURL:dest];
[self setFileModificationDate:nil];
}
如何在 iOS 和 OS X 之间进行同步(因为 NSDocument 在 iOS 上不存在,UIDocument 在 OS X 上不存在)?有谁知道我在哪里可以找到 Mac OSX 的示例(NSDocument 同步)?
【问题讨论】:
-
并非所有人都觉得文档“令人困惑且写得不好”。
-
我使用了文档,但它对我不起作用。
-
另外 - 为什么不显示一些您尝试过的代码,而不是寻找可以剪切和粘贴的东西。你已经为 iOS 完成了 - 所以你必须对流程有所了解。
-
给你,我从文档中粘贴了一些对我不起作用的代码。
标签: uidocument nsdocument icloud apple objective-c ios macos icloud nsdocument