在后台使用GPS和iBeacon

时间:2017-07-25 07:21:03

标签: ios iphone swift gps ibeacon

当app在后台时,是否可以将GPS与iBeacon一起使用? 当iPhone仅检测到iBeacon 180秒时我需要启动更新gps位置,我这样做但它不起作用:/

func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {
    if !isInForeground {
        extendBackgroundTime()
    }
    print(wasBeaconDetected)

    for beacon in beacons {
        if beacon.rssi < -10 {
            wasBeaconDetected = true
            nearbyBeacons.append(beacon)
        }
    }
    print(beacons)
    currentLocation = manager.location!.coordinate
    if firstRegionDetected == "" {
        firstRegionDetected = region.identifier
    } else if firstRegionDetected == region.identifier {
        analyzeScan(nearbyBeacons, currentLocation)
    }
}

当然我在确定状态时开始监控

func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion) {
    if isInBackground {
        extendBackgroundTime()
    }
}

0 个答案:

没有答案