Apple은 iOS 10에서 위치 기반 알림을 수신하는 방법을 실제로 단순화했습니다. 알림이 트리거되고 UNUserNotificationCenterDelegate
대리자 메서드가 호출되면, 내림차순 영역 객체에는 주 값과 부 값이 항상 null로 설정됩니다. 그래서 앱이 포 그라운드에 통지를 받기위한 위임 방법,이 방법은 호출되는 경우 :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
변수는 항상 null입니다. 나는 CLLocationManager
에게이 값을 제공해야하는 비컨의 범위에 대해 말하며 그렇지 않습니까? 무엇이 여기에서 놓치고 있는지 아는 것이 있습니까? 또는 디자인에 의한 것인가? CBPeripheralManager
을 사용하여 실제 신호 (예 : KST 입자) 또는 블루투스를 통해 브로드 캐스팅하는 다른 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에 등록한 지역과 동일하다는 것을 알았습니다. 이 프로그램에는 전공이나 부전공이 없었으므로 전공의 대다수가 없습니다. 알림 위임 메서드에서 범위 지정 비닝을 시작한 다음 major 및 minor의 'didRangeBeacon'에서 해결해야합니다. – Paulw11