didEnterRegion didExitregion没有被调用

时间:2015-03-02 00:53:01

标签: ibeacon estimote

我正在使用swift和coreLocation组合一个简单的estimote测试。但是我没有得到didEnterRegion,didExitRegion

我已经阅读了以下答案,但它仍然没有结束我的问题。

startMonitoringForRegion never calls didEnterRegion/didExitRegion

locationManager:didEnterRegion not called when a beacon is detected

我添加了背景模式(位置更新)

我在输出中得到“didStartMonitoringForRegion”日志,但是没有得到任何didenter或退出。我试着带着灯塔走出房子然后回来,但没有运气。然而,测量工作。

var locManager: CLLocationManager = CLLocationManager()

let iceRegion: CLBeaconRegion = CLBeaconRegion(proximityUUID: BEACON_PROXIMITY_UUID,  major: BEACON_ICE_MAJOR,  identifier: "ice")

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    if locManager.respondsToSelector("requestAlwaysAuthorization") {
        locManager.requestAlwaysAuthorization()
    }

    if (self.deviceSettingsAreCorrect())
    {
        iceRegion.notifyOnEntry = true
        iceRegion.notifyOnExit = true
        iceRegion.notifyEntryStateOnDisplay = true

        locManager.delegate = self

        locManager.startMonitoringForRegion(iceRegion)
        locManager.startRangingBeaconsInRegion(iceRegion)
    }
}

func locationManager(manager: CLLocationManager!, didStartMonitoringForRegion region: CLRegion!) {
    println("didStartMonitoringForRegion");
    locManager.requestStateForRegion(region);
}

func locationManager(manager: CLLocationManager!, didEnterRegion region: CLRegion!) {
    println("did Enter Region")
}

func locationManager(manager: CLLocationManager!, didExitRegion region: CLRegion!) {
    println("did Exit Region")
}

func locationManager(manager: CLLocationManager!, didDetermineState state: CLRegionState, forRegion region: CLRegion!) {
    println("didDetermineState \(state)");

    switch state {
    case .Inside:
        println("BeaconManager:didDetermineState CLRegionState.Inside");
    case .Outside:
        println("BeaconManager:didDetermineState CLRegionState.Outside");
    case .Unknown:
        println("BeaconManager:didDetermineState CLRegionState.Unknown");
    default:
        println("BeaconManager:didDetermineState default");
    }
}

func locationManager(manager: CLLocationManager!, didRangeBeacons beacons: [CLBeacon]!, inRegion region: CLBeaconRegion!) {
    println("BM didRangeBeacons");

    for beacon: CLBeacon in beacons {
        // TODO: better way to unwrap optionals?
        if let major: String = beacon.major?.stringValue {
            if let minor: String = beacon.minor?.stringValue {
                println(major)
            }
        }
    }
}

func deviceSettingsAreCorrect() -> Bool {
    var errorMessage = ""

    if !CLLocationManager.locationServicesEnabled()
        || (CLLocationManager.authorizationStatus() == CLAuthorizationStatus.Denied) {

            errorMessage += "Location services are turned off! Please turn them on!\n"
    }

    if !CLLocationManager.isRangingAvailable() {
        errorMessage += "Ranging not available!\n"
    }

    if !CLLocationManager.isMonitoringAvailableForClass(CLBeaconRegion) {
        errorMessage += "Beacon monitoring not supported!\n"
    }

    let errorLen = countElements(errorMessage)

    if errorLen > 0 {
        println(errorMessage)
    }

    return errorLen == 0
}

0 个答案:

没有答案