Iphone device token - NSData or NSString

前端 未结 6 1547
走了就别回头了
走了就别回头了 2020-12-13 13:38

I am receiving iPhone device token in the form of NSData object. When I tested my notifications script function, I have only copied that object from log and th

6条回答
  •  情话喂你
    2020-12-13 14:29

    If anyone is looking for a way to do this in Swift:

    func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
        let tokenChars = UnsafePointer(deviceToken.bytes)
        var tokenString = ""
    
        for i in 0..

    Edit: For Swift 3

    Swift 3 introduces the Data type, with value semantics. To convert the deviceToken to a String, you can do as follows:

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    
        var token: String = ""
        for i in 0..

提交回复
热议问题