我看过iOS的iCloud文档示例代码,并将其用于将UIDocument与iCloud同步,现在我正在尝试将iCloud与Mac OSX应用程序上的NSDocument同步,但该应用程序没有
我尝试将
例如,下面这个方法,在iOS的
苹果文档提供了这段针对OS X的代码:
我该如何在iOS和OS X之间进行同步(因为iOS上不存在
UIDocument
。我尝试将
UIDocument
更改为NSDocument
,但所有与iCloud同步的方法都不同。除了非常混乱且写得不好的Apple文档之外,我没有找到任何示例代码或教程。例如,下面这个方法,在iOS的
UIDocument
中存在,但在OS X的NSDocument
中不存在://doc is an instance of subclassed UIDocument
[doc openWithCompletionHandler:nil];
苹果文档提供了这段针对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之间进行同步(因为iOS上不存在
NSDocument
,而OS X上不存在UIDocument
)?有人知道在Mac OS X(NSDocument
同步)中可以找到示例吗?