iOS Push Notification Notes
UIApplication
https://developer.apple.com/documentation/uikit/uiapplication/
registerForRemoteNotifications()
https://developer.apple.com/documentation/uikit/uiapplication/1623078-registerforremotenotifications
If registration succeeds, the app calls your app delegate object’s application(_:didRegisterForRemoteNotificationsWithDeviceToken:) method and passes it a device token.
application(_:didRegisterForRemoteNotificationsWithDeviceToken:)
https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622958-application
deviceToken
A globally unique token that identifies this device to APNs. Send this token to the server that you use to generate remote notifications. Your server must pass this token unmodified back to APNs when sending those remote notifications.
APNs device tokens are of variable length. Do not hard-code their size.
Messaging
https://firebase.google.com/docs/reference/swift/firebasemessaging/api/reference/Classes/Messaging
MessagingDelegate
1. 執行 application.registerForRemoteNotifications()
2. application(_:didRegisterForRemoteNotificationsWithDeviceToken:) 被呼叫
3. Messaging.messaging().delegate = self
Messaging.messaging().apnsToken = deviceToken
4. func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) 被呼叫
5. let dataDict: [String: String] = ["token": fcmToken ?? ""]
NotificationCenter.default.post(
name: Notification.Name("FCMToken"),
object: nil,
userInfo: dataDict
)
留言
張貼留言