Apple 通知设备令牌更改

Apple Notification Device Token change

我在更新我的应用程序后遇到问题。我收到了这种格式的设备令牌 C43461D5-E9CB-4C10-81F8-020327A07A62 并且通知不起作用。

以前,我收到过这种格式的通知: 2add70865401171c7ca1d3b3957b719eaf721fef8f8d7a52bc91ef8a872cc004

我确实允许应用程序的通知,并且我没有在后端更改任何内容。谁能指导我为什么它不起作用?

didFinishLaunchingWithOptions中的代码:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}

获取设备令牌:

NSString *deviceTokenID = [[NSUserDefaults standardUserDefaults] objectForKey:DEVICE_TOKEN_PUSH_NOTI];
if ([deviceTokenID isEqualToString:@""] || deviceTokenID == nil) {
    NSString *tempApplicationUUID  = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    [dics setObject:tempApplicationUUID forKey:@"cust_device_id"];
} else {
    [dics setObject:[[NSUserDefaults standardUserDefaults] objectForKey:DEVICE_TOKEN_PUSH_NOTI] forKey:@"cust_device_id"];
}

我收到以下错误:

Code=3000 "no valid 'aps-environment' entitlement string found for application" UserInfo={NSLocalizedDescription=no valid 'aps-environment' entitlement string found for application}, no valid 'aps-environment' entitlement string found for application

NSString *tempApplicationUUID  = [[[UIDevice currentDevice] identifierForVendor] UUIDString];

UUIDString 是唯一的设备 ID,但对于 Apple 推送通知,您需要从 APNS 取回设备令牌,因此使用以下方法您可以获得 64 位 deviceToken 并收到通知。

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken


{
    NSString *devToken = [[[[deviceToken description]
                            stringByReplacingOccurrencesOfString:@"<"withString:@""]
                           stringByReplacingOccurrencesOfString:@">" withString:@""]
                          stringByReplacingOccurrencesOfString: @" " withString: @""];


    NSString *str = [NSString
                     stringWithFormat:@"Device Token=%@",devToken];

    [[NSUserDefaults standardUserDefaults]setObject:devToken forKey:@"DeviceToken"];

}

请前往

点击 .xcodeproj -> 功能 -> 启用推送通知

希望成功

点击 .xcodeproj -> 功能 -> 启用推送通知