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

后端 未结 30 1927
挽巷
挽巷 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条回答
  •  -上瘾入骨i
    2020-11-28 19:24

    Swift

        // make sure that we have token for the devie on the App
        func application(application: UIApplication
            , didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
    
                var tokenStr = deviceToken.description
                tokenStr = tokenStr.stringByReplacingOccurrencesOfString("<", withString: "", options: [], range: nil)
                tokenStr = tokenStr.stringByReplacingOccurrencesOfString(">", withString: "", options: [], range: nil)
                tokenStr = tokenStr.stringByReplacingOccurrencesOfString(" ", withString: "", options: [], range: nil)
    
    
    
                print("my token is: \(tokenStr)")
    
        }
    

提交回复
热议问题