General Tech Bugs & Fixes . 1 year ago

Send device token or registration token to server?

Send device token or registration token to server?

1 views   2   0 likes   0 shares Tuteehub forum manpreet 2 answers
tuteehub_quiz
Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

profilepic.png

Tuteehub forum answer Answers (2)


profilepic.png
manpreet Tuteehub forum best answer Best Answer 1 year ago

I'm implementing Firebase in my app for push notification. Previously, the app has sent device token to own server for them to configure which device to send a push notification to.

1) Now in Firebase, there is something called registration token. So to maintain the same function of server handling which device to send a push notification to, should I send the device token from didRegisterForRemoteNotification or the firebase registration token from the didReceiveRegistrationToken delegate?

1 views   0 shares
profilepic.png
manpreet 1 year ago

In my app I am using this. send it from there,

import UserNotifications
import Firebase
import FirebaseInstanceID
import FirebaseMessaging

func application(_ application: UIApplication,
                     didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {

        InstanceID.instanceID().instanceID { (result, error) in
            if let error = error {
                print("Error fetching remote instange ID: \(error)")
            } else if let result = result {
                print("Remote instance ID token: \(result.token)")
          // save in userdefault and fetch when you user register and login,
                Constants.kUserDefaults.set(result.token, forKey: appConstants.fcmToken)
            }
        }
        Messaging.messaging().apnsToken = deviceToken as Data 
}
// and i also use
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
        print("Firebase registration token: \(fcmToken)")
        let token = Messaging.messaging().fcmToken
        print("FCM token: \(token ?? "")")
        Constants.kUserDefaults.set(token, forKey: appConstants.fcmToken)

}

 
1 views   0 shares

Related Tags

AskAnything Ask Anything

Ask Me Anything

ask me anything tuteehub

Hello! How can I assist you today?
Whether you have questions, need information, or just want to chat, feel free to let me know