iCloud: Callback for NSFileManager#39;s startDownloadingUbiquitousItemAtURL?(iCloud:NSFileManager 的 startDownloadingUbiquitousItemAtURL 的回调?)
问题描述
我正在使用 NSFileManager
的 startDownloadingUbiquitousItemAtURL
将文件从 iCloud 下载到本地副本(在这种情况下本地还没有文件的副本).我似乎找不到这个过程的回调.我需要回调来告诉我的应用程序请求的文件已完成下载(到本地副本),以便其他任务可以开始读取文件的内容并执行操作.
I am using NSFileManager
's startDownloadingUbiquitousItemAtURL
to download file from iCloud to local copy (the local does not yet have the copy of the file in this case). I can't seem to find the callback for this process. I need the callback to tell my app that the requested file is finished downloaded (to local copy) so other task can start reading the content of the file and does stuff.
我可以检查文件是否已下载.但它会涉及不断的轮询.有没有办法在不设置计时器来轮询的情况下做到这一点?
I can check to see if the file is downloaded. But it would involve in polling constantly. Is there a way to do this without setting a timer to poll for this?
推荐答案
我相信这个方法打算和基于Apple 的文档.所以你需要像这样使用文件协调器:
I believe that this method is intended to be used in conjunction with file coordinators based on Apple's documentation. So you would need to use a file coordinator like so:
NSURL *itemURL = nil; // this is the URL you want to read from
__block NSData *data = nil;
NSError *error = nil;
NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
[coordinator coordinateReadingItemAtURL:itemURL options:0 error:&error byAccessor:^(NSURL *newURL) {
data = [NSData dataWithContentsOfURL:newURL];
}];
不过,这将是同步的,因此如果您想异步执行某项操作,可以这样使用块:
This will be synchronous, however, so if you wanted to do something asynchronously, you could use blocks as so:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// read info from the URL using the code above
dispatch_async(dispatch_get_main_queue(), ^{
// handle data read from the URL
});
});
这篇关于iCloud:NSFileManager 的 startDownloadingUbiquitousItemAtURL 的回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iCloud:NSFileManager 的 startDownloadingUbiquitousItemAtURL 的
基础教程推荐
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01