Ich versuche, eine Beacon-Hintergrunderkennung in meiner App auszuführen. Ich habe eine spezielle Klasse für diese und starten Sie es in meinem Viewcontroller:Swift 2 Beacon Scan im Hintergrund
override func viewDidLoad() {
super.viewDidLoad()
beaconSharedInstance
....
}
und hier ist der Code meiner Klasse:
let beaconSharedInstance = iBeacon();
class iBeacon: NSObject, UIApplicationDelegate, CLLocationManagerDelegate {
var locationManager: CLLocationManager!
var beaconRegion:CLBeaconRegion!
override init(){
super.init()
let uuidString = "FDA50693-A4E2-4FB1-AFCF-C6EB07640978"
let beaconIdentifier = "uby-06B524"
let beaconUUID:NSUUID = NSUUID(UUIDString: uuidString)!
beaconRegion = CLBeaconRegion(proximityUUID: beaconUUID, identifier: beaconIdentifier)
locationManager = CLLocationManager()
locationManager.delegate = self
if(CLLocationManager.authorizationStatus() != CLAuthorizationStatus.AuthorizedAlways){
locationManager.requestAlwaysAuthorization()
}
locationManager.allowsBackgroundLocationUpdates = true
locationManager!.startRangingBeaconsInRegion(beaconRegion)
}
func locationManager(manager: CLLocationManager,
didRangeBeacons beacons: [CLBeacon],
inRegion region: CLBeaconRegion) {
print("didRangeBeacons");
if(beacons.count > 0) {
print("Discovered beacon \(beacons[0].rssi) dBM name: \(beacons[0].proximityUUID)")
}
}
}
diese Klasse perfekt im Vordergrund arbeitet , aber sobald meine Anwendung inaktiv wird, kann ich in den Log-Dateien sehen:
Ending background task
und der CLLocatioManager stoppt ...
Ich setze Standort-Updates im Hintergrund-Modus meines Projekts sowie NSLocationAlwaysUsageDescription in meiner Datei info.plist, aber ich habe immer noch das gleiche Verhalten, mein Thread stoppt, wenn App inaktiv ist.
Ich habe auch versucht, mein Thema wie folgt zu starten:
let qualityOfServiceClass = DISPATCH_QUEUE_PRIORITY_DEFAULT
let backgroundQueue = dispatch_get_global_queue(qualityOfServiceClass, 0)
dispatch_async(backgroundQueue, {
print("Running beacon detection in the background queue")
beaconSharedInstance
})
aber in diesem Fall CLLocationManager nie beginnt ... eine Idee?
Woher kommt das Protokoll "ending background task"? Verwenden Sie 'beginBackgroundTaskWithExouarininHandler'? – Paulw11