iOS13新出之后會有收不到推送的問題
因為iOS13的處理方法變了,代碼如下
//獲取DeviceToken成功 - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { //Xcode11打的包,iOS13獲取Token有變化 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 13) { if (![deviceToken isKindOfClass:[NSData class]]) { //記錄獲取token失敗的描述 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(@"deviceToken1:%@", strToken); return; } else { NSString *token = [NSString stringWithFormat:@"%@",deviceToken]; token = [token stringByReplacingOccurrencesOfString:@"<" withString:@""]; token = [token stringByReplacingOccurrencesOfString:@">" withString:@""]; token = [token stringByReplacingOccurrencesOfString:@" " withString:@""]; NSLog(@"deviceToken2 is: %@", token); } }