在 swift 中使用 xCode 7 时,我无法仅在应用程序处于前台时在后台对信标进行测距。
我的核心位置didRangeBeacons在后面
func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {
let near = beacons[0]
print(near)
}
didFinishLaunchingWithOptions 是紧随其后的那个。位置管理器对象是类的全局对象。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
if(locationManager.respondsToSelector("requestAlwaysAuthorization")) {
locationManager.requestAlwaysAuthorization()
}
locationManager.delegate = self
locationManager.pausesLocationUpdatesAutomatically = false
locationManager.startMonitoringForRegion(region)
locationManager.startRangingBeaconsInRegion(region)
locationManager.startUpdatingLocation()
return true
}
在我的 .plist 文件中,我设置了 NSLocationAlwaysUsageDescription,在功能中,我打开了背景模式,并检查了位置更新和使用蓝牙 LE 配件。
我还向项目添加了 CoreLocation 框架。
非常感谢您的帮助或一些可能有用的 URL。谢谢。
最佳答案
我设法解决了这个问题。核心位置添加了默认为否的 allowsBackgroundLocationUpdates 女巫。您可以看到视频 ( https://developer.apple.com/videos/wwdc/2015/?id=714 )。
关于swift - iOS 9后台iBeacon检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32852029/