Getting Remote Notification Device Token in Swift 4?

前端 未结 8 2383
梦谈多话
梦谈多话 2021-02-20 06:59

I am using this code to get the Notification Center Device token.

It was working in Swift 3 but not working in Swift 4. What changed?

if #available(iOS 1         


        
8条回答
  •  旧时难觅i
    2021-02-20 07:24

    You can use this both function for getting Device Token & FCM Token:


    For device token use this:

    func application(_ application:UIApplication,didRegisterForRemoteNotificationsWithDeviceToken 
    devicetoken: Data)
     {
            let deviceTokenString = deviceToken.hexString
            print(deviceTokenString)
     }
    

    For FCM token use this:

    func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
        print("Firebase registration token: \(fcmToken)")
        userDefault.set(fcmToken, forKey: "fcmToken")
    
    }
    

    For UUID use this:

     let deviceIds = UIDevice.current.identifierForVendor!.uuidString
    

提交回复
热议问题