Sporadic Can not Read file Error - File does not exist

I sporadically receive an error message

*** Application termination due to the uncaught exception "NSInvalidArgumentException", reason: "Cannot read the file in the file: ///var/mobile/Applications/D743821C-6F34-4E97-8FBA-D7EAD6738E38/Documents/contacts.zip

*** The first roll stack calls: (0x2ef1ef83 0x39799ccf 0x2eb5f7c3 0x2eb5f2dd 0x39c8181f 0x39c87677 0x2eb5f289 0x2eb9897f 0x172cb9 0x17bac3 0x5b769 0x160d99 0x69f2d 0x698cb 0x1709c7 0x17a9a3 0x39c81833 0x39c88ad7 0x39c88d29 0x39dc3bd3 0x39dc3a98) libS ++ abi.dylib: completion with uncaught exception type NSException

The program crashes on a line

Info.uploadTask = [self.session uploadTaskWithRequest:request fromFile:url]; 

When I look in the device container, I see that the file is not there.

I do not understand

  • why exists when checking the path if the file does not exist
  • why the program does not work, even if it is in the catch try block

     NSString *path = file.myPath; if ([[NSFileManager defaultManager] fileExistsAtPath:path]) { @try { NSURL *url = [NSURL fileURLWithPath:path]; Info.uploadTask = [self.session uploadTaskWithRequest:request fromFile:url]; } @catch (NSException *exception) { BLog("error Reading file:%@",path); return; } } else { BLog(@"file not found:%@",path); return; } 
+5
source share
1 answer

So, I had exactly the same problem - NSURLSession could not read the file for some reason. However, I can catch the exception using the same code that you have. I created a category for convenience:

 @implementation NSURLSession (DMAdditions) - (NSURLSessionUploadTask * _Nullable)crashFreeUploadTaskWithRequest:(NSURLRequest *)request fromFile:(NSURL *)fileURL { @try { return [self uploadTaskWithRequest:request fromFile:fileURL]; } @catch (NSException *exception) { NSLog(@"We crashed: %@", exception); return nil; } } @end 
+1
source

Source: https://habr.com/ru/post/1206480/


All Articles