I am getting the following crash on crashlytics which I can not reproduce on my device
Fatal Exception: NSGenericException
Task created in a session that has been invalidated
at the following line
NSURLSessionTask *task = [self.session uploadTaskWithRequest:request fromFile:filePathURL];
[task resume];
[self.session finishTasksAndInvalidate];
I handled session invalidation at the delegate method
- (void)URLSession:(NSURLSession *)session didBecomeInvalidWithError:(NSError *)error {
// Crashlytics logging
[CrashlyticsKit setBoolValue:true forKey:@"URLSession_didBecomeInvalid"];
self.session = [self createNewSession];
}
- (NSURLSession *)CreateSession {
NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:SERVER_URL];
if (@available(iOS 11.0, *)) {
sessionConfig.waitsForConnectivity = YES;
}
return [NSURLSession sessionWithConfiguration:sessionConfig delegate:self delegateQueue:nil];
}
after uploading a new build, I still have the same crash and no Crashlytics logs at "didBecomeInvalidWithError
" at all!
any idea how to solve this crash?
didBecomeInvalidWithError
ever called? I guess what I'm trying to find out is: are you sure this method is implemented in some object that really is the URLSession delegate? — Also: are you conscious that a URLSession retains its delegate? This causes tricky memory management issues. What are you doing about that? — Also, please showcreateNewSession
. – BaptistdidBecomeInvalidWithError
when it finish uploading the files later it works again when trying to upload files but on production I got this crash – Dukenil
yoursession
reference so you won’t use it again. Alternatively, if you might ever need to use it again, just don’t invalidate it. Especially in the case of background sessions, IMHO. – Chivaree