如何在iOS 7应用上启用后台更新

前端之家收集整理的这篇文章主要介绍了如何在iOS 7应用上启用后台更新前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何让我的应用程序使用iOS 7后台更新功能?我注意到一些应用程序已经这样做了,但它似乎并不是全自动的.

解决方法

根据 What’s New in iOS 7,你正在寻找的是:

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:,在你必须调用completionHandler之前,总共需要30秒才能完成你需要做的事情.绝对建议尽快执行您的民意调查,并在完成执行后立即调用completionHandler.如果您未在指定的30秒内调用它,您的应用将暂停从后台获取.或者,如果您开始花费很长时间进行每次提取,那么您的应用将来获得后台提取的机会将会减少.

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

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.

原文链接:https://www.f2er.com/iOS/330765.html

猜你在找的iOS相关文章