我在更新我的应用程序后面临一个问题我正在以这种格式获取设备令牌 C43461D5-E9CB-4C10-81F8-020327A07A62 并且通知无效。
在我收到此格式的通知之前: 2add70865401171c7ca1d3b3957b719eaf721fef8f8d7a52bc91ef8a872cc004
我确实允许通知应用,并且没有在后端更改任何内容。 可以任何人指导它为什么不起作用。
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'权利字符串
答案 0 :(得分:2)
答案 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)