requestAlwaysAuthorization not showing permission alert

前端 未结 17 1149
我寻月下人不归
我寻月下人不归 2020-12-29 20:19

I\'m trying to use some fancy iBeacons without success, kCLAuthorizationStatusNotDetermined all time. According to other questions it\'s a requirement to add those keys to

17条回答
  •  -上瘾入骨i
    2020-12-29 21:12

    Found, documented at forums and tested it's an Objective-C iOS 8 related bug. Same code written in Swift just works. Working swift code, delegate is call.

    Add Core Location framework to Project Settings / Targets / Capabilities / Background Modes set "Location Updates" and "Uses Bluetooth LE Accessories" Add key at Info.plist NSLocationAlwaysUsageDescription

    import CoreLocation
    
    class ViewController: UIViewController, CLLocationManagerDelegate  {
    
    var locManager: CLLocationManager?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.locManager = CLLocationManager();
        self.locManager!.delegate = self;
        if (!CLLocationManager.locationServicesEnabled()) {
            println("Location services are not enabled");
        }
        self.locManager!.requestAlwaysAuthorization();
        self.locManager!.pausesLocationUpdatesAutomatically = false;
        let uuidString = ""  // My ibeacon string there
        let beaconIdentifier = "myCompany"
        let beaconUUID:NSUUID = NSUUID(UUIDString: uuidString)
        let beaconRegion:CLBeaconRegion = CLBeaconRegion(proximityUUID: beaconUUID,
            identifier: beaconIdentifier)
        self.locManager!.startMonitoringForRegion(beaconRegion)
        self.locManager!.startRangingBeaconsInRegion(beaconRegion)
        self.locManager!.startUpdatingLocation()
    }
    

    Dialog appears OK

提交回复
热议问题