推送通知不会显示

时间:2015-01-05 23:06:18

标签: ios ios8 push-notification notificationcenter

我添加了接收远程通知的功能,但行为真的很奇怪。 当应用程序在前台时,方法

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
正在呼叫

。虽然应用程序在后台时 - 没有任何显示。我看不到带有传入通知消息的横幅,并且通知滑动列表中没有任何内容。

另一个奇怪的事情 - 应用程序没有显示在设备的设置中 - >通知应用列表。我收到它们可以吗?即使它只是在后台?

有没有人遇到类似的问题?

2 个答案:

答案 0 :(得分:1)

当您的应用程序处于打开状态时,将在您的应用程序委托中调用didReceiveRemoteNotification方法,但不会显示警报。警报仅在您的应用处于后台/非活动状态时显示。您可以在应用程序中轻松创建UIAlertView,并在应用程序处于活动状态并收到推送通知时显示。

答案 1 :(得分:0)

我自己解决了这些问题 - 我没有打电话给registerUserNotificationSettings,所以不允许任何类型的通知。现在我这样做:

[application registerForRemoteNotifications];
UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[application registerUserNotificationSettings:mySettings];

完美无缺!

相关问题