我有一个应用程序一般我想使用APN与iOS推送通知。我的推送通知与ios 8及更低版本兼容。我在模拟器上启动时,推送通知权限对话框正常工作。但是当它在真实设备中发布时,它会说;
“尝试标记应用程序图标但尚未收到 用户允许对应用程序进行标记“
的AppDelegate
[[NotificationManager sharedInstance] requestPushNotificationIfNeeded];
NotificationManager - requestPushNotificationIfNeeded
// Refresh the token.
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
if([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]){
// iOS 8 Notification
UIUserNotificationType types = UIUserNotificationTypeSound | UIUserNotificationTypeBadge | UIUserNotificationTypeAlert;
UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
}
else {
// Less then iOS 8
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound];
}
#else
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound];
#endif
App委托方法
#ifdef __IPHONE_8_0
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings: (UIUserNotificationSettings *)notificationSettings
{
TRACE(@"Delegate did");
//register to receive notifications
[application registerForRemoteNotifications];
}
#endif
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
// Using parse.com save push notification token
}
问题
这段代码有什么问题?我试了好几天但是徒劳无功。你能指导一下这个错误吗?怎么了还是我错过了必要的东西?非常感谢你。
顺便说一下,我注销了委托方法只注册 UIUserNotificationTypeAlert 像这样;
Delegate didRegisterUserNotificationSettings: <UIUserNotificationSettings: 0x17422e2c0; types: (UIUserNotificationTypeAlert);>
答案 0 :(得分:1)
好像你的应用没有合适的permissions
来生成push notifications
根据苹果公司在这种情况下的建议,我曾经也要遵循。请遵循以下步骤:
1)取消安装应用程序,然后重新启动手机
2)转到设置 - &gt;日期和时间,并将日期设置为当前日期之前至少1天
3)再次重启设备。
4)现在进行设置并将时间恢复正常
5)重启设备。
6)现在安装应用程序,它应该要求您提供推送通知&#39;权限。如果仍然没有请求权限,请重复上述步骤,但是在步骤4之后重新启动,而不是重新启动只需安装应用程序然后重新启动,您就可以开始了。
我希望这可以解决你的问题。