BGTaskScheduler ColorFeed sample project doesn't work

I was trying to implement the BGTaskScheduler but couldn't get it working than tried it with the sample project provided by Apple. I tried to run it on latest Xcode beta and latest iOS beta but can't get the background tasks to work. I tried the BGAppRefreshTaskRequest, didn't modify that and slighty modified BGProcessingTaskRequest so it would also be scheduled every x minutes. But in the console you can see it keeps rejecting it.


Example of the console:

bgRefresh-com.example.apple-samplecode.ColorFeed.refresh:63693C:[

{name: DataBudgetPolicy, policyWeight: 1.000, response: {Decision: Must Not Proceed, Score: 0.00, Rationale: [{[/system/budgets/networking]: Required:1.00, Observed:0.00},]}}

], FinalDecision: Must Not Proceed}


bgProcessing-com.example.apple-samplecode.ColorFeed.db_cleaning:E319C7:[

{name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Must Not Proceed, Score: 0.00}}

{name: DeviceActivityPolicy, policyWeight: 5.000, response: {Decision: Must Not Proceed, Score: 0.00, Rationale: [{launchType == PROCESSING AND deviceActive == 1}]}}

], FinalDecision: Must Not Proceed}


I tried everything I could think of. Even when the iPhone X is fully charged and on charger, it doesn't matter.


The implementation looks quite simple but if the sample code doesn't even run correct what else could you do.


Can someone help me please?

Replies

I have the same problem. Did everything according to the WWDC video and I can trigger execution via lldb _simulateLaunchForTaskWithIdentifier, but other than that, it's never executed. Is there any way to analyze whats going on?

Also interested in hearing anyone that has gotten BGProcessingTasks or BGAppRefreshTasks to trigger in the "real world". Nothing I do seems to make a difference and no projects that are supposed to "teach" how-to use them work.

I have the same issue. Too many things seem to conspire to prevent it from actually happening.


1) Thermal state

2) CPU usage

3) a mysterious Device Activity Policy

4) Thundering herd event, which seems to require at least 15 minutes before relenting

5) and finally this "DataBudgetPolicy, policyWeight: 1.000, response: {Decision: Must Not Proceed, Score: 0.00, Rationale: [{[/system/budgets/networking", which happens reliably whenever I switch from Wifi to cellular (I have ATT unlimited) - very occasionally, it seems to work in the wee hours - maybe I was hallucinating...., but during the day, the problem happens most reliably.


I understand Apple's issue with too many apps trying to grab precious background resources with dynamic fluctuations, but trying to juggle a few ad-hoc criteria to allow/reject background notifications and/or background tasks is just inviting trouble.


My app requires only a few robust silent push notifications that can wake up the app from suspension, but without requiring user intervention. It is probably a relatively feather-weight requirement(**) compared to various other usage scenarios, but as of now, I cannot achieve that. Apple should at least allow a budget, i.e. a number of total such tasks allowed per day per app before being limited by these intractable constraints.

Personally, I wouldn't mind having just about a dozen such BGRefresh events allowed per day unconditionally before being shut out for the rest of the cycle. Is this asking too much?

(**: parsing a simple payload in the silent notification and adjust the app badge icon number accordingly.)

Post not yet marked as solved Up vote reply of sryu Down vote reply of sryu

First of all, you have such record:

"launchType == PROCESSING AND deviceActive == 1"

which probably means that you shouldn't keep your device unlocked while waiting for background task.


The other thing i've noticed is that chance for background launch to happen in the future is much higher if you don't kill the app from App Switcher.


In our case, when app killed from switcher, ApplicationPolicy says Must not proceed for some reason:

[{name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Must Not Proceed, Score: 0.00}}], FinalDecision: Must Not Proceed}

I have the same problem on iPad (6th generation) with iPadOS 13.6.
Actually the ColorFeed example is working well on my other device (iPhone 8 - iOS 13.5.1). I have added a small enhancement that using local notification whenever we receive background fetch event. But it didn't work on my iPad. I have not received any events for few days.