当前位置: 动力学知识库 > 问答 > 编程问答 >

objective c - NSFileManager setUbiquitous:YES pushed my file in limbo! Why?

问题描述:

I have a really strange problem. When I use NSFileManager setUbiquitous function, my file is being pushed to iCloud, but when I check the existence of this file after one sec, the file is NOT there anymore! It looks like that iCloud just removed my file, is it possible, and why? Anybody encounter this problem before?

static void moveItem( CD_ICloudOperationItem *item, bool toCloud, NSURL *srcDocumentURL, NSURL *srcThumbnailURL, NSURL *dstDocumentURL, NSURL *dstThumbnailURL)

{

dispatch_queue_t mainQueue = dispatch_get_main_queue();

dispatch_queue_t operationQueue = dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 );

dispatch_async(operationQueue, ^(void) {

__block NSError *err1 = nil;

NSFileManager * fm = [ NSFileManager defaultManager];

__block bool success1 = true;

NSString *message = nil;

success1 = [fm setUbiquitous:toCloud itemAtURL:srcDocumentURL destinationURL:dstDocumentURL error:&err1];

bool fileExits = false;

if (toCloud) {

fileExits = [fm isUbiquitousItemAtURL:dstDocumentURL];

if (!fileExits) {

NSLog(@"---> File has NOT been moved correctly!!!! [%@]", dstDocumentURL);

NSLog(@"%@",[err1 description]);

}

else{

NSLog(@"---> File has been moved correctly!!!! [%@]", dstDocumentURL);

}

sleep(1);

fileExits = [fm isUbiquitousItemAtURL:dstDocumentURL];

if (!fileExits) {

NSLog(@"---> After 1 sec file has disappear!!!! [%@]", dstDocumentURL);

NSLog(@"%@",[err1 description]);

}

else{

NSLog(@"---> After 1 sec file still there!!!! [%@]", dstDocumentURL);

}

}

else{

fileExits = [fm fileExistsAtPath:[dstDocumentURL path]];

if (!fileExits) {

NSLog(@"---> File has NOT been moved correctly!!!! [%@]", dstDocumentURL);

NSLog(@"%@",[err1 description]);

}

else{

NSLog(@"---> File has been moved correctly!!!! [%@]", dstDocumentURL);

}

}

if( !success1 )

{

success = false;

message = meaningfulMessageFromError( err1 );

NSLog(@"%@",[err1 description]);

}

dispatch_async( mainQueue, ^(void) {

postNotification( item, success, message );

});

});

}

See my traces :

 ---> File has been moved correctly!!!! [file://localhost/private/var/mobile/Library/Mobile%20Documents/U5LPYJSPQ3~com~my~container-imobile/Documents/Untitled_(2).fbdi]

---> After 1 sec file has disappear!!!! [file://localhost/private/var/mobile/Library/Mobile%20Documents/U5LPYJSPQ3~com~my~container-imobile/Documents/Untitled_(2).fbdi]

网友答案:

Discussion

Use this method to move a file from its current location to iCloud. For files located in an app’s sandbox, this involves physically removing the file from the sandbox container. (The system extends your app’s sandbox privileges to give it access to files it moves to iCloud.) You can also use this method to move files out of iCloud and back into a local directory.

File physically moved from srcDocumentURL (sandbox) to dstDocumentURL. Try this:

NSLog(@"[%@]", [ [ NSFileManager defaultManager ] contentsOfDirectoryAtURL:destinationURL includingPropertiesForKeys:nil options:nil error:nil ]);
分享给朋友:
您可能感兴趣的文章:
随机阅读: