iOS background process similar to Android AlarmMan

2020-07-06 02:42发布

I've to schedule a fixed task that check some info from internet at fixed interval timer.

Into Android, I use AlarmManager with setRepeating, but I'm newbie to iOS. There are some similar api that help me? I need a task that survive when app is killed by operating system.

Do you know a tutorial about it?

5条回答
在下西门庆
2楼-- · 2020-07-06 03:24

You may use NSBackgroundActivityScheduler to pull something periodically.

查看更多
看我几分像从前
3楼-- · 2020-07-06 03:35

Check link on Apple's Multitasking Guide that add's the voip tag to UIBackgroundModes in Info.plist and use setKeepAliveTimeout:handler: method of UIApplication to relaunch it if needed once the app is going to sleep.

Note : For this you need to take special permissions from Apple and mostly Apple rejects such app.

Another solution :-

You can store last sync date and if sync date has crossed your interval when application comes from background, you can start sync your data.

Hope this info helps you..

查看更多
干净又极端
4楼-- · 2020-07-06 03:39

AFAIK in iOS you cannot implement such service that will stay alive after its host app is killed, also only several types of applications can run some background tasks - see documentation here. You can do your task on server side and send push notification when you need users attention - if only user will allow your app to receive push notifications.

查看更多
甜甜的少女心
5楼-- · 2020-07-06 03:42

I found that UILocalNotification was the best option for this. Unfortunately you cant trigger the app to open but you can get a notification to show up at a set interval.

https://developer.apple.com/library/ios/documentation/iPhone/Reference/UILocalNotification_Class/index.html#//apple_ref/doc/c_ref/UILocalNotification

查看更多
SAY GOODBYE
6楼-- · 2020-07-06 03:44

You need local notifications of iOS

查看更多
登录 后发表回答