![](/img/trans.png)
[英]didRegisterForRemoteNotificationsWithDeviceToken is not called up in ios 9
[英]didRegisterForRemoteNotificationsWithDeviceToken not called on iOS7
我经常要求通知令牌:
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
[application registerForRemoteNotifications];
} else {
[application registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
然而didRegisterForRemoteNotificationsWithDeviceToken回调在我的iOS 8 iPad上一直被调用,从不在我的iOS 7 iPhone上(甚至不是didFailToRegisterForRemoteNotificationsWithError),甚至没有删除应用程序并重新安装它:也没有显示警报。 我检查了我的iPhone中的证书和设置,但所有看起来都是有序的,以及测试SO和整个互联网上的所有建议,但似乎没有什么可以修复它。 还有什么建议吗?
这可能是由于权限拒绝。 应用程序卸载不会重置此权限。
为了验证是否拒绝此权限,请执行以下操作( iOS7 ):
[[UIApplication sharedApplication] enabledRemoteNotificationTypes] != UIRemoteNotificationTypeNone;
如果权限被拒绝,则必须执行以下步骤:
安装应用程序并再次运行
检查Xcode项目目标中的以下设置:目标项目>功能>推送通知启用推送通知并检查是否已将“推送通知”权利添加到您的应用程序ID。
我正在使用以下“代码”并为我工作。
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
尝试这个,
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)];
}
希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.