
IM即时通讯
安全可靠、全球互通

实时音视频
流畅稳定、省钱省力
回答:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSString *token = [deviceToken description]; token = [token stringByReplacingOccurrencesOfString:@"<" withString:@""]; token = [token stringByReplacingOccurrencesOfString:@">" withString:@""]; token = [token stringByReplacingOccurrencesOfString:@" " withString:@""]; [[RCIMClient sharedRCIMClient] setDeviceToken:token]; }
{length=32,bytes=0xfe270338e80825d6c5d1754096f916b8...0d19a5d5834cff75}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [[RCIMClient sharedRCIMClient] setDeviceTokenData:deviceToken]; }
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSString *token = [self getHexStringForData:deviceToken]; [[RCIMClient sharedRCIMClient] setDeviceToken:token]; } - (NSString *)getHexStringForData:(NSData *)data { NSUInteger len = [data length]; char *chars = (char *)[data bytes]; NSMutableString *hexString = [[NSMutableString alloc] init]; for (NSUInteger i = 0; i < len; i ++) { [hexString appendString:[NSString stringWithFormat:@"%0.2hhx", chars[i]]]; } return hexString; }
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { const unsigned *tokenBytes = [deviceToken bytes]; if (tokenBytes == NULL) { return; } NSString *token = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x", ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]), ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]), ntohl(tokenBytes[6]), ntohl(tokenBytes[7])]; [[RCIMClient sharedRCIMClient] setDeviceToken:token]; }
Swift 处理方法:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { var deviceTokenString = String() let bytes = [UInt8](deviceToken) for item in bytes { deviceTokenString += String(format: "%02x", item&0x000000FF) } RCIMClient.shared()?.setDeviceToken(deviceTokenString) }