在iOS背景中的灯塔测距

时间:2016-02-06 16:15:17

标签: ios swift

我目前正试图通过使用位置监控找到一种在iOS背景中定位信标的方法,然后触发范围如下:

if (this.o.rtl){
    this.picker.addClass('datepicker-rtl');
    this.picker.find('.prev i, .next i')
               .toggleClass('icon-arrow-left icon-arrow-right');
}

然后我尝试在信标范围内进行API调用

func locationManager(manager: CLLocationManager, didDetermineState state: CLRegionState, forRegion region: CLRegion) {
    if (state == .Inside) {
        locationManager.startRangingBeaconsInRegion((region as? CLBeaconRegion)!)
    }
}

然而,这只能在电话处于后台工作大约十分钟,十分钟后它不再有效但我希望能连续工作,以便在找到信标时始终可以进行API调用。我也在权限中设置了正确的密钥,我在我的locationManager上使用requestAlwaysAuthorization()

2 个答案:

答案 0 :(得分:1)

查看Apple的iOS Dev Library有关后台执行的信息: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

如果您的应用类型是较长时间背景执行的可接受类型之一,请使用包含一个或多个已启用类型的数组将Required background modes键添加到Info.plist:{{ 1}},audiolocationvoipnewsstand-content和/或external-accessory

请注意,在App Store上发布您的应用之前,Apple会对此进行审核。

<强>编辑:

我暂时没有使用它,但现在进行了测试,从Xcode 6开始,它似乎更容易。 请按照以下步骤操作:

1。将密钥bluetooth-central添加到Required background modes

2。转到Info.plist enter image description here

3. 选择适合的背景模式。 enter image description here

答案 1 :(得分:0)

我遇到了同样的问题。正如评论员所说,我已将位置管理器委托方法移至App Delegate中。我还补充说:

locationManager.allowsBackgroundLocationUpdates = true
locationManager.pausesLocationUpdatesAutomatically = false

它有效。