5
應用程序配置爲在後臺接收位置更新以保持應用程序處於活動狀態,並且在應用程序處於後臺時成功接收更新。如何在應用程序處於後臺時接收達爾文通知
達爾文通知也已配置,並且只有當應用程序是前臺的當前應用程序時纔會收到通知。只要應用程序放在後臺,它就會停止接收達爾文通知。
有關如何在應用程序處於後臺時接收達爾文通知的任何想法?
下面的代碼片段。
建築應用中Swift2
在appdeligate
let callback: @convention(c)
(CFNotificationCenter!, UnsafeMutablePointer<Void>, CFString!, UnsafePointer<Void>, CFDictionary!) -> Void = {
(center, observer, name, object, userInfo) in
//Execute callback code
}
let exCb: CFNotificationCallback = unsafeBitCast(callback, CFNotificationCallback.self)
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),nil ,exCb,"com.apple.springboard.hasBlankedScreen" as CFString,nil ,CFNotificationSuspensionBehavior.DeliverImmediately)
在視圖 - 控制
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
//locationManager.requestWhenInUseAuthorization()
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
你有沒有嘗試過啓用後臺模式'位置更新'並檢查委託方法'locationManager:didUpdateLocations:'是否被稱爲 –
@ Rich16你有沒有得到這個工作?如果是這樣,它仍然在iOS 10上工作嗎? – simonthumper