点击推送,跳转到查看推送消息的页面
- ( BOOL )application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ <br> <br> if (launchOptions) <br> <br> { <br> <br> [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]; <br> <br> NSDictionary *userInfo = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey]; <br> <br> [self presentViewControllerWithUserInfo:userInfo]; <br> <br> } <br> <br>} <br> <br> <br> <br> //App状态为正在前台或者后台运行,那么此函数将被调用 <br> <br>- ( void )application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo <br> <br>{ <br> <br> <br> <br> if (application.applicationState != UIApplicationStateActive) <br> <br> { <br> <br> <br> <br> [self presentViewControllerWithUserInfo:userInfo]; <br> <br> <br> <br> } <br> <br>} <br> <br> <br> <br>#pragma mark - 消息跳转页面 <br> <br>- ( void )presentViewControllerWithUserInfo:(NSDictionary *)userInfo <br> <br>{ <br> <br> //拿出你的消息内容,跳转即可~~ <br> <br>[self.window.rootViewController presentViewController:fyfNavCtrl animated:YES completion:^{ <br> <br> // <br> <br> }]; <br> <br>} |
第一种,如果程序是打开的,但是在后台,这个时候收到推送信息,可以进入指定页面- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 方法可以做到
程序完全没有启动的时候,是不会调用第一种那个方法的
第二种- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 这个函数在你正常启动下 launchOptions 是空,如果你是从点击推送通知过来的,那么 laungchOptions里面会包含你的推送的内容。在这里就可以进行相应的处理
推送消息可以带自定义字段,
如message:”/product/detail”
程序在收到推送消息时,读取消息该字段,就可以直接跳转了!