2

我有一个非常奇怪的问题。当我使用 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]
4

1 回答 1

0

讨论

使用此方法将文件从其当前位置移动到 iCloud。对于位于应用程序沙箱中的文件,这涉及从沙箱容器中物理删除文件。(系统扩展了您的应用程序的沙盒权限,使其能够访问它移动到 iCloud 的文件。)您还可以使用此方法将文件移出 iCloud 并返回到本地目录。

文件从 srcDocumentURL(沙箱)物理移动到 dstDocumentURL。尝试这个:

NSLog(@"[%@]", [ [ NSFileManager defaultManager ] contentsOfDirectoryAtURL:destinationURL includingPropertiesForKeys:nil options:nil error:nil ]);
于 2013-02-19T15:28:32.437 回答