我只是想将此图片上传到iCloud。它一直给我错误“操作无法完成。操作不允许”。我从基于文档的应用程序编程指南中获取了这些代码,我相信我已正确设置了所有证书,标识符,配置文件和权利。任何帮助将非常感激。这太令人沮丧了。
#import "docx.h"
@implementation docx
-(IBAction)test:(id)sender{
NSURL *src = [NSURL URLWithString:@"/Users/rjm226/Desktop/jh.jpg"];
NSLog(@"%@", src);
NSURL *dest = NULL;
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:
[src lastPathComponent]];
//Move file to iCloud
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:src
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];
}
});
});
}
@end
答案 0 :(得分:1)
这令人非常沮丧。
欢迎来到iCloud。一段时间后你会习惯这种感觉。与此同时,你还有其他问题。
NSURL *src = [NSURL URLWithString:@"/Users/rjm226/Desktop/jh.jpg"];
这不会给你一个有效的URL,这将是一个问题。你需要的是:
NSURL *src = [NSURL fileURLWithPath:@"/Users/rjm226/Desktop/jh.jpg"];
这会为您提供有效的file://
网址。