iCloud集成中的警告 [英] Warning in iCloud integration

查看:122
本文介绍了iCloud集成中的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试集成iCloud.

I am trying to integrating iCloud.

一切正常,但是当我尝试从iCloud读取文件时,出现警告,如:

Everything works fine but when I try to read a file from iCloud I get a warning Like:

Foundation called mkdir("/var/mobile/Library/Mobile Documents/.ubd/peer-E8A60A8F-FB9D-8721-F47C-hdffgdfg-v23/ftr/(A Document Being Saved By XYZ)"), it didn't return 0, and errno was set to 1.

我的代码以获取数据:

for (NSMetadataItem *item in results)
        {
            NSString *filename = [item valueForAttribute:NSMetadataItemDisplayNameKey];
            NSURL *url = [item valueForAttribute:NSMetadataItemURLKey];
            MyDocument *doc = [[MyDocument alloc] initWithFileURL:url];

                [doc openWithCompletionHandler:^(BOOL success) {
                    if (success) {
                        NSData *file = [NSData dataWithContentsOfURL:url];

                        NSString *docDir = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"Import/iCloud"];
                        if (![[NSFileManager defaultManager] fileExistsAtPath:docDir])
                            [[NSFileManager defaultManager] createDirectoryAtPath:docDir withIntermediateDirectories:YES attributes:nil error:nil];

                        NSString *pdfFile = [docDir stringByAppendingPathComponent:filename];
                        if(![[NSFileManager defaultManager] fileExistsAtPath:pdfFile])
                            [[NSFileManager defaultManager] createFileAtPath:pdfFile contents:file attributes:nil];

                        NSLog(@"Successfully loaded data from cloud file name %@", filename);                        
                    }
                    else
                    {
                        NSLog(@"Failed to load data");
                    }
                }];

        }
    }

推荐答案

您似乎在iCloud中有部分写入的文件(基于错误中 XYZ保存的文档),您的元数据查询已将其返回给您,因为它也与文件名匹配.几周前,我遇到了类似情况,并使用文件的确切路径解决了该问题,如下所示:

It looks like you have a partially written file in iCloud (based on the A Document Being Saved By XYZ in the error), and your meta data query has returned that to you since it also matches the filename. I ran into a similar situation a few weeks ago and solved it by using the exact path to the file, as in:

NSString *filepath = [containerURL.path stringByAppendingPathComponent:@"MyFileName"];

NSPredicate *pred = [NSPredicate predicateWithFormat: @"%K == %@", NSMetadataItemPathKey, filepath];
[query setPredicate:pred];

这篇关于iCloud集成中的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆