18°

iOS将 device token 转String

    NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
    NSLog(@"deviceToken=%@", token);

//对Data类型进行扩展 extension Data { //将Data转换为String var hexString: String { return withUnsafeBytes {(bytes: UnsafePointer<UInt8>) -> String in let buffer = UnsafeBufferPointer(start: bytes, count: count) return buffer.map {String(format: "%02hhx", $0)}.reduce("", { $0 + $1 }) } } }

 

本文由【west_zll】发布于开源中国,原文链接:https://my.oschina.net/wayzhu/blog/3136361

全部评论: 0

    我有话说: