How can I convert my device token (NSData) into an NSString?

后端 未结 30 2001
挽巷
挽巷 2020-11-28 18:31

I am implementing push notifications. I\'d like to save my APNS Token as a String.

- (void)application:(UIApplication *)application
didRegisterForRemoteNotif         


        
30条回答
  •  青春惊慌失措
    2020-11-28 19:15

    Swift 3:

    If any one is looking for a way to get device token in Swift 3. Use the below modified snippet.

        let characterSet: CharacterSet = CharacterSet( charactersIn: "<>" )
    
        let deviceTokenString: String = (deviceToken.description as NSString)
            .trimmingCharacters(in: characterSet as CharacterSet)
            .replacingOccurrences(of: " ", with: "")
            .uppercased()
    
        print(deviceTokenString)
    

提交回复
热议问题