开发者

How to execute a function in background at specific intervals in iOS

I would like for my iOS app when it is in background mode to execute at specific intervals some functions (What I precisely want to do is to check a URL, and indicate 开发者_如何学Cits (int) content as a badge.)

However, I don't know how to have the function executed in the background.

Thanks.


Read about Executing Code in the Background. There is a limited set of things you can do in the background, what you describe not among them unfortunately.


I think you have two options to solve this problem each of them has pros and cons.

First, one is background refresh check the link. Have in mind that it is different for ios 13 and above. You need to define background tasks check here. It takes me some time to understand the background tasks but it seems more logical and easy to manage if you have several tasks. Still, you don't have the full control of when this task will be executed. It depends on how much battery, network and so on your task will use every time. The system will choose what is the best time to run it.

There is one more option, to implement a silent push notification check here. Here you can implement a good push mechanism for updates but you will depend on network and permission for notifications. Also, you will need a backend for this solution.

You need to define what works best for you.


I think the best option is to use the voip background mode. Here you can find all the required information: how to run background process on the iOS using private APIs to sync email items without jailbreaking the phone


https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_background_updates_to_your_app

To update the content frequently when the app is in the background might be difficult, Instead, you can wake the app by pushing a silent notification from backend at regular intervals. For more information check this article also https://medium.com/@m.imadali10/ios-silent-push-notifications-84009d57794c

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜