ジオフェンスに入ったり出たりする人々の動きを監視するための単純なジオフェンスベースのアプリケーションを作成しましたが、これらのイベントについて通知を送信しようとしていますが、正しく実装できないようです。ジオフェンスでトリガされたローカル通知を実装する方法は?
私は実際には、ビューコントローラとアプリケーションデリゲートに入るサンプルコードを説明していただきたいと思います。
P.s私の知りたいことは多少限られていますが、私はこのアプリケーションに必要な多くの側面を理解しています。 助けてくれてありがとう!
編集:
これは私が正しいと思い通知を作成するための私の関数です。
func scheduleNotification() {
let centre = CLLocationCoordinate2DMake(51.364730, -0.189986)
let region = CLCircularRegion(center: centre, radius: 150, identifier: "SGS")
region.notifyOnEntry = true
let trigger = UNLocationNotificationTrigger(region: region, repeats: true)
let enterContent = UNMutableNotificationContent()
enterContent.title = "Enter"
enterContent.body = "Entered premesis"
enterContent.sound = UNNotificationSound.default()
let enterRequest = UNNotificationRequest(identifier: "enterNotification", content: enterContent, trigger: trigger)
UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
UNUserNotificationCenter.current().add(enterRequest) {(error) in
if let error = error {
print("Error: \(error)")
}
}
}
私はdidFinishLaunchingWithOptionsにこれを追加しました:
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {(accepted, error) in
if !accepted {
print("Notification access denied.")
}
}
私は関数を呼び出す必要がある知っているが、私はどこジオフェンスが残っているとき、それが呼び出されるようにそれを行うにはわかりません。また、AppDelegateにあるようにView Controllerから呼び出す方法がわかりません。
申し訳ありませんが、私はばかげているが、助けてくれてありがとう!
あなたが試したものと動作しないものを投稿してください。 – shallowThought