美文网首页iOS 三方分享登录推送
iOS 友盟推送(二)远程推送处理

iOS 友盟推送(二)远程推送处理

作者: HH思無邪 | 来源:发表于2019-07-16 23:24 被阅读2次
  • 1.程序未启动处理通知

  • 2.程序已启动-应用在前台处理通知

  • 3.程序已启动-应用在后台处理通知

**仅支持iOS10及以上版本**

iOS10新增:处理后台、前台、程序未启动状态下 点击通知的代理方法

-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler{
    NSDictionary * userInfo = response.notification.request.content.userInfo;
    if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
       //应用处于运行时(前台、后台)的消息处理,回传点击数据
        [UMessage didReceiveRemoteNotification:userInfo];
        TSLog(userInfo);
//        NSString *notifactionType = userInfo[@"content-available"];
            NSString *type = userInfo[@"type"];
     
            //1:互动通知;2:私信;3;内容推送
            if ([type integerValue] == 1) {
              JPMessageNotificationViewController *vc = [[JPMessageNotificationViewController alloc]init];
            UITabBarController *tab = (UITabBarController *)self.window.rootViewController;
            JPNavigationViewController *nav = tab.viewControllers[tab.selectedIndex];
            [nav pushViewController:vc animated:NO];
                
            } else if ([type integerValue] == 2){
            JPMessageListViewController *messageListVC = [[JPMessageListViewController alloc]init];

                UITabBarController *tab = (UITabBarController *)self.window.rootViewController;
                JPNavigationViewController *nav = tab.viewControllers[tab.selectedIndex];
                [nav pushViewController:messageListVC animated:NO];

            }else{
                JPHotPushDetailViewController *destaileVC = [[JPHotPushDetailViewController alloc]init];
                UITabBarController *tab = (UITabBarController *)self.window.rootViewController;
                JPNavigationViewController *nav = tab.viewControllers[tab.selectedIndex];
                [nav pushViewController:destaileVC animated:NO];
            }
        [UMessage setBadgeClear:YES];
    }else{
        //应用处于后台时的本地推送接受
    }}

iOS 10后,通知的处理变得简单了,只在这一个代理中处理就可以了。

可能遇到pop 回来的界面导航栏消失

  • 在baseViewController 中,也就是基类控制器
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.delegate=self;
}

如果有启动广告,点击通知启动程序不加载广告

  • 判断是否是通知启动程序
  • 只加载根控制器,不做通知的处理
//程序启动成功
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

 if (launchOptions) {
        NSDictionary *userInfo = [launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
        if (userInfo) { //点击通知启动应用
            //加载根控制器
            [self INMainTabbarViewController];
        }
    }else{
        //正常启动流程,加载广告后再加载根控制器
        [self INLaunchAd];
    }
 return YES;
}

iOS 友盟推送(一)集成+基础配置

相关文章

网友评论

    本文标题:iOS 友盟推送(二)远程推送处理

    本文链接:https://www.haomeiwen.com/subject/uugxlctx.html