問題描述
我開發的應用程序應該每 15 分鐘處理一次數據.所以我在 plist 文件中添加了 voip 標志.并使用 900 秒(15 分鐘)的 setKeepAliveTimeout.還添加了處理一些數據的后臺任務功能.處理數據最多需要 10 秒.
I've developed app which should process some data every 15 min. So I added voip flag into plist file. And use setKeepAliveTimeout with 900 sec(15 min). Also added background task functionality which processes some data. Processing of data takes up to 10 seconds.
問題是應用沒有及時喚醒.有時在 12 分鐘后,有時在 16 分鐘后等等.但我需要正好在 15 分鐘內.
The problem is that app wakes up NOT in time. Sometimes after 12 min, sometimes after 16 min etc. But I need exactly in 15 min.
如何解決以下問題?
iOS版本為5.0+
如果是 iOS 特定的,請向我提供有關蘋果 api 文檔的官方參考.
If it's iOS's specific please provide me official reference into the apple's api document where this mentioned .
推薦答案
setKeepAliveTimeout:handler:
不是通用的間隔調度程序.它允許您設置提供的處理程序的調用之間的最大間隔.該功能的目的是幫助您防止連接超時或落后于您的 VOIP 應用程序標準(例如在線/離開狀態).
setKeepAliveTimeout:handler:
is not a general purpose interval scheduler. It allows you to set the maximum interval between invocations of the supplied handler. The purpose of the function is to help you keep your connections from timing out or falling behind your VOIP applications standards (for things like online/away status).
所以第一個參數 (timeout
) 告訴 iOS 在不超過 15 分鐘內調用您的處理程序.如果操作系統決定在 12 分鐘內有一些空閑周期,它可能會調用您的處理程序.或者在 7 分鐘內,或者 15 分鐘內.
So the first parameter (timeout
) tells iOS to call your handler in no more than 15 minutes. If the OS decides that it's got some cycles to spare at 12 minutes, it might call your handler. Or in 7 minutes, or 15.
如果您需要對間隔進行更精細的控制,您應該設置一個較小的超時窗口并忽略對您不重要的調用.但是調用仍然會相當不規則.
If you need finer grained control of the interval, you should set a smaller timeout window and just ignore invocations that aren't important to you. But the invocations will still going be fairly irregular.
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/occ/instm/UIApplication/setKeepAliveTimeout:handler:
一般來說,目前沒有辦法讓它按精確的時間表喚醒您的應用.您必須遵守 iOS 有限的后臺處理選項,所有這些選項都旨在為操作系統提供很大的余地來管理所有進程的總體優先級和資源需求.
In general, there is currently no way to make it wake your app on a precise schedule. You must adhere to iOS' limited background processing options, all of which are designed to give the OS a lot of leeway to manage overall priorities and resource needs across ALL processes.
這篇關于如果為 setKeepAliveTimeout 方法設置 15 分鐘,VOIP 應用程序不會及時喚醒的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!