本文介绍了如何在应用程序的活动状态下将远程推送通知显示为横幅样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个我正在使用苹果推送通知的应用。当我的应用处于后台状态时,我可以收到通知作为横幅,但当我的应用处于活动状态时,我能够显示通过此代码收到通知的提醒: -

I am making an app in which I am using apple push notification. When my app is in background state then I am able to receive notification as a banner but when my app is in active state then I am able to show an alert that you have received a notification through this code : -

(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];

    } else {
        //Do stuff that you would do if the application was not active
    }
}

但我想将通知显示为横幅。我会为此做些什么?请建议。

but I want to show notification as a banner. What I'll do for it? Please suggest.

推荐答案

如果您的应用处于活动状态(在前台运行),则无法直接发送推送通知到你的应用程序。通知中心不会处理通知。

You can't, if your app is active(running in the foreground) the push notification is directly send to your app. The notification center will not handle the notification.

您必须自己实施某种横幅。

You will have to implement some kind of banner your self.

这篇关于如何在应用程序的活动状态下将远程推送通知显示为横幅样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 08:21