Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 跟踪iCloud文件的上载进度_Objective C_Ios_Cocoa_Icloud - Fatal编程技术网

Objective c 跟踪iCloud文件的上载进度

Objective c 跟踪iCloud文件的上载进度,objective-c,ios,cocoa,icloud,Objective C,Ios,Cocoa,Icloud,我正在编写一个利用iCloud的Unity插件 现在,我当前将文件移动到iCloud的方式是使用以下代码: [byteDocument saveToURL:savePathURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) { if (ubiquitousContainerURL != nil) { NSU

我正在编写一个利用iCloud的Unity插件

现在,我当前将文件移动到iCloud的方式是使用以下代码:

     [byteDocument saveToURL:savePathURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success)
     {
         if (ubiquitousContainerURL != nil)
         {
             NSURL *ubiquityDocumentDirectory = [ubiquitousContainerURL
                                                 URLByAppendingPathComponent:@"Documents"
                                                 isDirectory:YES];

             ubiquityDocumentDirectory = [ubiquityDocumentDirectory URLByAppendingPathComponent:[NSString stringWithFormat:@"%@%@", filename, extension]];

             NSFileManager* fm = [NSFileManager defaultManager];

             dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

                 NSError* error = nil;

                 if (![fm fileExistsAtPath:ubiquityDocumentDirectory.path])
                 {
                     NSLog(@"Attemping to move to cloud");
                     didMoveToCloud = [fm setUbiquitous:YES itemAtURL:savePathURL destinationURL:ubiquityDocumentDirectory error:nil];
                 }
                 else
                 {
                     NSLog(@"Attemping to replace in cloud");
                     didMoveToCloud = [fm replaceItemAtURL:ubiquityDocumentDirectory withItemAtURL:savePathURL backupItemName:nil options:0 resultingItemURL:nil error:&error];
                 }

                 if (didMoveToCloud)
                 {
                     NSLog(@"Did move text document successfully to cloud");
                     //UnitySendMessage("GameObject", "DidSaveFile", [savePathURL.path cStringUsingEncoding:NSASCIIStringEncoding]);
                 }
                 else
                 {
                     NSLog(@"Failed to move text document to cloud");
                     //UnitySendMessage("GameObject", "DidSaveFile", [savePathURL.path cStringUsingEncoding:NSASCIIStringEncoding]);
                 }

                 if (error != nil)
                 {
                     NSLog(@"Error saving text document to cloud: %@", error.description);
                     //UnitySendMessage("GameObject", "DidSaveFile", [savePathURL.path cStringUsingEncoding:NSASCIIStringEncoding]);
                 }
             });
         }
     }];
基本上,我只是使用一个简单的UIDocument继承类CloudBytedDocument。我首先将其本地保存在设备上,然后将其移动到iCloud

现在的问题是,使用SetUbiquituos似乎无法提供任何跟踪上传进度的方法?我已连接到两个MSMetaDataQuery observerser,即:

 // Listen for the second phase live-updating
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(queryDidReceiveNotification:) name:NSMetadataQueryDidUpdateNotification object:nil];

// Listen for the first phase gathering
[[NSNotificationCenter defaultCenter] addObserver:self
                                      selector:@selector(queryIsDoneGathering:) name:NSMetadataQueryDidFinishGatheringNotification
                                           object:nil];
我还意识到,在NSMetadataQueryDidUpdateNotification过程中,您可以获得上传和下载进度之类的信息,但是这种更新方法似乎并不总是提供非常可靠的结果

我想知道是否有什么方法可以让你在文件上传到iCloud时使用实际的回调方法来通知你?或者NSMetadataQueryDidUpdateNotification方法是这样做的标准方法吗

如有任何提示和帮助,将不胜感激:


感谢您抽出时间:

查看NSMetaDataItem和NSMetadataUbiquitousItemPercentUploadedKey和NSMetadataUbiquitousItemPercentDownloadedKey的文档。是的,我知道您可以从NSMetaDataItem检索这些数字,也许我应该在帖子中提到这一点:我的问题是,这是否是确定文件何时上传的唯一方法?也就是说,使用NSMetadataQueryDidUpdateNotification结合NSMetaDataItem键。您能否给出一个流级示例如何实现这一点我正在努力从自定义筛选器存储和恢复核心数据Sqlite文件。我不想用iCloud做传统的核心数据处理方法,但我认为我的代码像wahtsapp。@rmaddy我检查了建议和一些文档,但没有明确的教程或了解这是如何实现的,我无法得到百分比,直到上传0-1,但不是0.1,0.2…,你能帮我举个例子吗。我使用的是iOS 7以后的版本和Xcode 7FYI@VickyDhas您是否成功地实现了类似whatsApp的将聊天备份到iCloud的过程?如果你有什么要分享的,请在这里回答