如何在iOS 7应用上启用后台更新 [英] How to enable background update on iOS 7 apps

查看:82
本文介绍了如何在iOS 7应用上启用后台更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何启用我的应用以使用iOS 7后台更新功能?我注意到一些应用程序已经这样做了,但它似乎并不是全自动的。

How can I enable my app to use iOS 7 background update capability? I notice some apps already do it, but it doesn't seem to be automatic for all.

推荐答案

根据 iOS 7中的新功能,您所寻找的内容被描述为:

According to What's New in iOS 7, what you're looking for is described as:


通过联系服务器定期更新其内容的应用程序可以
在系统中注册并定期启动以检索
内容在后台。要注册,请在应用的中包含 UIBackgroundModes
键以及 fetch 值Info.plist
文件。然后,当你的应用程序启动
时,调用 setMinimumBackgroundFetchInterval:
方法来确定它接收更新消息的频率。最后,
你还必须在app
委托中实现
应用程序:performFetchWithCompletionHandler:方法。

Apps that regularly update their content by contacting a server can register with the system and be launched periodically to retrieve that content in the background. To register, include the UIBackgroundModes key with the fetch value in your app’s Info.plist file. Then, when your app is launched, call the setMinimumBackgroundFetchInterval: method to determine how often it receives update messages. Finally, you must also implement the application:performFetchWithCompletionHandler: method in your app delegate.

在里面, application:performFetchWithCompletionHandler: ,你总共需要30秒才能完成执行你需要做之前必须调用completionHandler。绝对建议尽快执行您的民意调查,并在完成执行后立即调用completionHandler。如果您未在规定的30秒内调用它,您的应用将暂停后台获取。或者,如果您开始花费很长时间进行每次提取,您的应用将来获得后台提取的机会将会减少。

Inside, application:performFetchWithCompletionHandler:, you have a total of 30 seconds to finish executing what you need to do before you have to call the completionHandler. It's definitely advised to execute your poll as quickly as possible and call completionHandler as soon as you're done with your execution. If you don't call it within the allotted 30 seconds, your app will be suspended from background fetching. Or, if you start taking a long time for each fetch, your app will get fewer opportunities to perform background fetches in the future.

或者,如果您希望执行收到推送通知时的其他代码:

Alternatively, if you were looking to execute additional code when a push notification is received:


使用推送通知通知用户新内容
可用的应用程序可以在后台获取内容。要支持此
模式,请在远程通知
值中包含 UIBackgroundModes 键您的应用 Info.plist 文件。您还必须在应用代理中实现
应用程序:didReceiveRemoteNotification:fetchCompletionHandler:
方法。

Apps that use push notifications to notify the user that new content is available can fetch the content in the background. To support this mode, include the UIBackgroundModes key with the remote-notification value in your app’s Info.plist file. You must also implement the application:didReceiveRemoteNotification:fetchCompletionHandler: method in your app delegate.

这篇关于如何在iOS 7应用上启用后台更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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