지오 펜스에 원형 영역을 사용하는 앱을 만들고 있습니다. 휴대 전화가 활성 상태이거나 앱이 열려 있으면 시뮬레이터와 기기 (10.3.1을 실행하는 iPhone 6)에서 모두 지오 펜스 알림이 올바르게 작동합니다.지오 펜스 알림/로컬 알림이 울릴 때 잠겨있는 전화를 깨우지 않습니다.
시뮬레이터에서 잘 작동합니다. 사용자가 지역을 입력하면 잠에서 깨어나 소리를 내며 잠금 화면에 경고를 표시합니다.
전화에서 "didEnterRegion"대리인 전화는 지역을 입력 할 때 (일부 메시지를 기록하지만) 전화가 알림을 보내고 깨어나지 않고 있습니다. 홈 버튼을 한 번 누르면 잠금 화면에서 알림을 볼 수 있지만 알림이 표시되면 즉시 알림을 표시합니다. 시뮬레이터에서 작동하기 때문에 무엇이 잘못 될 수 있는지 궁금합니다. 그것은 몇 번이나 나를 위해 몇 번, 어디 경고가 전화와 내 시계에 표시되었지만, 그것이 작동하지 않는 시간의 95 % - 통지가 생성되지만 내가 수동으로 전화를 깨울 경우에만 표시됩니다.
해결 방법? 여기
내가 로컬 알림 만들기 위해 사용하는 코드입니다 : 이let message = "CLRegion event"
// Show an alert if application is active:
if UIApplication.shared.applicationState == .active {
if let viewController = UIApplication.shared.keyWindow?.rootViewController {
showSimpleAlertWithTitle(nil, message: message, viewController: viewController)
}
}
else {
// Otherwise app is in background, present a local notification:
let content = UNMutableNotificationContent()
content.body = message
content.sound = UNNotificationSound.default()
content.categoryIdentifier = "message"
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1.0, repeats: false)
let request = UNNotificationRequest(identifier: "com.foobar", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
}
정말 유일한 DIFF는 : 여기
// https://blog.codecentric.de/en/2016/11/setup-ios-10-local-notification/
let location = CLLocation(latitude: item.coordinate.latitude, longitude: item.coordinate.longitude)
GeoTools.decodePosition(location: location) {
(address, city) in
let content = UNMutableNotificationContent()
content.title = "Camera nearby!"
content.subtitle = item.id
content.body = "\(address), \(city)"
content.categoryIdentifier = Constants.notificationCategoryId
content.sound = UNNotificationSound.default()
content.threadIdentifier = item.id
// FIXME make action for clicking notification
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.001, repeats: false) // FIXME HACK
let request = UNNotificationRequest(identifier: "camNotification", content: content, trigger: trigger)
let unc = UNUserNotificationCenter.current()
unc.removeAllPendingNotificationRequests()
unc.add(request, withCompletionHandler: { (error) in
if let error = error {
print(error)
}
else {
print("completed")
}
})
}