iOS - 应用程序运行时不显示推送通知警报 [英] iOS - Push notification alert is not shown when the app is running
问题描述
我在我的应用中集成了推送通知。用户将收到推送通知以加入群组。当用户点击加入时,我将处理代码中的内容。所以我正在实现:
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
当应用程序未运行时,此功能正常。
当应用程序运行时,我没有看到任何 UIAlertView
。如何让我的应用程序显示推送通知提醒,以便用户仍然可以决定是否加入?
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?
推荐答案
我使用的代码这样在我的应用程序委托中模仿应用程序处于活动状态时的通知警报。您应该实现适当的 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.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive) {
NSString *cancelTitle = @"Close";
NSString *showTitle = @"Show";
NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Some title"
message:message
delegate:self
cancelButtonTitle:cancelTitle
otherButtonTitles:showTitle, nil];
[alertView show];
[alertView release];
} else {
//Do stuff that you would do if the application was not active
}
}
这篇关于iOS - 应用程序运行时不显示推送通知警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!