I am downloading a file using NSURLSessionDownloadTask. it get downloaded and saved. and I can display data normally.
Unfortunitly I only have the iOS simulator to test. What is happenning if I close the app with the stop button on Xcode. then I relaunch, the file is no longer exists.
But, If I closed it by removing it from apps. running list by clicking cmd + shift + H twice. and reluanch it by tapping app. on simulator. I find the file.
BOOL found = [[NSFileManager defaultManager] fileExistsAtPath:path];
Is this a simulator problem? and I shouldn't worry about it in a real device?
Actually, I just managed to test on iPhone. exactly the same behaviour!! Any explanation.
I call this on the NSURLSessionDownloadTask
which I sent a destination block that returns the destination to save:
- (NSURLSessionDownloadTask *)downloadTaskWithRequest:(NSURLRequest *)request
progress:(NSProgress * __autoreleasing *)progress
destination:(NSURL * (^)(NSURL *targetPath, NSURLResponse *response))destination
completionHandler:(void (^)(NSURLResponse *response, NSURL *filePath, NSError *error))completionHandler
Destination block code:
NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSLibraryDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]];