Apple通知设备令牌更改

时间:2016-10-13 10:34:13

标签: ios objective-c xcode apple-push-notifications

我在更新我的应用程序后面临一个问题我正在以这种格式获取设备令牌 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“找不到有效'aps-environment'权利字符串   application“UserInfo = {NSLocalizedDescription =无效   为应用程序找到'aps-environment'权利字符串},无效   为应用程序找到'aps-environment'权利字符串

3 个答案:

答案 0 :(得分:2)

enter image description here

请转到

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

希望它的工作

答案 1 :(得分:0)

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"];

}

答案 2 :(得分:0)

点击.xcodeproj - &gt;能力 - &gt;启用推送通知

enter image description here