If you’re building library code that uses
URLSession
background sessions you must provide an entry point that the app can call when it gets the
application(_:handleEventsForBackgroundURLSession:completionHandler:)
app delegate callback. Beyond that I don’t think there’s any other restrictions here.
With regards the code snippet you posted, here’s a version with line numbers:
extension BackgroundUpload: URLSessionDelegate
{
@nonobjc func urlSessionDidFinishEvents(forBackgroundURLSession session: URLSession) {
DispatchQueue.main.async {
// Call back is not getting called.
}
}
}
You’ve indicated that you never get to line 6. What about to line 4? If you get to 4 but not 6, there’s clearly a problem with getting to the main thread.
Also, what’s up with the
@nonobjc
attribute on line 3? This method is expected to be called from Objective-C, because that’s what
NSURLSession
is implemented using, so marking it as
@nonobjc
is incorrect.
Note You can mark code snippets as code using the
<>
icon, and doing so makes it easier to discuss the details.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"