简体   繁体   English

如何使用特定时间间隔在后台调用Web服务?

[英]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. 如果您的手机处于“睡眠”状态,则此间隔可能需要几个小时。

  1. In your project ->capabilities->background modes turn on "background fetch" 在您的项目中->功能->后台模式打开“后台获取”

  2. 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.

相关问题 如何使用Swift 4 iOS在特定时间间隔内更新用户的后台位置? - How to update background location of user within specific time interval using swift 4 iOS? 具有特定时间间隔的iOS后台任务 - IOS Background task with specific time interval 如何使用Swift在iOS的特定时间缓存从Web服务获取的数据? - How to cache data get from web services for specific time in iOS using Swift? 仅当应用程序在后台运行且时间间隔为一小时时,如何调用方法数据 - How to call a method data, only when app is in background, with a time interval of one hour 当应用未运行时,在后台按固定的时间间隔重复调用一个函数 - Call a function repeatedly in fixed interval of time in background when the app is not running 如何使用iOS SDK在cellForRowAtIndexPath方法中调用Web服务 - How can I call the web services in cellForRowAtIndexPath method using iOS sdks 如何对iOS相机胶卷中的视频采取特定的时间间隔? - How to take specific time interval on videos from Camera Roll on iOS? iPhone:过一会儿,停止使用后台位置服务 - iphone : using Background location services is stopped after a little time 每天在后台的特定时间从iOS调用网络服务 - Call a web service from iOS at a particular time daily in the background 如何在特定时间在后台下载/获取数据? - How to downlad/fetch data in background at specific time?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM