iOS - 应用程序运行时不显示推送通知警报
我已在我的应用程序中集成了推送通知。用户将收到加入群组的推送通知。当用户单击加入时,我必须处理代码中的某些内容。所以我正在实施:
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
当应用程序未运行时,这工作正常。
当应用程序运行时,我看不到任何 UIAlertView
。如何让我的应用程序显示推送通知警报,以便用户仍然可以决定是否加入?
I've integrated push notifications in my app. Users will receive push notification to join a group. When the user clicks Join, I've to handle something in the code. And so I'm implementing:
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
This is working fine when the app is not running.
When the app is running, I don't see any UIAlertView
. How can make my app show the push notification alert so that user can still decide whether to join or not?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我在应用程序委托中使用了这样的代码来模拟应用程序处于活动状态时的通知警报。您应该实现适当的 UIAlertViewDelegate 协议方法来处理用户点击任一按钮时发生的情况。
I used code like this in my application delegate to mimic the notification alert when the app was active. You should implement the appropriate
UIAlertViewDelegate
protocol method(s) to handle what happen when the user taps either of the buttons.对于任何可能感兴趣的人,我最终创建了一个自定义视图,看起来像顶部的系统推送横幅,但添加了一个关闭按钮(小蓝色 X)和一个用于点击消息以执行自定义操作的选项。它还支持在用户有时间阅读/忽略旧通知之前到达多个通知的情况(对可以堆积的数量没有限制......)
GitHub 链接:AGPushNote
使用方式基本上是在线的:
在 iOS7 上看起来像这样(iOS6 有 iOS6 的外观和感觉。 ..)
For anyone might be interested, I ended up creating a custom view that looks like the system push banner on the top but adds a close button (small blue X) and an option to tap the message for custom action. It also supports the case of more than one notification arrived before the user had time to read/dismiss the old ones (With no limit to how many can pile up...)
Link to GitHub: AGPushNote
The usage is basically on-liner:
And it looks like this on iOS7 (iOS6 have an iOS6 look and feel...)
如果您愿意,您必须自己显示警报。这是故意行为,如此处记录的 http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html 下面清单 2-6
You have to show the alert yourself if you want to. This is intentional behavior as documented here http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html below Listing 2-6
仅调用此函数,并且您必须在这种情况下显式显示警报,如果您已实现通知的应用程序正在运行,则不会收到任何通知。将断点放在那里,并在调用函数时处理通知调用并显示您的自定义在那里保持警惕。
only this function will be invoked and you have to explicitly show the alert on that case no notification will come if app is running in which you have implement the notification.Put the break point there and handle the notification call when function called and show your customized alert there.
要在运行应用程序时显示警报视图,您必须使用
并访问
userInfo
变量For showing alert view while running application you have to use
and by accessing the
userInfo
variable应用程序仍会在您的应用程序委托中接收
-application:didReceiveRemoteNotification
消息,但您必须自己对该消息采取行动(即默认情况下不显示警报)。userInfo
参数包含一个带有键notificationType
的对象,您可以使用它来标识推送消息。The app will still receive the
-application:didReceiveRemoteNotification
message in your App Delegate, but you'll have to act on the message yourself (i.e. the alert isn't displayed by default).The
userInfo
parameter contains an object with the keynotificationType
, which you can use to identify the push message.这是支持 UIAlertController 的版本
}
** 请注意,我的应用程序在 App Delegate 中使用 self.navigationController,只需挂接到任何 ViewController 即可呈现(显示)警报 **
Here is a version which support UIAlertController
}
** Please note my app uses self.navigationController in App Delegate, just hook on to any ViewController to present ( show ) the Alert **