この方法は、 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];
}];
ただし、これは同期的であるため、非同期で何かを実行したい場合は、次のようにブロックを使用できます。
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
});
});