[英]Why I can't set the default zoom on my UIScrollView in my ios swift app?
[英]why I can't use background mode in my app in swift 3?
我想在應用程序中使用后台模式,因此在功能中我勾選了后台獲取和通知功能,但問題是,僅在模擬器中一切正常,在真實的iPhone中,應用程序將凍結在后台
您無法在后台模式下從服務器獲取最新內容,因為Apple僅出於特定原因才允許獲取內容,例如。
對於需要更多執行時間才能實現的任務,您必須請求特定的權限才能在后台運行它們而不暫停它們。 在iOS中,只允許特定的應用類型在后台運行:
實現這些服務的應用必須聲明它們支持的服務,並使用系統框架來實現這些服務的相關方面。 聲明服務可以使系統知道您使用的服務,但是在某些情況下,實際上是系統框架阻止了應用程序被掛起。
除了這些,您還可以在短時間內從服務器獲取內容,例如。 1-2分鍾,具體取決於CPU使用情況
func doUpdate() {
DispatchQueue.global(qos: .default).async(execute: {() -> Void in
self.beginBackgroundUpdateTask()
var response: URLResponse? = nil
var error: Error? = nil
let responseData: Data? = try? NSURLConnection.sendSynchronousRequest(request, returningResponse: response)
// Do something with the result
self.endBackgroundUpdateTask()
})
}
func beginBackgroundUpdateTask() {
backgroundUpdateTask = UIApplication.shared.beginBackgroundTask(withExpirationHandler: {() -> Void in
self.endBackgroundUpdateTask()
})
}
func endBackgroundUpdateTask() {
UIApplication.shared.endBackgroundTask(backgroundUpdateTask)
backgroundUpdateTask = UIBackgroundTaskInvalid
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.