关于极光推送的问题

今天第一次做推送,遇到了很多问题, 记录一下。。。。。。。。。

1.用CocoaPods 下载是最快、最简单的途径 ,只需在 podfile 文件中添加一下代码即可,具体集成,官网文档很清楚,不具体说明了

我遇到的问题是当App接收到通知之后,跳转到指定界面,极光推送有2个接收消息的方法

1.1 当app在运行状态下调用的方法

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

当app 在后台或者未运行的情况下调用的方法

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


如果点击通知进入app直接在第二种方法中接收数据,跳转即可

如果想用户正在使用时,提示用户可以用第一种方法进行接收数据

2接收数据进行跳转
刚开始用的通知跳转到指定界面的,但是发现一个问题,当用户正在使用app时,用户可能会在任意一个界面操作的时候来通知,不可能所有的界面都注册通知来进行跳转的操作,于是 此方法pass了。
3,获取当前屏幕显示的界面,然后push到指定界面,将接收到的数据以属性的方法进行传递,

//获取当前屏幕显示的viewcontroller

- (UIViewController *)getCurrentVC

{

    UIViewController *rootViewController = [UIApplicationsharedApplication].keyWindow.rootViewController;

    

    UIViewController *currentVC = [selfgetCurrentVCFrom:rootViewController];

    

    return currentVC;

}


- (UIViewController *)getCurrentVCFrom:(UIViewController *)rootVC

{

    UIViewController *currentVC;

    

    if ([rootVCpresentedViewController]) {

        // 视图是被presented出来的

        

        rootVC = [rootVC presentedViewController];

    }

    

    if ([rootVC isKindOfClass:[UITabBarControllerclass]]) {

        // 根视图为UITabBarController

        

        currentVC = [self getCurrentVCFrom:[(UITabBarController *)rootVCselectedViewController]];

        

    } else if ([rootVCisKindOfClass:[UINavigationControllerclass]]){

        // 根视图为UINavigationController

        

        currentVC = [self getCurrentVCFrom:[(UINavigationController *)rootVCvisibleViewController]];

        

    } else {

        // 根视图为非导航类

        

        currentVC = rootVC;

    }

    

    return currentVC;

}

//调用方法,获取到当前屏幕的 UIViewController

UIViewController * currectView = [selfgetCurrentVC];

这样就获取了controller


PushViewController * pushView = [[PushViewControlleralloc]init];

UIViewController * currectView = [selfgetCurrentVC];

[currectView.navigationController pushViewController:pushView animated:YES];

这样就直接跳转到了展示接收到的通知消息的内容



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值