我有一个非常奇怪的问题。当我使用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]
答案 0 :(得分:0)
<强>讨论强>
使用此方法将文件从其当前位置移动到iCloud。 对于位于应用程序沙箱中的文件,这涉及物理上的 从沙箱容器中删除该文件。 (系统扩展你的 应用程序的沙箱权限,使其可以访问它移动到的文件 iCloud。)您也可以使用此方法将文件移出iCloud和 回到本地目录。
文件从srcDocumentURL(沙箱)物理移动到dstDocumentURL。试试这个:
NSLog(@"[%@]", [ [ NSFileManager defaultManager ] contentsOfDirectoryAtURL:destinationURL includingPropertiesForKeys:nil options:nil error:nil ]);