0

I have a working Alamofire upload request using the following:

Alamofire.upload(multipartFormData: { multipartFormData in
    ...
}

Now I want the request to be launched in background, as it's embedded in a Share extension.

Looking at Alamofire page, I simply added:

let configuration = URLSessionConfiguration.background(withIdentifier: "com...")
let sessionManager = Alamofire.SessionManager(configuration: configuration)

sessionManager.upload(multipartFormData: { multipartFormData in
    ...
}

Now when executed I instantly get:

Operation couldn't complete. NSURLErrorDomain error -995

I can't find any reference to this error and what it means. Any ideas? Thanks a lot!

pacification
  • 5,838
  • 4
  • 29
  • 51
lorenzo
  • 1,487
  • 1
  • 17
  • 25
  • Press command-shift-O and then search for `NSURLError` and you'll see `-995` is `NSURLErrorBackgroundSessionRequiresSharedContainer`. Are you doing this in an extension? – Rob Sep 13 '17 at 14:25
  • Yes I do, is there anything to add? Thanks! – lorenzo Sep 13 '17 at 14:32
  • 1
    Go to target properties, choose "capabilities" and turn on app group. See https://stackoverflow.com/a/42172748/1271826. – Rob Sep 13 '17 at 14:35
  • Ok had to specify it in the sessionManager. Now I have a "cancelled" error. Back to your 1st comment, I don't see the error code numbers when I open NSURLError. – lorenzo Sep 13 '17 at 14:40
  • In Xcode 9 you will see the numbers. In Xcode 8 you have to open an Objective-C file before you hit command-shift-O (create a blank Objective-C project if you want). – Rob Sep 13 '17 at 14:46
  • Ok solved my issues. Please make an official answer with: configuration.sharedContainerIdentifier = Config.appGroupName so I can validate – lorenzo Sep 13 '17 at 15:20

0 Answers0