前提
swiftで通話アプリを作っています。
awsでユーザーごとのデバイストークンを管理しています。
実現したいこと
- 任意のタイミングで任意のデバイストークンにプッシュ通知を送信したい
発生している問題
apnsの仕組みとしては、デバイストークンを指定すればその対応したデバイスに通知が送信されるものと思っているのですが、その指定方法がわからず困っています。
調べても出てこないので自分の勘違いなのかとも思っているのですが、であればトークンは何に使うのかと疑問に思っています。
ソースコード
以下のように作成しているのですが、この中にトークンを指定できるようなものがあると考えておりましたが、そう言った記事は見つからなかったのでやり方を見直す必要があるのかと思っています。
swift
1func sendNotification(identifier: String, 2 title: String, 3 body: String, 4 sound: String?, 5 dateComponents: DateComponents, 6 repeats: Bool = false) { 7 let content = UNMutableNotificationContent() 8 content.title = title 9 content.body = body 10 if let sound = sound { 11 content.sound = UNNotificationSound.init(named: UNNotificationSoundName(rawValue: sound)) 12 } 13 let trigger = UNCalendarNotificationTrigger.init( 14 dateMatching: dateComponents, 15 repeats: repeats) 16 let request = UNNotificationRequest( 17 identifier: identifier, 18 content: content, 19 trigger: trigger) 20 UNUserNotificationCenter.current().add(request) { error in 21 if let error = error { 22 print(error) 23 } 24 } 25}
回答1件
あなたの回答
tips
プレビュー