【发布时间】:2015-04-17 04:10:48
【问题描述】:
嗨,我被这个问题困扰了一个多星期。我按照本教程here 在我的应用程序中添加推送通知。在我的应用程序的初始运行中,“应用程序想向您发送推送通知”没有出现。但是,当我转到应用程序通知时,它已经注册了仅针对声音和横幅的通知,并且徽章应用程序图标未打开。 但是当我在我的应用程序中登录时,徽章应用程序图标通知类型不再存在。 (抱歉不能发图)
当我检查我的日志时,我遇到了这个运行时错误:尝试为应用程序图标添加徽章,但未获得用户对应用程序添加徽章的权限
这是我在 AppDelegate.m 中的代码
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound];
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *hexToken= [[[[deviceToken description]
stringByReplacingOccurrencesOfString: @"<" withString: @""]
stringByReplacingOccurrencesOfString: @">" withString: @""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
[[NSUserDefaults standardUserDefaults] setObject:hexToken forKey:@"deviceToken"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
任何帮助将不胜感激。 谢谢。
【问题讨论】:
-
删除 if 块中的
[[UIApplication sharedApplication] registerForRemoteNotifications];行,并添加 Nilesh 在他的回答中建议的方法,一切都会正常工作。而且,不需要#ifdef声明。 -
Parse 有很好的推送通知服务。教程也很清晰,效果很好:parse.com/tutorials/ios-push-notifications
标签: ios objective-c iphone notifications