fluttercommunity / fluttercommunity/flutter_downloader

Plugin causes iOS App to be treated as a Bad Citizen

Open
#414 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
940
Forks
561
Avg merge
1h 18m
Merged PRs (30d)
1

Description

When reinstating an app from the background, the urlSessionDidFinishEvents delegate method is called. From observations on simulator and running devices, it is possible for this delegate callback to be invoked before all the events in the queue have been processed.

In the handler, this plugin checks to see if there are any download tasks still in the queue (using getTasksWithCompletionHandler). If the count is > 0, then the background completion handler is not called. Our observation is that more often than not, the count of tasks is > 0. This results in the background completion handler never being called. This is not recommended by iOS and the developer docs specifically state that repeated failure to call the background completion handler (signalling the OS that your app has finished processing tasks) results in future background time restrictions (the app can be classed as a Bad Citizen).

The developer documentation specifically states that urlSessionDidFinishEvents is only called when all events have been processed:

"Tells the delegate that all messages enqueued for a session have been delivered.".
and
"When your app later receives a urlSessionDidFinishEvents(forBackgroundURLSession:) message, this indicates that all messages previously enqueued for this session have been delivered, and that it is now safe to invoke the previously stored completion handler or to begin any internal updates that may result in invoking the completion handler."

Does the plugin need to check for outstanding tasks in this event? Also, it appears that the callback handler should be specifically invoked from the main thread, which the plugin does not do.

See https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622941-application?language=objc for notes about the completion handler.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the plugin's urlSessionDidFinishEvents delegate implementation and compare its task-count check and callback-thread handling with the Apple documentation linked in the issue. Reproduce background-session reinstatement on a simulator or device, then verify that queued events are fully handled and the stored background completion handler is invoked on the main thread.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.