Reputation: 127
I would like that my app could make a small api call to a server so that it checks if there is an update, the data is very small and it shouldn't require that much time to execute, if it fails, it's not a problem that will try the next 15 minutes. It will show a generic notification to the user, so that the real data update will be done when the app is loaded. I know how to do the notification part, but not the api call.
The app should do this call when it's in the background and even if the user closes it from the multitasking UI and auto start when the device is turned on but the app hasn't been opened once yet.
In Android you can archieve this with the AlarmManager
but from what I understand there is no way for this on iOS other than remote push notifications?
Upvotes: 2
Views: 1645
Reputation: 10078
In the iOS part, you can achieve it with Backgrounding with Tasks. However, iOS backgrounding is much more restrictive than on Android as there are only a few specific tasks that apps are allowed to do in the background (things like VOIP, audio, location, etc.). You can use a UIApplication background task to delay that suspension for a few minutes, but you can’t delay it indefinitely.
public override void DidEnterBackground (UIApplication application) {
nint taskID = UIApplication.SharedApplication.BeginBackgroundTask( () => {});
new Task ( () => {
DoWork();
UIApplication.SharedApplication.EndBackgroundTask(taskID);
}).Start();
}
The other approach is using remote notifications which means applications can register to receive notifications from a provider, and use the notification to kick off an update before the user opens the application.
Upvotes: 2