每天在后台的特定时间从iOS调用网络服务 [英] Call a web service from iOS at a particular time daily in the background

查看:67
本文介绍了每天在后台的特定时间从iOS调用网络服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法安排每天在特定时间调用网络服务的功能?

Is there a way to schedule a function which calls a web service at a particular time on a daily basis?

根据我的研究,我将不得不使用本地通知或 NSTimer 安排或在特定时间调用该函数。
但是无论我的应用程序是在计划时间在后台(而不运行任何后台任务)还是在前台,我都需要这样做。

According to my research, I will have to use local notifications or NSTimer to schedule or call the function at a specific time. But I need this to work whether my application is in the background at the schedule time (and not running any background task), or in the foreground.

有两种情况:
1.位置服务在我的应用程序中在后台运行
2.没有位置或后台服务在运行,或者应用程序处于挂起状态(如果用户禁用了位置更新)

There are two cases: 1. Location service is running in the background in my application 2. No location or background service is running, or the app is in the suspended state (if the user disabled location updates)

但是我必须每天在计划的时间向服务器发送一些状态。

But I have to send some status to my server at the scheduled time daily.

推荐答案

您有以下选择。


  1. 静默通知:静默推送通知是从服务器推送的,表明现在是时候了,您需要调用Web服务并进一步执行必要的任务。您将在 30秒左右的时间内完成任务。现在请注意,在此期间不必打开您的应用程序,因为这将在后台完成,而不会打开您的应用程序。

  1. Silent Notification : A silent push notification is pushed from the server, indicating that now is the time, you need to call the webservice and further do the necessary tasks. You will have around 30 seconds to complete the task. Now notice that during this it is not necessary that your app is opened, as this will be done in the background, without your app not opening.

关注

链接此处可通过静音通知配置项目

Follow this link here to configure your project with silent notification

基于位置(地理/位置更改):您可以通过为应用提供一个位置来管理您的应用,只要该应用进入/存在/位置都会更新到该位置附近

Location based (Geofencing / Location Change) : Well you manage your app by giving it a location, that whenever it enters/ exists / location is updated near to / on that particular location, the app even if terminated, will be launched in the background.

applicationDidBeginLaunchingWithOptions 会在特定位置(即使终止)也将在后台启动。
特定密钥,通知此应用是从
位置更改启动的。

applicationDidBeginLaunchingWithOptions will be called with a specific key notifying that this app was launched from a location change.

按照
链接配置您的应用相应地。现在需要注意的是,这
不会取决于时间,而是一个或多个特定位置,
会适合您。

Follow this link to configure your app accordingly. Now the caveat here is this wont depend on time, but rather a particular location or locations, whichever suits you.

UILocalNotification Push Notification :但在两种情况下,都不能保证用户将与通知横幅进行交互并首先打开应用程序。

UILocalNotification or Push Notification : But in both cases, its no guarantee that user will interact with the notification banner and open the application in the first place.

因此,在第一个选项中,您无需用户与设备交互(设备必须连接到互联网)即可完成工作基于位置的更改和基于位置的更改,在第二个选项中,用户必须与设备进行交互(通知标题)。请选择最适合您的需求。

Hence in the first option, you can do the work without the user interacting with the device (Device has to be connected to the internet) on Time based and Location based changes and in the second option User has to interact with the device (notification banner). Please choose the one best for your requirement.

这篇关于每天在后台的特定时间从iOS调用网络服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆