【发布时间】:2015-04-09 10:47:23
【问题描述】:
我有一个应用程序,我想将 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
应用委托方法
#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);>
【问题讨论】:
-
你的设备iOS版本是多少?
-
@TENSRI 应用现在在 iOS 8.2 上运行
-
据我所知,一切都很好,您可以尝试删除应用程序并重新安装或清理项目中的构建......
-
你在Project Capabilities中开启远程通知了吗??
-
@kayzersoze 你能在这里粘贴你推送通知委托方法吗?
标签: ios objective-c push-notification