Apple已经真正简化了如何在iOS 10中接收基于位置的通知,但是,我发现当通知被触发并调用UNUserNotificationCenterDelegate
委托方法时,下来的区域对象的主值和次值始终设置为空。所以,当接收时,应用程序是在前台通知委托方法,该方法被调用:iOS 10灯塔基于位置的通知不提供主要和次要值
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
// When the app is in the foreground
if let trigger = notification.request.trigger as? UNLocationNotificationTrigger,
let region = trigger.region as? CLBeaconRegion {
// When you examine the region variable here, its major and minor
// values are null
}
completionHandler([.alert, .sound])
}
的CLBeaconRegion
对象的主要和次要NSNumber
变量总是空。我告诉CLLocationManager
范围为信标,应该提供这些值,不应该吗?任何想法这里缺少什么?或者这是由设计?无论是实际的信标(例如KST粒子)还是使用CBPeripheralManager
通过蓝牙进行广播的其他iOS设备,我都会得到相同的结果。
这里是我通知的注册代码:
let locationManager = CLLocationManager()
func createLocationNotification() {
self.locationManager.requestWhenInUseAuthorization()
let region = CLBeaconRegion(proximityUUID: UUID(uuidString: "UUID-STRING")!, identifier: "com.company.identifier")
region.notifyOnEntry = true
region.notifyOnExit = false
let content = UNMutableNotificationContent()
content.title = "New Checkin Received"
content.body = "Swipe or tap this message to see who's here"
let trigger = UNLocationNotificationTrigger(region: region, repeats: true)
let request = UNNotificationRequest.init(identifier: "BeaconNotificationIdentifier", content: content, trigger: trigger)
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().add(request, withCompletionHandler: { (error) in
})
self.locationManager.startRangingBeacons(in: region)
}
我想像一下,传递给委托的CLBeaconRegion与您在UNLocationNotificationTrigger中注册的区域相同。由于这没有大的或未成年人,你在代表中没有主修或未成年人。你应该在通知委托方法中启动测距信标,然后从'didRangeBeacon'中找出主要和次要信号。 – Paulw11