4

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 its (int) content as a badge.)

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

Thanks.

Bhadresh Kathiriya
  • 3,147
  • 2
  • 21
  • 41
Laurent Crivello
  • 3,809
  • 6
  • 45
  • 89

4 Answers4

4

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.

Mark Granoff
  • 16,878
  • 2
  • 59
  • 61
  • Thanks Mark. However I have the impression to (want to) do the same things than the email client on the iPhone. No push mechanism, but a pull every x minutes. Does the mail client have more advanced rights ? – Laurent Crivello Jun 08 '11 at 11:39
  • Most certainly it does. :-) There are definitely apps on iOS, provided by Apple, that do more than the rest of us can do legally. There are lots of private interfaces developers are not allowed to use. Surely among those private APIs are all the cool things Apple does in their apps (like complex background stuff) that we wish we could do in our own app! Over time, sometimes, Apple opens up some of these kinds of APIs, but it doesn't happen often. – Mark Granoff Jun 08 '11 at 12:32
3

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.

m1sh0
  • 2,236
  • 1
  • 16
  • 21
0

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

Community
  • 1
  • 1
José Manuel Sánchez
  • 5,215
  • 2
  • 31
  • 24
0

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

Mohan Meruva
  • 322
  • 1
  • 3
  • 11