在iOS中运行后台服务 [英] Running background services in iOS

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

问题描述

我需要编写一个每30分钟向服务器发送一次数据的iOS应用程序。当应用程序在后台时,这可以工作吗?它的可靠性如何?

I need to code an iOS app that sends data to server every 30 minutes. Can this work when the app is in the background? How reliable it can be?

推荐答案

在您请求的时间间隔内无法永久执行后台任务。您可以通过开发者连接请求特定权限,但我必须警告您,您需要一个非常有说服力的论点。我包含了下面的文档,也许您的请求属于可以永久运行的分组之一。或者也许您可以使用其中一个长时间运行的后台线程并使其适应您正在尝试的任务。

There is no way to perform tasks in the background permanently at the interval of time you are requesting. You may request specific permission via the developer connection but I must warn you that you will need a very compelling argument. I included the documentation below, maybe your request falls within one of the groupings that could run permanently. Or maybe you could use one of the long running background threads and adapt it in such a way that it fulfils the task you are attempting.

直接来自Apple的文档:

Directly from Apple's Documentation:

对于需要更多执行时间来实现的任务,您必须请求特定权限在后台运行它们而不会被暂停。在iOS中,只允许特定应用类型在后台运行:

For tasks that require more execution time to implement, you must request specific permissions to run them in the background without their being suspended. In iOS, only specific app types are allowed to run in the background:


  • 在后台播放用户可听内容的应用,
    ,例如音乐播放器应用

  • 让用户随时了解其
    位置的应用,例如导航应用支持
    语音的应用需要
    下载和处理新内容的互联网协议(VoIP)报亭应用程序

  • 从外部附件接收定期更新的应用程序

实施这些服务的应用程序必须声明它们支持的服务,并使用系统框架来实现这些服务的相关方面。声明服务可以让系统知道您使用哪些服务,但在某些情况下,系统框架实际上会阻止您的应用程序被暂停。

Apps that implement these services must declare the services they support and use system frameworks to implement the relevant aspects of those services. Declaring the services lets the system know which services you use, but in some cases it is the system frameworks that actually prevent your application from being suspended.

〜/ End of Line

~/End of Line

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

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