Perform background tasks when app is terminated

前端 未结 3 660
盖世英雄少女心
盖世英雄少女心 2020-11-29 08:36

I\'m creating an application for my school which should check every n minutes if there is a new mark on the website. To do this when the user login for the first time, the n

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 09:11

    You have two options

    1. Background App Refresh
    2. Silent push notifications

    Easiest one is Background App Refresh. Because later one needs a server to send the notification. You can check following API for the usage. Basically you set Background Fetch capability on Capabilities/Background Modes of your app. Then from time to time, iOS will wake up your app and call application(_:performFetchWithCompletionHandler:) delegate. You will have around 30-45 seconds to call your function and call completion handler. If you don't finish it on time, iOS will kill your app. If you don't obey the rules, iOS will give you less chances to wake up. For more detailed usage of Background Modes, you may check following tutorial

提交回复
热议问题