What can we use instead of nstimer?

為{幸葍}努か 提交于 2019-12-10 15:02:16

问题


I can get the GPS location in the background using [locationManager startUpdatingLocation], but I don't know how to schedule it. I have used NSTimer for scheduling but many of them are saying that NSTimer will get expire if the application enters background.

I want to know how to schedule calling the method , if we are not using NSTimers.


回答1:


Apple provides 5 kinds of app task to run in background:

  • Apps that play audible content to the user while in the background, such as a music player app
  • Apps that keep users informed of their location at all times, such as a navigation app
  • Apps that support Voice over Internet Protocol (VoIP)
  • Newsstand apps that need to download and process new content
  • Apps that receive regular updates from external accessories

Refer this link for location updates while app is in background

Also refer this tutorial for further help




回答2:


We can use Push Notification instead of NSTimer for scheduling as shown:-

http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html

Hope it helps.Thanks :)




回答3:


I think you can use this :

[self performSelector:@selector(_yourMethod) withObject:nil afterDelay:delay_in_milliseconds];


来源:https://stackoverflow.com/questions/10169241/what-can-we-use-instead-of-nstimer

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