iOS Background Fetch mode can be used to schedule some operation in the future that doesn't actually fetch remote data?

南楼画角 提交于 2020-01-14 01:56:06

问题


I'm doing an app that requires to reschedule local notification on daily basis. I'm aware about the repeatInterval property, but repetitioon here is like each 2 days etc.
I've seen silent notifications, but they can be used only with push notifications and due to some requirements I can't use that approach.
Now the app works on the hypothesis that the user will open the app quite enough to reschedule those notifications. This hypothesis is fine and we all agree that will work, but I will be more confident, if it would be possible to reschedule them on daily basis without opening the app.
I've seen the new API Background Fetch, this could be really good for me, but from doc and WWDC videos I didn't understand if it is possible to use for "everything" or just to fetch remote data.


回答1:


As I understand you can do everything that does not take too long, plus you don't get a guaranteed interval when you app will be woken up - you just can request a certain minimum wake interval, which will be treated as a suggestion by iOS.

The only catch is that apparently you have to create an NSURLSession and actually do a web request, upon which return you can do whatever you want. So, you can do a dummy request and forget about any data you get returned, or maybe even create a failing request, as you are not interested in any real request at all - although I'm not sure what Apple will do when you implement the latter ...




回答2:


You can use repeatInterval property of localNotification

        localNotification.repeatInterval=NSWeekCalendarUnit;  

For daily basis you can use NSDayCalendarUnit




回答3:


No there are not API which can wake app after some time interval. In back ground fetch mode application will wake up after you set minimum time. Application will wake up any time after minimum time interval might be after 5 min or 1 sec. and that will decide system on application usage. so we can not take this approach, if you willing to retrieve remote data compulsory after some time interval.this may help u.

http://www.doubleencore.com/2013/09/ios-7-background-fetch/



来源:https://stackoverflow.com/questions/21982815/ios-background-fetch-mode-can-be-used-to-schedule-some-operation-in-the-future-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!