我嘗試使用下面的代碼將文件上傳到iCloud上傳數據到iCloud
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"test.png"];
NSURL* sourceURL = [[NSURL alloc]initWithString:path];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:[sourceURL path]]) {
NSLog(@"File found!");
}
else{
NSLog(@"File not found!");
}
NSURL *ubiq = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
if (ubiq) {
NSLog(@"iCloud access at %@", ubiq);
NSError* error = nil;
NSURL *destinationURL = [ubiq URLByAppendingPathComponent:@"Documents/test.png"];
[[NSFileManager defaultManager] setUbiquitous:YES
itemAtURL:sourceURL
destinationURL:destinationURL
error:&error];
if(error != nil){
NSLog(@"Error while uploading the file: %@", error);
}
else{
NSLog(@"File ulpoaded successfully");
}
else {
NSLog(@"No iCloud access");
}
我試圖上傳該文件存在(「找到的文件」印在),但它上傳到iCloud生成以下錯誤
Error while uploading the file: Error Domain=NSCocoaErrorDomain Code=513 "The operation couldn’t be completed. (Cocoa error 513.)" UserInfo=0x1dd6bda0 {NSURL=/var/mobile/Applications/9F496F51-9DCA-4379-A62E-FFF7D7AB7385/VerticalSwipeArticles.app/test.png, NSUnderlyingError=0x1dd6c120 "The operation couldn’t be completed. Operation not permitted"}
感謝
請確保您的所有權利都是正確的,並且您已將應用程序標記爲dev設備中的iCloud。 – logancautrell
是的,我檢查了它,它是正確的 –