我有一个通用的应用程序,我想将APN与iOS Push通知一起使用。我的推送通知与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
应用程序委托方法
#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);>
似乎您的应用没有适当permissions
的生成能力push notifications
。
按照苹果在这种情况下的建议,我曾经也必须遵循。请执行以下步骤:
1)取消安装应用程序,然后重新启动手机。
2)转到设置->日期和时间,并将日期设置为当前日期至少1天。
3)再次重新启动您的设备。
4)现在进入设置,使时间恢复正常。
5)重新启动设备。6)现在安装该应用程序,它应该询问您推送通知的权限。如果它仍然不要求权限,请再次重复上述步骤,但是在第4步之后,而不是重新启动,只需安装应用程序,然后重新启动,就可以了。
我希望这可以解决您的问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句