[英]How to call web services in background using specific time interval?
i know that this questions may be repeated some times but i need some clarifications so i asked here. 我知道这个问题可能会重复几次,但是我需要澄清一下,所以我在这里问。
My requirement is I got location using my iPhone every 20 sec and update my Web Application using the web services.It's also working on Background. 我的要求是我每20秒钟使用iPhone定位一次,并使用Web服务更新Web应用程序。它也可以在Background上运行。
I know that i will got the location in background using the Background Fetch but i little confuse here.I want to update My web database every 20 sec using web services. 我知道我将使用“后台提取”在后台获取该位置,但是我在这里有点困惑。我想使用Web服务每20秒更新一次我的Web数据库。 is it possible to update Web database every 20 second using web service in Application Background mode?
是否可以在应用程序后台模式下使用Web服务每20秒更新一次Web数据库?
Thanks in advance. 提前致谢。
No. Minimal interval when your app "wakes up" in background mode is 6-10 minutes. 否。您的应用在后台模式下“唤醒”的最小间隔为6-10分钟。 If your phone is active and unlocked.
如果您的手机处于活动状态且已解锁。 If your phone is "sleeping", this interval may be some hours.
如果您的手机处于“睡眠”状态,则此间隔可能需要几个小时。
In your project ->capabilities->background modes turn on "background fetch" 在您的项目中->功能->后台模式打开“后台获取”
In your appDelegate 在您的应用程序中
-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { //Add your code here You will have 30 sec. to do all that you want in background mode completionHandler(UIBackgroundFetchResultNewData); }
Try to use NSURLSession
using its task you can do background upload and download. 尝试使用
NSURLSession
通过其任务可以执行后台上传和下载。
After 1st request complete start timer which start the second request. 在第一个请求之后,完成启动计时器,该计时器将启动第二个请求。
Good tutorial for NSURLSession
is here.. NSURLSession
好教程在这里。
tutsplus (its 4 part tutorial) tutsplus (第4部分教程)
Here 这里
And check the NSURLSession
document here .. 并在此处检查
NSURLSession
文档。
Its supported in iOS7+. 它在iOS7 +中受支持。 But if user force close the application it will be stopped.
但是,如果用户强行关闭应用程序,它将停止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.