我有一个非常奇怪的问题。当我使用 NSFileManager setUbiquitous 函数时,我的文件被推送到 iCloud,但是当我在一秒钟后检查该文件是否存在时,该文件不再存在!看起来 iCloud 刚刚删除了我的文件,有可能吗,为什么?以前有人遇到过这个问题吗?
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 );
});
});
}
查看我的痕迹:
---> 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]