model.GetPrediction method returns a null object when the iOS app is running in background mode. The method return correct predictions when app is in foreground. Has anyone else come across this issue?
Asked
Active
Viewed 114 times
1 Answers
2
Couple of things:
You have very limited time to execute arbitrary code when the app is Backgrounded
.
- You can check
BackgroundTimeRemaining
to determine how much time you have left. - You have to perform your predictions within a
BeginBackgroundTask
action
The foregrounded app (including Springboard) has priority over the GPU.
The foregrounded app GPU processing will not be interrupted to perform your background task-based prediction.
You can request predictions to use the CPU (
UsesCpuOnly
) by supplying theMLPredictionOptions
to your prediction call.
Your model should be restricted to the CPU if it might run in the background or if your app has other GPU intensive tasks.

SushiHangover
- 73,120
- 10
- 106
- 165
-
1Thanks for the quick reply. Enabling the UsesCpuOnly option returns valid predictions in the background. – Srini111 Feb 27 '18 at 20:59
-
1The `usesCPUOnly` flag was the solution for us as well. Posted sample code of how to do it here: https://stackoverflow.com/questions/48480610/error-computing-nn-outputs-error – Simon Bengtsson Mar 16 '18 at 13:30