aboutsummaryrefslogtreecommitdiffhomepage
path: root/Example/Messaging
diff options
context:
space:
mode:
Diffstat (limited to 'Example/Messaging')
-rw-r--r--Example/Messaging/App/iOS/AppDelegate.swift21
1 files changed, 9 insertions, 12 deletions
diff --git a/Example/Messaging/App/iOS/AppDelegate.swift b/Example/Messaging/App/iOS/AppDelegate.swift
index aafd844..32b55ed 100644
--- a/Example/Messaging/App/iOS/AppDelegate.swift
+++ b/Example/Messaging/App/iOS/AppDelegate.swift
@@ -66,19 +66,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// register for remote notifications
NotificationsController.shared.registerForUserFacingNotificationsFor(application)
}
-
- printFCMToken()
return true
}
- func printFCMToken() {
- if let token = Messaging.messaging().fcmToken {
- print("FCM Token: \(token)")
- } else {
- print("FCM Token: nil")
- }
- }
-
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
print("APNS Token: \(deviceToken.hexByteString)")
@@ -116,8 +106,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
extension AppDelegate: MessagingDelegate {
- func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
- printFCMToken()
+ // FCM tokens are always provided here. It is called generally during app start, but may be called
+ // more than once, if the token is invalidated or updated. This is the right spot to upload this
+ // token to your application server, or to subscribe to any topics.
+ func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
+ if let token = Messaging.messaging().fcmToken {
+ print("FCM Token: \(token)")
+ } else {
+ print("FCM Token: nil")
+ }
}
// Direct channel data messages are delivered here, on iOS 10.0+.