且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何处理点击推送通知ios

更新时间:2023-02-26 22:23:07

尝试处理这个点击代码,

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];
                        });

                    }
        }