0

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

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

正在被调用。虽然当应用程序在后台时 - 什么都没有出现。我没有看到带有传入通知消息的横幅,并且通知向下滑动列表中没有任何内容。

还有一件奇怪的事情——应用程序没有出现在设备的设置——>通知应用程序列表中。我可以收到它们吗?即使它只是在后台?

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

4

2 回答 2

1

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

于 2015-01-05T23:22:40.917 回答
0

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

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

完美运行!

于 2015-01-09T17:55:22.767 回答