在未来的特定时间在 iOS 中运行后台任务 [英] Running a background task in iOS at a specific time in the future

查看:19
本文介绍了在未来的特定时间在 iOS 中运行后台任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 iOS 7 中连接后台任务(例如切换位置服务的使用)以在特定时间点(例如明天早上)运行而无需用户打开应用程序,或者无需经常运行后台进程?

Is there a way to wire a background task (such as toggling the use of location services) in iOS 7 to run at a specific point of time (e.g. tomorrow morning) without the user opening the app, or without having a constantly running background process?

我知道的唯一选择是在所需时间向设备发送推送通知,但有没有人知道任何纯设备上的替代方案?

The only option that I am aware of is to have a push notification sent to the device at the desired time, but does anyone know of any purely on-device alternatives for this?

推荐答案

任何纯设备端 - 不幸的是,直到现在 - 2014 年还没有这样的方法.Background task execution if content avaliable 出现在 iOS 7 中是件好事,但它是基于推送的.

所以当应用程序被挂起时,它不能做ANYTHING 来直接唤醒自己.它不能事先安排一个 NSTimer,它不能使用诸如 performSelector:afterDelay 之类的东西等等.ONLY 应用程序可以再次激活的方式是,如果 USER HIMSELF 执行某些操作使其处于活动状态,例如收到本地通知并弹出警报.只有当应用程序具有后台模式时,才允许在后台模式下长时间执行应用程序,这些模式是:语音、音频、位置、报亭.注意:从 iOS 9 开始,kCFStreamNetworkServiceTypeVoIP 现在已弃用,VoIP 应用程序应改用 PushKit(VoIP 高优先级推送通知).即使它具有这些类型之一,应用程序也无法在没有一些限制的情况下执行其代码.你可以在文档中阅读它.所以我们必须接受这种事态.可能在未来的某个时候,Apple 工程师将进行真正的多任务处理,或者至少在收到的本地通知上执行后台任务或为所有已安装的应用程序提供一些全局后台任务调度程序.但我不相信这一点,因为3-rd 方进程的有限后台执行是iOS调度器的核心设计,它是CMU Mach 3调度器的修改版本.

any purely on-device - unfortunately till now - 2014 there is no such ways. Background task execution if content avaliable appeared in iOS 7 is rather a good thing but it is push-based.

So when the app is suspended it cannot do ANYTHING to rouse itself directly. It cannot previously have scheduled an NSTimer, it cannot make use of something like performSelector:afterDelay and so on and so forth. The ONLY way the app can become active again is if the USER HIMSELF does something to make it active e.g local notification received and an alert poped up. Execution of an app in background mode for a long time is only allowed when an app has a background mode, theses modes are: voip, audio, location, newstand. Note: Starting in iOS 9, kCFStreamNetworkServiceTypeVoIP is deprecated now, and VoIP apps should use PushKit instead (VoIP high-prioirity push notifications). Even if it has one of these types an application cannot execute its code without some restrictions. You can read about it in the docs. So we have to accept this status of affairs. May be some time in a future Apple engineers will make a true multitasking or at least something like background task execution on local notification received or some global background tasks sheduler for all the apps installed. But I don't believe in this, because limited background execution of 3-rd party processes is a core design of iOS scheduler, which is a modified version of CMU Mach 3 scheduler.

这篇关于在未来的特定时间在 iOS 中运行后台任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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