[英]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"];
}
我收到以下錯誤:
代碼= 3000“找不到適用於應用程序的有效“ aps-environment”授權字符串” UserInfo = {NSLocalizedDescription =找不到適用於應用程序的有效“ aps-environment”授權字符串},找不到適用於應用程序的有效“ aps-environment”授權字符串
NSString *tempApplicationUUID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
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.