iCloud在第一次发布时不会同步

时间:2012-10-17 20:52:48

标签: ios synchronization load sync icloud

我有一个错误,我的应用程序不会在第一次启动时拉出icloud inforamtion,但它会在随后的尝试中执行。这是我从icloud加载文件的代码。

  

void DLC :: loadFromiCloud(std :: string fileName){

     
    

NSURL * mUbiqUrl = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];

         

if(mUbiqUrl)        {

         
std::string fullPath = getLibraryPath_iOS() + fileName;

NSString* restorePath = [NSString stringWithUTF8String:(fullPath.c_str())];
    NSError *error = nil;
    NSURL *fileToDownload = [mUbiqUrl URLByAppendingPathComponent:[NSString stringWithUTF8String:(fileName.c_str())]];
    [[NSFileManager defaultManager] startDownloadingUbiquitousItemAtURL:fileToDownload 
                                                error:&error];
    if (error != nil)
    {
        NSLog(@"iCloud L2 error: %@", [error localizedDescription]);
    }
    else 
    {
        NSNumber*  isIniCloud = nil;
        if ([fileToDownload getResourceValue:&isIniCloud forKey:NSURLIsUbiquitousItemKey error:nil])
        {
            // If the item is in iCloud, see if it is downloaded.
            if ([isIniCloud boolValue]) 
            {
                NSNumber*  isDownloaded = nil;
                if ([fileToDownload getResourceValue:&isDownloaded forKey:NSURLUbiquitousItemIsDownloadedKey error:nil]) 
                {
                    if ([isDownloaded boolValue])
                    {
                        NSString *fileData = [NSString stringWithContentsOfURL:fileToDownload encoding:NSUTF8StringEncoding error:&error];
                        //NSLog(@"iCloud data: %@", fileData);
                        [fileData writeToFile:restorePath atomically:YES encoding:NSUTF8StringEncoding error:&error];
                        if (error)
                        {
                            NSLog(@"iCloud L3 error: %@", [error localizedDescription]);
                        }
                    }
                }
            }
        }
    }
}}
    
  

0 个答案:

没有答案