极光推送 推送处理总结 点击通知跳转

来源:互联网 发布:java格式化日期24小时 编辑:程序博客网 时间:2024/06/10 16:44


当应用处于杀死状态的时候,通过点击通知内容开启APP 此时只需在  (位于后台的时候点击通知内容不会走这个方法)

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

]方法中判断launchOptions是否为空

例如:

  if (launchOptions !=nil) {// 不是空 就是推送点击 否则是图标启动

        NSDictionary* remoteNotification = [launchOptionsobjectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

if ([[UIDevicecurrentDevice].systemVersionfloatValue] < 10.0) {

 // iOS 10 不必走此方法

        [selfreciveNotification:remoteNotification];// 处理推送跳转方法 详见下方

      }

}

#pragma mark  iOS 6 以下收到推送

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

    [JPUSHServicehandleRemoteNotification:userInfo];

    //pushDic = userInfo;

    //[selfreciveNotificationAlertShow];

}


iOS 7 及以上10以下 收到推送及点击处理

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

    [JPUSHServicehandleRemoteNotification:userInfo];

    

 if (application.applicationState == UIApplicationStateActive) {

// 如果是前台运行出现弹窗

         pushDic = userInfo;

// 前台收到推送出现弹窗

        [selfreciveNotificationAlertShow];

    }else{

        // 处于后台 的点击

        [self reciveNotification:userInfo];

    }

    completionHandler(UIBackgroundFetchResultNewData);

}



#pragma mark iOS 10 前台收到通知(远程推送本地通知)

- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification*)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {

    NSDictionary * userInfo = notification.request.content.userInfo;

    if([notification.request.triggerisKindOfClass:[UNPushNotificationTriggerclass]]) {

        /// iOS10处理远程推送

        [JPUSHServicehandleRemoteNotification:userInfo];

        pushDic = userInfo;

// 前台出弹窗提示

        [self reciveNotificationAlertShow];

    }else{

        /// iOS10处理本地通知添加到通知栏

completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);

    }

    // 需要执行这个方法,选择是否提醒用户,有BadgeSoundAlert三种类型可以选择设置

}


当APP 无论运行于后台时,杀死 点击通知内容 开启APP 会走这个方法 这要在这个方法中处理推送跳转

iOS 10

- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {

    // Required

    NSDictionary * userInfo = response.notification.request.content.userInfo;

    if([response.notification.request.triggerisKindOfClass:[UNPushNotificationTriggerclass]]) {

// 推送处理

        [JPUSHServicehandleRemoteNotification:userInfo];

        [selfreciveNotification:userInfo];

    }else{

// 本地通知处理


}

    completionHandler();  // 系统要求执行这个方法

}



3. APP运行于前台的时候 需要获取到推送内容,添加alertView

// APP前台弹窗提示

- (void )reciveNotificationAlertShow{




}

 // APP杀死和后台时 推送点击的跳转处理

- (void)reciveNotification:(NSDictionary *)pushdic{

    // 点击推送之后广告页消失

        HuoDongXiangQingViewController *hdxqVC = [[HuoDongXiangQingViewControlleralloc]init];

        hdxqVC.hidesBottomBarWhenPushed =YES;

    // 获取当前停留的controler 进行push

        [[selfcurrentViewController].navigationControllerpushViewController:hdxqVCanimated:YES];

   }


#pragma mark 获取当前的停留的VC用来实现任意页面跳转到指定页面

- (UIViewController *)currentViewController{

    UIViewController *currVC =nil;

    UIViewController *Rootvc =self.window.rootViewController;

    do{

        if ([RootvcisKindOfClass:[UINavigationControllerclass]]) {

            UINavigationController *nav = (UINavigationController *)Rootvc;

            UIViewController *v = [nav.viewControllerslastObject];

            currVC = v;

            Rootvc = v.presentedViewController;

            continue;

        }elseif ([RootvcisKindOfClass:[UITabBarControllerclass]]){

            UITabBarController *tabvc = (UITabBarController *)Rootvc;

            currVC = tabvc;

            Rootvc = [tabvc.viewControllersobjectAtIndex:tabvc.selectedIndex];

            continue;

        }


    }while (Rootvc !=nil);

        return currVC;

}

// APP 处于前台的时候 推送通知点击创建alertview  点击跳转方法和杀死 后台运行状态处理方法相同

- (void)reciveNotificationAlertShow{

    UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"提示"message:@"收到热门推送"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"查看",nil];

    [alert show];

}






获取当前页的方法也可以使用

- (UIViewController *)topVC:(UIViewController *)rootViewController{

    if ([rootViewControllerisKindOfClass:[UITabBarControllerclass]]) {

        UITabBarController *tab = (UITabBarController *)rootViewController;

        return [selftopVC:tab.selectedViewController];

    }elseif ([rootViewControllerisKindOfClass:[UINavigationControllerclass]]){UINavigationController *navc = (UINavigationController *)rootViewController;

        return [selftopVC:navc.visibleViewController];

    }elseif (rootViewController.presentedViewController){

        UIViewController *pre = (UIViewController *)rootViewController.presentedViewController;

        return [selftopVC:pre];

    }else{

        return rootViewController;

    }

}

使用方法 

        UIViewController *vc = [selftopVC:[UIApplicationsharedApplication].keyWindow.rootViewController];

        huodong.hidesBottomBarWhenPushed =YES;

        [vc.navigationControllerpushViewController:huodonganimated:YES];

如果想实现模态效果 可以这样写

       TBMoiveViewController* currentView = [[TBMoiveViewControlleralloc]init];

       // 创建导航栏

        FLGNanViewController *nanVC = [[FLGNanViewControlleralloc]initWithRootViewController:currentView];

        [self.window.rootViewControllerpresentViewController:nanVCanimated:YEScompletion:^{

            

        }];



0 0
原创粉丝点击