AFNetworking 3.0 continuing upload when app moves to background
<p>My app initiates uploading content to a server while in the foreground. Since this process could take some time, the user could very well transition the app to the background. </p>

<p>I'm using AFHTTPSessionManager to submit the upload:</p>

<pre><code>let sessionManager = AFHTTPSessionManager()
sessionManager.requestSerializer.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-type")
sessionManager.POST(urlStr, parameters: params, constructingBodyWithBlock: { (formData) -&gt; Void in
    formData.appendPartWithFileData(dataObject, name: "object", fileName: mimeType == "image/jpg" ? "pic.jpg" : "pic.mp4", mimeType: mimeType)
}, progress: { (progress) -&gt; Void in
}, success: { (task, responseObject) -&gt; Void in
    print(responseObject)
    success(responseObject: responseObject)
}, failure: { (task, error) -&gt; Void in
    print(error)
    if let errorData = error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] as? NSData {
        do {
            let json = try NSJSONSerialization.JSONObjectWithData(errorData, options: NSJSONReadingOptions.MutableContainers)
            failure(error: error, responseObject: json)
        } catch let error {
            print(error)
        }
    }
})
</code></pre>

<p>I need this process to continue while the app is in the background state until completion. There's an excellent SO answer <a href="https://stackoverflow.com/a/21359684/2410991">here</a> which has gotten me on the right track, but I'm still in the dark in some places. I've tried using the "BackgroundSessionManager" class from the linked answer to change my upload call to this:</p>

<pre><code>BackgroundSessionManager.sharedManager().POST(NetworkManager.kBaseURLString + "fulfill_request", parameters: params, constructingBodyWithBlock: { (formData) -&gt; Void in
    formData.appendPartWithFileData(dataObject, name: "object", fileName: mimeType == "image/jpg" ? "pic.jpg" : "pic.mp4", mimeType: mimeType)
}, progress: nil, success: nil, failure: nil)?.resume()
</code></pre>

<p>And added this to my AppDelegate:</p>

<pre><code>func application(application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: () -&gt; Void) {
    BackgroundSessionManager.sharedManager().savedCompletionHandler = completionHandler
}
</code></pre>

<p>But I'm getting an EXC_BAD_ACCESS crash on some background thread with little to no information. Am I even approaching this correctly?</p>