Edited at

【Swift3】Firebase経由でpush通知と値を送り、アプリ側で値を取得

More than 1 year has passed since last update.

Firebaseの設定は割愛。

送信内容

curl \

--verbose \
--request POST \
--header 'Content-Type: application/json' \
--header 'Authorization: key=firebaseのAPIのKEY' \
--data '{"notification":{"title":"通知のタイトル","body":"通知の本文"},"to":"送り先のtoken","data":{"payload":"hoge"}}' \
'https://fcm.googleapis.com/fcm/send'

iOSアプリ側での通知を開いた後の処理。

func userNotificationCenter(_ center: UNUserNotificationCenter,

didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
let payload = userInfo["payload"] as! String
print(payload) // hoge
}