Network Call (Rest API) Fails During iOS Background Task Execution

Issue Statement: I am encountering difficulties with executing network calls from within a Flutter method during iOS native background task handling.

Background: In my iOS Flutter application, I've implemented background task handling using native iOS code (Swift), leveraging the BGTaskScheduler's BGProcessingTask provided by iOS. The background task is set up to perform periodic network requests, but the network calls are made through a Flutter method invoked via platform channels from the iOS code.

Problem Description: While the background task executes as expected and invokes the Flutter method successfully, the network calls initiated within the Flutter method fail to complete during background task execution. The method execution seems to proceed up to the point of initiating the network call, but the call itself does not complete successfully.

It’s hard to say what’s going on here without knowing more about how your third-party tools uses Apple’s APIs. My advice is that you create a small test project, using one of Xcode’s built-in templates, to explore the relationship between Background Tasks framework and URLSession. If you have problems with that, I’m happy to help. OTOH, if your test project works as expected but you still have problems in your main app, that’s something you should escalate via the support channel for your third-party tools.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Network Call (Rest API) Fails During iOS Background Task Execution
 
 
Q