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;