Search code examples
swiftbackground-process

Warn the user loudly when the API response received


The project scenario is when the api response play warn voice or something.

It must send request in background.For example user active warn system using button(on/off) and close the app. App check datas every 5 seconds in background. When data == 1 play warn voice loudly. I looked notification systems and read some document for background. Which technologies should I use ? I've been using swift for 2 months. I'm trying to learn how to develop an app in iOS.


Solution

  • It sounds to me like what you are looking to do is schedule local notifications along with background fetch. However, you can't reliably use background fetch to ping a server every 5 seconds, like you suggest. At best you can suggest to the operating system that the minimum time interval between background tasks is 5 seconds but it could be much longer. There's no way to reliable run a service in the background when an app is entirely closed.

    More info:

    User notifications: https://developer.apple.com/documentation/usernotifications

    Background fetching: https://developer.apple.com/documentation/uikit/core_app/managing_your_app_s_life_cycle/preparing_your_app_to_run_in_the_background/updating_your_app_with_background_app_refresh