Unable to run App Refresh BackgroundTasks Task, even in Apple Sample Code app

I am attempting to implement App Refresh with the Background Tasks framework and I cannot get the app to wake. Obviously I can get it to wake with debug functions, but I cannot seem to have the app refresh occur normally.

At first I assumed I was doing something wrong, so I went and downloaded the Refreshing and Maintaining Your App Using Background Tasks sample code. I edited it to OSLog every step of the way and ran that on two separate devices for over a day. One device is a test device for work, the other is my daily driver.

Upon inspecting the logs I'm not seeing any of my log messages indicating executions of the App Refresh Tasks, on either device.

Searching the logs with "com.example.apple-samplecode" provides a bunch of messages from dasd. It looks like when the app has first been loaded onto the phone it came up with a "Final Decision" of "Can Proceed" but then was immediately followed up with
Code Block plain
com.apple.duetactivityscheduler default 2021-02-16 10:48:29.767009 +1100 dasd scoring 'bgRefresh-com.example.apple-samplecode.ColorFeed.refresh:5EE83C' CurrentScore: 0.617755, ThresholdScore: 0.772525 DecisionToRun:0

Which seems like something made it decide it shouldn't run (based on "DecisionToRun:0").

Subsequent messages from dasd the decision always becomes "Must Not Proceed", with the vast majority of logs appearing like so
Code Block plain
com.apple.duetactivityscheduler default 2021-02-16 10:58:25.975816 +1100 dasd scoring bgRefresh-com.example.apple-samplecode.ColorFeed.refresh:5EE83C:[
{name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Must Not Proceed, Score: 0.00}}
 ], FinalDecision: Must Not Proceed}


Occasionally there'll be extra policies, but vast majority of the time it's just the ApplicationPolicy.

There seems to be one of those log entries, from dasd, quite frequently with the most frequent being mere tens of milliseconds, all the way up to 4 minutes; though the most common time between evaluation does appear to be ~30 seconds.

With nearing an additional day of running the app on both devices I am seeing within about a 3 hour window another dozen "Can Proceed" messages immediately followed by "DecisionToRun:0", but there haven't been any more for the last 10 or so hours. Obviously also none of my log messages are there either.

Is there something, obvious or otherwise, that am I doing wrong here?
I have the same issue. Did you figure something out already?

Hi,

I had a similar issue while doing some dev regarding Silent Push Notifications. I was sending notifications sall day long and finally met some limits:

	{name: CPUUsagePolicy, policyWeight: 5.000, response: {Decision: Must Not Proceed, Score: 0.00, Rationale: [{[Max allowed CPU Usage level]: Required:50.00, Observed:75.00},]}}
 ], FinalDecision: Must Not Proceed}

From this moment, the Push Notifications were not completely cancelled, but rather delayed until app was entering on Foreground.

Policy is not the same, but it seems I managed to reset the CPU Usage Level by incrementing the version of the app.

I could then see some device logs mentioning Relaxing scores on the next Notification reception.

default	17:14:43.708426+0200	dasd	com.apple.pushLaunch.***:9722B2:[
	{name: CPUUsagePolicy, policyWeight: 5.000, response: {Decision: Can Proceed, Score: 0.50, Rationale: [{cpuLevel == 50}]}}
 ] sumScores:94.410000, denominator:96.910000, FinalDecision: Can Proceed FinalScore: 0.974203}
default	17:14:43.709007+0200	dasd	'com.apple.pushLaunch.***:9722B2' has compatibility score of 0.917862 with 'com.apple.pushLaunch.***:1D1192'. Relaxing scores.
default	17:14:43.709773+0200	dasd	'com.apple.pushLaunch.***:9722B2' DecisionToRun:1 (Bypasses Predictions)

Hope it helps.

Unable to run App Refresh BackgroundTasks Task, even in Apple Sample Code app
 
 
Q