该应用程序已配置为在后台接收位置更新,以保持应用程序活动,并在应用程序处于后台时成功接收更新。
Darwin通知也已配置,并且仅在应用程序在前台时才会接收到。一旦将应用程序置于后台,它就停止接收Darwin通知。
有没有想法在应用程序处于后台时接收Darwin通知?
以下是代码片段。
使用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:
是否被调用了吗? - Sunil Sharma