Reputation: 2022
I got a problem , How to know the file is accessible ???
For example , the file is writing , but not finish yet. And I check the file again ,
I use
[[NSFileManager defaultManager] fileExistsAtPath:filePath];
It return true ... but the file is not accessible .
How to determine the file is ready ?
Thanks
Webber
EDIT Maybe I'm not telling my problem clearly . I mean if you start transport a video file . before transport finish . the video file is not accessible , but you still can get a part of transporting file.
Upvotes: 4
Views: 943
Reputation: 14687
Basically you need to check the attributes of the file and particullary the NSFileBusy
attribute:
if ([fileManager fileExistsAtPath:filePath]) {
NSDictionary *attributes = [fileManager attributesOfItemAtPath:filePath error:nil];
NSLog(@"File Busy %@", [attributes objectForKey:NSFileBusy]);
}
Upvotes: 1
Reputation: 2312
Write Data in async way using GCD concept and once it is completed, the completion handler will be executed.(Where completion of a writing process shall be detected)
The dispatch I/O convenience API lets you perform asynchronous read and write operations on file descriptors. This API supports stream-based semantics for accessing the contents of the file-descriptor.
Method:
void dispatch_write ( dispatch_fd_t fd, dispatch_data_t data, dispatch_queue_t queue, void (^handler)(dispatch_data_t data, int error) );
Upvotes: 1
Reputation: 49
Try to fetch data of file by using following code :
NSURL *url = [NSURL fileURLWithPath:filePath];
NSData *readData = [NSData dataWithContentsOfURL:url];
Upvotes: 0
Reputation: 3017
NSFileCoordinator and NSFilePresenter are created just for that. You may find interesting Advanced iCloud Document Storage video from wwdc that covers the usage of this classes. Building a Document-based App will be great to watch too.
Upvotes: 0