use*_*234 14 ios ios5 icloud icloud-api
我使用NSFileManager的startDownloadingUbiquitousItemAtURL从iCloud的本地副本(本地还没有文件在这种情况下副本)下载文件.我似乎找不到这个过程的回调.我需要回调告诉我的应用程序所请求的文件已完成下载(到本地副本),因此其他任务可以开始读取文件的内容并执行操作.
我可以检查文件是否已下载.但它会不断涉及民意调查.有没有办法在没有设置计时器的情况下执行此操作?
wby*_*ung 29
我相信这种方法可以与基于Apple文档的文件协调器一起使用.所以你需要使用像这样的文件协调器:
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];
}];
Run Code Online (Sandbox Code Playgroud)
但是,这将是同步的,因此如果您想要异步执行某些操作,可以使用块,如下所示:
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
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4262 次 |
| 最近记录: |