iOS 8 推送通知在真实设备上不起作用
iOS 8 Push notification does not work on real device
我有一个通用应用程序我想将 APN 与 iOS 推送通知一起使用。我的推送通知与 ios 8 及更低版本兼容。当我在模拟器上启动时,推送通知权限对话框可以正常工作。但是当在真实设备上启动时它说;
"Attempting to badge the application icon but haven't received
permission from the user to badge the application"
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) 卸载应用程序,然后重新启动您的 phone.
2) 转到设置 -> 日期和时间并将日期设置为至少比当前日期提前 1 天。
3) 再次重启您的设备。
4) 现在进入设置,将时间恢复正常。
5) 重启设备。
6) 现在安装应用程序,它会询问您推送通知的权限。如果它仍然不请求权限,请再次重复上述步骤,但在第 4 步之后不要重新启动,只需安装应用程序然后重新启动即可。
我希望这能解决您的问题。
我有一个通用应用程序我想将 APN 与 iOS 推送通知一起使用。我的推送通知与 ios 8 及更低版本兼容。当我在模拟器上启动时,推送通知权限对话框可以正常工作。但是当在真实设备上启动时它说;
"Attempting to badge the application icon but haven't received permission from the user to badge the application"
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) 卸载应用程序,然后重新启动您的 phone.
2) 转到设置 -> 日期和时间并将日期设置为至少比当前日期提前 1 天。
3) 再次重启您的设备。
4) 现在进入设置,将时间恢复正常。
5) 重启设备。
6) 现在安装应用程序,它会询问您推送通知的权限。如果它仍然不请求权限,请再次重复上述步骤,但在第 4 步之后不要重新启动,只需安装应用程序然后重新启动即可。
我希望这能解决您的问题。