2017-02-03 6 views
1

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) 
} 
+1

위임자에게 전달 된 CLBeaconRegion이 UNLocationNotificationTrigger에 등록한 지역과 동일하다는 것을 알았습니다. 이 프로그램에는 전공이나 부전공이 없었으므로 전공의 대다수가 없습니다. 알림 위임 메서드에서 범위 지정 비닝을 시작한 다음 major 및 minor의 'didRangeBeacon'에서 해결해야합니다. – Paulw11

답변

1

UNLocationNotificationTrigger는 비콘 모니터링하는 API의 간이 래퍼에 이르기까지 API를 비컨하지입니다 :

여기 내 알림 등록 코드입니다. 모니터링 API는 감지 된 개별 식별자를보고하지 않고 모니터링을 설정하는 패턴 필터로 CLBeaconRegion 만 사용합니다. 모니터링을 사용하여 탐지 된 정확한 식별자를 파악할 수 없습니다.

API 작동 방식을 살펴보면이 점이 좋습니다. UNLocationNotificationTrigger의 영역 속성은 CLRegion입니다. 개별 식별자를 검색하기 위해 가지고 있어야하는 CLBeacon 속성이 없습니다. 식별자가 완전히 채워진 CLBeaconRegion을 가질 수는 있지만 iOS가 원하는대로 작동하는 경우 탐지 된 특정 표지 식별자로 필드를 채우기 위해 새 CLRegion 인스턴스를 만들어야했습니다.

불행히도 @ Paulw11이 제안한 대안은이 편리한 래퍼를 사용하지 않고 비컨 범위를 사용하여 알림을 수동으로 트리거하는 것입니다.

+0

확인. 글쎄, 나는 더 이상 내 꼬리를 쫓지 않을 것 같다. 포인터 주셔서 감사. 사실이라면 너무 좋았지 만,'UNLocationNotificationTrigger'가'CLBeaconRegion'을 받아들이면 희망이 생겼습니다. 오 잘. 다시 한번 감사드립니다. –