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

后端 未结 30 2014
挽巷
挽巷 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:27

    You could use this

    - (NSString *)stringWithDeviceToken:(NSData *)deviceToken {
        const char *data = [deviceToken bytes];
        NSMutableString *token = [NSMutableString string];
    
        for (NSUInteger i = 0; i < [deviceToken length]; i++) {
            [token appendFormat:@"%02.2hhX", data[i]];
        }
    
        return [token copy];
    }
    

提交回复
热议问题