iCloud Cocoa Error 512 [英] iCloud Cocoa Error 512

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

问题描述

我正在尝试将文件从iCloud容器复制到我的应用缓存目录。我一直在无法完成操作。 (Cocoa error 512。)在我的日志中,这是一个非常广泛的错误,意思是 NSFileWriteUnknownError ,或写入失败,iOS不知道为什么。

I'm trying to copy a file from my iCloud container to my apps' cache directory. I keep getting The operation couldn’t be completed. (Cocoa error 512.) in my log, which is a very broad error meaning NSFileWriteUnknownError, or the write failed and iOS doesn't know why.

以下是 NSMetadataQuery 完成并在iCloud中拥有文件名的代码。我将简要介绍下面的代码。

Here is the code for when the NSMetadataQuery finishes and has the file names in iCloud. I'll briefly describe the code below.

- (void)loadData:(NSMetadataQuery *)query {

    NSArray *cache = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[cacheDirectory stringByAppendingString:@"/issues"] error:NULL];

    for (NSMetadataItem *item in [query results]) {

        NSURL *name = [item valueForAttribute:NSMetadataItemURLKey];
        NSString *nameString = [item valueForAttribute:NSMetadataItemPathKey];

        NSError *error;

        NSURL *cacheURL = [NSURL fileURLWithPath:cacheDirectory];
        NSURL *destination = [cacheURL URLByAppendingPathComponent:[NSString stringWithFormat:@"issues/%@", [[nameString stringByDeletingLastPathComponent] lastPathComponent]] isDirectory:YES];

        [[NSFileManager defaultManager] copyItemAtURL:[name URLByDeletingLastPathComponent] toURL:destination error:&error];

        }

    }

}

这个应用程序同步报纸问题。在iCloud文档容器中,有包含数据的文件夹(一个文件夹可能是 5.1.12 ),每个文件夹中都有一个PDF文件,其中相同 name( 5.1.12.pdf )。

This app syncs newspaper issues. In the iCloud documents container, there are folders with the data (one folder could be 5.1.12), and inside each folder is a PDF file with the same name (5.1.12.pdf).

知道为什么会这样吗?感谢您的帮助。

Any idea why this is happening? Thanks for your help.

iCloud: file://localhost/private/var/mobile/Library/Mobile%20Documents/AppBundleID/Documents/5.3.12/

Local: file://localhost/var/mobile/Applications/F91E115B-ECED-403E-AB61-41F7A99EF928/Library/Caches/issues/5.3.12/


推荐答案

当iCloud将文件同步到iOS设备时,它将会首先在应用程序的容器中创建一个空的无数据文件,以通知您有可用的文件。这就是您的 NSMetadataQuery 报告。

When iCloud syncs a file to an iOS device, it will first create an empty, dataless file in your app's container to let you know there is a file available. This is what your NSMetadataQuery reports.

如果您查看的其他键NSMetadataItem ,您可能会注意到它表示您的商品尚未下载。

If you look at the other keys of your NSMetadataItem, you'll probably notice it says your item is not downloaded yet.

在能够复制该文件或打开它之前,你必须要求iCloud下载它。在项目的路径上进行协调读取(正如您应该在任何打开或复制操作中进行的那样)将隐式下载文件。

Before being able to copy that file or to open it, you have to ask iCloud to download it. Taking a coordinated read at the item's path (as you should do around any opening or copying operation) will implicitly download the file.

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

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