Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSURLSession: Could not communicate with background transfer service

When trying to create a NSURLSessionUploadTask using AFNetworkings AFURLSessionManager in a share extension I keep getting an error. The delegate for the session keeps getting called for

- (void)URLSession:(NSURLSession *)session didBecomeInvalidWithError:(NSError *)error

With the error

Error Domain=NSURLErrorDomain Code=-996 "Could not communicate with background transfer service" UserInfo=0x60800007a6c0 {NSLocalizedDescription=Could not communicate with background transfer service}

This happens if the app has a session and then the share extension tries to make a session. To init the session I do the following in both the app and the share extension.

NSURLSessionConfiguration* config = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:kSHARE_UPLOAD_SESSION];
config.sharedContainerIdentifier = kAPP_GROUP;
self.sessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:config];
self.sessionManager.attemptsToRecreateUploadTasksForBackgroundSessions = YES;
like image 994
datinc Avatar asked Oct 23 '25 21:10

datinc


1 Answers

You must use a different "Identifier" (kSHARE_UPLOAD_SESSION) for the main app & the extension. You apparently cannot have 2 NSURLSession with the same identifier running at the same time. You should keep the same group though (kAPP_GROUP)

like image 115
user2962499 Avatar answered Oct 25 '25 11:10

user2962499



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!