I am trying to upload audio file like session1.mp3 from document directory to iCloud using the following code
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"session1.mp3"];
NSURL* sourceURL = [[NSURL alloc] initFileURLWithPath:path];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath: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"] URLByAppendingPathComponent:@"session1.mp3"];
[[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");
}
The file i am trying to upload exists (the "File found" is printed), but the uploading it to iCloud generates the following error
Error while uploading the file: Error Domain=NSCocoaErrorDomain Code=513 "The operation couldn’t be completed. (Cocoa error 513.)" UserInfo=0x1f03d9f0 {NSURL=file://localhost/var/mobile/Applications/20D82CDA-021E-4067-B9AB-C0197A6FA834/dox.app/session1.mp3, NSUnderlyingError=0x1f03d990 "The operation couldn’t be completed. Operation not permitted"}
session1.mp3
that's in the documents directory. But your error message complains about a file namedtest.png
that's located in the app bundle. Could you resolve this conflict? For one of these files the problem is obvious, but in the other it's difficult to tell. – Tom Harrington