简体   繁体   English

推送通知不显示

[英]Push notifications don't show up

I've added functionality for receiving remote notifications yet the behaviour is really weird. 我添加了用于接收远程通知的功能,但是该行为确实很奇怪。 When the application is in a foreground, the method 当应用程序处于前台时,该方法

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

is being called. 正在被呼叫。 Although when the app is in the background — nothing shows up. 尽管当应用程序在后台运行时-没有任何显示。 I do not see the banner with incoming notification's message and nothing appears in Notifications swipe down list. 我没有看到带有传入通知消息的横幅,并且“通知”下拉列表中没有任何内容。

One more weird thing — the application doesn't show up in device's Settings --> Notification apps list. 还有一件奇怪的事情—该应用程序未显示在设备的“设置”->“通知应用程序”列表中。 Is it ok that I receive them at all? 我完全可以接受吗? Even if it is only when in the background? 即使只是在后台?

Has anyone faced similar issues? 有没有人遇到过类似的问题?

When your app is open, the didReceiveRemoteNotification method will be called in your app delegate, but an alert will not be shown. 打开应用程序时,将在应用程序委托中调用didReceiveRemoteNotification方法,但不会显示警报。 The alert is only shown when your app is in background/inactive. 仅当您的应用程序处于后台/非活动状态时,才会显示警报。 You can though create a UIAlertView in your app easily enough and show it when the app is active and a push notification is received. 尽管您可以在应用程序中轻松创建一个UIAlertView,并在应用程序处于活动状态并收到推送通知时显示它。

Solved that stuff myself finally — I didn't call registerUserNotificationSettings , so no types of notifications were allowed. 最终,我自己解决了这些问题-我没有调用registerUserNotificationSettings ,所以不允许任何类型的通知。 Now I do this: 现在,我这样做:

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

Works perfectly! 完美的作品!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM