如何无限期地每隔1分钟运行一个iOS应用程序? [英] How to run an iOS application every 1 minute infinitely?
问题描述
我制作了一个需要每1分钟向服务器发送一次位置和状态更新的应用程序.我尝试了以下方法,但是没有一个方法可以帮助我.有什么解决办法吗?
I have made an application which needs to send Location and status update to server every 1 minute. I tried below ways but none of them helped me out. is there any solution for this?
1- NSTimer -许多人建议这样做.但是问题出在backgroundMode上,并且只能工作20分钟.该应用程序停止发送数据之后.
1 - NSTimer - Many people suggested to do this way. but the problem is going to backgroundMode and it only works for 20 minutes. after that application stops sending data.
2- BackgroundFetchMode -一开始看起来像是正确的解决方案.但是此功能不能保证每1分钟运行一次应用程序.它具有iOS决定应运行哪个应用程序的算法.
2 - BackgroundFetchMode - at beginning looks like the correct solution. But this ability do not guarantee to run application at every 1 minute. it has an algorithm that iOS decide which application should run.
此API与计时器任务不同,系统将决定何时调用处理程序取决于许多约束.因此,如果将timeInterval设置为2.00f(2secs),每2+(最小)秒调用一次处理程序.
This API is not like a timer task, system will decide when to call the handler depending on many constraints.so if you set timeInterval to 2.00f(2secs), handler is called for every 2+(minimum) secs.
3- LocationUpdate -再次以这种方式不起作用,因为它仅在您移动至少500米时才运行您的应用程序.
3 - LocationUpdate - again this way do not works because it only run your application if you move at least 500 meter.
设备移动500米后,应用程序可能会收到通知或之前的通知中的更多内容.它不应该期望通知的频率超过每五分钟一次.如果设备能够从网络,位置管理器中检索数据更有可能及时发送通知.
Apps can expect a notification as soon as the device moves 500 meters or more from its previous notification. It should not expect notifications more frequently than once every five minutes. If the device is able to retrieve data from the network, the location manager is much more likely to deliver notifications in a timely manner.
4-推送通知-在使用此方法的文章中,您可以在定义的时间内运行应用程序,并且确实可以运行!
4 - Push Notifications - in an article said in this method you can run an application within defined time and it really does !
您可以在定义的计划时间内安排通知.但问题是向用户显示通知.我需要在背景中保持沉默.
you can schedule a notification within defined schedule time. but the problem is showing notification to user. which I need something silent in Background.
此外,您不能每1分钟运行一些代码.它只是向用户显示通知.用户应该点击您的通知,然后点击didReceiveLocalNotification可用,您可以运行代码.
Also , you can not run some code every 1 minute. it just show a notification to user. and user should tap on your notification and then didReceiveLocalNotification can be available and you can run the code.