苹果ios应用上架前本机调试可以获取正确的hms 推送 token 进行推送操作,上架后收到的token 无法推送,利用自查工具发现requestid+token 提示400错误,请教产生错误的原因
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:
(NSData *)deviceToken {
NSString *pushToken ;
NSLog(@"success get token:{%@}", deviceToken);
// Check the iOS version.
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 13) {
if (![deviceToken isKindOfClass:[NSData class]]) {
return;
}
const unsigned *tokenBytes = (const unsigned *)[deviceToken bytes];
NSString *strToken = [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])];
NSLog(@">=ios13 My FINAL TOKEN is:%@", strToken);
pushToken = [[HmsInstanceId getInstance] getToken:strToken];
NSLog(@"push token is %@", pushToken);
[self writeToFile:pushToken];
return;
}
- (void)writeToFile:(NSString*)str{
NSError *error = nil;
NSString *tmpDir;
tmpDir = [NSTemporaryDirectory() stringByAppendingString:@"token.txt"];
BOOL flag = [str writeToFile:tmpDir atomically:YES encoding:NSUTF8StringEncoding error:&error];
if (flag) {
NSLog(@"写入成功");
}
else{
NSLog(@"写入失败");
}
}
以上代码思路是获取token后写入tmp目录的token.txt文件,待ionic应用完全启动完毕后,调用file插件读取token.txt文件内保存的token进行后续操作。调试时token一切正常,上架后token就是错误的。