我经常要求通知令牌:
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
[application registerForRemoteNotifications];
} else {
[application registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
然而,我的iOS 8 iPad上一直调用didRegisterForRemoteNotificationsWithDeviceToken回调,而且从不在我的iOS 7 iPhone上调用(甚至不包括didFailToRegisterForRemoteNotificationsWithError),甚至不删除应用程序并重新安装它:也不显示警报。我检查了我的iPhone中的证书和设置,但所有看起来都是有序的,以及测试SO和整个互联网上的所有建议,但似乎没有什么可以修复它。还有什么建议吗?
答案 0 :(得分:2)
这可能是由于权限拒绝。应用程序卸载不会重置此权限。
为了验证此权限是否被拒绝,请执行以下操作( iOS7 ):
[[UIApplication sharedApplication] enabledRemoteNotificationTypes] != UIRemoteNotificationTypeNone;
如果权限被拒绝,您将必须执行以下步骤:
安装应用程序并再次运行
答案 1 :(得分:1)
检查Xcode项目目标中的以下设置: 目标项目>功能>推送通知 启用推送通知并检查您是否添加了推送通知'您的应用ID的权利。
答案 2 :(得分:0)
我正在使用以下“代码”并为我工作。
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
答案 3 :(得分:0)
试试这个,
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)];
}
希望这有帮助