简体   繁体   English

苹果通知设备令牌更改

[英]Apple Notification Device Token change

I'm facing an issue after updating my app. 更新我的应用程序后,我遇到了问题。 I'm getting a device token in this format C43461D5-E9CB-4C10-81F8-020327A07A62 and the notifications aren't working. 我正在以这种格式C43461D5-E9CB-4C10-81F8-020327A07A62获取设备令牌,并且通知无法正常工作。

Before, I had a notification in this format: 2add70865401171c7ca1d3b3957b719eaf721fef8f8d7a52bc91ef8a872cc004 之前,我收到过以下格式的通知: 2add70865401171c7ca1d3b3957b719eaf721fef8f8d7a52bc91ef8a872cc004

I did allow notifications for the app and I've not changed anything in the backend. 我确实允许该应用的通知,但我在后端没有做任何更改。 Can anyone guide me why it's not working? 谁能指导我为什么它不起作用?

Code in didFinishLaunchingWithOptions : 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)];
}

Getting the device token: 获取设备令牌:

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

I got the below error: 我收到以下错误:

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 代码= 3000“找不到适用于应用程序的有效“ aps-environment”授权字符串” UserInfo = {NSLocalizedDescription =找不到适用于应用程序的有效“ aps-environment”授权字符串},找不到适用于应用程序的有效“ aps-environment”授权字符串

在此处输入图片说明

plz go to 请前往

Click on .xcodeproj -> Capabilities -> Enable Push Notification 单击.xcodeproj->功能->启用推送通知

hope it's work 希望它能工作

Click on .xcodeproj -> Capabilities -> Enable Push Notification 单击.xcodeproj->功能->启用推送通知

在此处输入图片说明

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

The UUIDString is the Unique device ID but for the Apple Push Notification you required the device token get back from APNS so for that Use the below method you get 64 digit deviceToken and get notification. UUIDString是唯一设备ID,但对于Apple Push Notification,您需要从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"];

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM