如何处理点击推送通知ios [英] How to handle on click on push notifications ios

查看:89
本文介绍了如何处理点击推送通知ios的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法收到推送通知,但我不知道如何处理到达应用程序的推送通知上的点击,我想告诉应用程序点击时根据通知类型转到特定活动,不只是打开应用程序(默认行为)

I managed to recive a push notification, but i don't know how to handle the click on the push notification that arrive to the application, i want to tell the application when click go to specific activity based on the type of notification, not just open the app (Default behavior)

我知道我可以收到

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{

    NSLog(@"Here I should Recive The notification .... ") ;
    //call the commented functions .....
}

在这个函数中,但是当我实现它时,通知不会出现,只是在这个函数中做什么

in this function , but when i implement it, the notification don't appear and just do what in this function

推荐答案

尝试处理这个点击代码,

Try to handle this the click as shown in code,

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

//Accept push notification when the app is not open.
        if (remoteNotifiInfo) {
            [self application:application didReceiveRemoteNotification: remoteNotifiInfo];
        }

}



   // On click of notification open related screen.

像这样覆盖 didReceiveRemoteNotification

override didReceiveRemoteNotification like this

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
        {
                    UIApplicationState state = [[UIApplication sharedApplication] applicationState];
                    if ( state == UIApplicationStateInactive )
                    {
                        //Your actions on notification click
                        double delayInSeconds = 0.3;
                        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
                        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
                            //code to be executed on the main queue after delay
                            [[NSNotificationCenter defaultCenter] postNotificationName:@"pushTOEventDetails" object:eventVO];
                        });

                    }
        }

这篇关于如何处理点击推送通知ios的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆