繁体   English   中英

“该操作无法完成。 仅将图像发送到icloud时,“不允许操作”错误

[英]“The operation couldn’t be completed. Operation not permitted” error when simply sending image to icloud

我只是试图将此图像上传到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

这真是令人沮丧。

欢迎使用iCloud。 一段时间后,您会习惯这种感觉。 同时,您还有其他问题。

NSURL *src = [NSURL URLWithString:@"/Users/rjm226/Desktop/jh.jpg"];

这不会为您提供有效的URL,这将是一个问题。 您需要的是:

NSURL *src = [NSURL fileURLWithPath:@"/Users/rjm226/Desktop/jh.jpg"];

这将为您提供一个有效的file:// URL。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM