美文网首页
iOS 点击推送跳转详情页

iOS 点击推送跳转详情页

作者: 头像是我老婆 | 来源:发表于2017-09-15 11:12 被阅读0次

系统 API :iOS < 77 <= iOS < 10iOS >= 10
app 状态:后台运行前台运行未启动

iOS 6 及以前接收到远程推送的代理

- application: didReceiveRemoteNotification;

- application: didReceiveRemoteNotification 官方文档
If the app is running, the app calls this method to process incoming remote notifications. If the app is not running when a remote notification arrives, the method launches the app and provides the appropriate information in the launch options dictionary. The app does not call this method to handle that remote notification.
Instead, your implementation of the application:willFinishLaunchingWithOptions:
or application:didFinishLaunchingWithOptions: method needs to get the remote notification payload data and respond appropriately.

如果应用程序正在运行,应用程序调用这个方法来处理传入的远程通知。
如果应用程序在远程通知到达时没有运行,该方法会启动应用程序,并提供启动信息。应用程序不会调用这个方法来处理远程通知。这时你可以通过application:didFinishLaunchingWithOptions:方法来获得推送信息。
虽然是iOS 6之前的,但使用范围是NS_DEPRECATED_IOS(3_0, 10_0)。只是iOS 7之后有了更好的选择,所以这个就显得有点鸡肋了。如果要适配iOS 6及以前还需实现这个

iOS 7(包含) 到 iOS 10(不包含)新增代理。

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    NSLog(@"[XGDemo] receive slient Notification");
    NSLog(@"[XGDemo] userinfo %@", userInfo);
    if (application.applicationState == UIApplicationStateActive) {
        // 前台处理
    }else {
        [self pushToVCWithNotificationInfo:userInfo];
    }
    completionHandler(UIBackgroundFetchResultNewData);
}

- application:didReceiveRemoteNotification:fetchCompletionHandler 官方文档
 Use this method to process incoming remote notifications for your app. Unlike the application:didReceiveRemoteNotification:method, which is called only when your app is running in the foreground,the system calls this method when your app is running in the foreground or background.
 If your delegate implements both methods, the app object calls the application:didReceiveRemoteNotification:fetchCompletionHandler: method.

application:didReceiveRemoteNotification:只有当应用程序在前台运行调用,而这个方法在前台、后台、未启动都能调用。如果两个代理方法都被实现了,系统将只调用application:didReceiveRemoteNotification:fetchCompletionHandler:

因为我们应用只适配iOS 8及以上,所以我就没有再实现- (void)application: didReceiveRemoteNotification ;毕竟有了更新的代理,更简单不用单独处理应用未启动的情况。当然也可以使用- application: didReceiveRemoteNotification;

iOS 10及以上新增代理

首先要在application:didFinishLaunchingWithOptions中加入

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = self;
#endif

然后实现代理

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler {
    NSLog(@"[XGDemo] click notification");
    //收到推送的请求
    UNNotificationRequest *request = response.notification.request;
    //收到推送的内容
    UNNotificationContent *content = request.content;
    //收到用户的基本信息
    NSDictionary *userInfo = content.userInfo;
    [self pushToVCWithNotificationInfo:userInfo];
    completionHandler();
}
- userNotificationCenter: willPresentNotification: withCompletionHandler;   // App 在前台弹通知需要调用这个接口

跳转详情页

- (void)jumpWithNotificationInfo:(NSDictionary *)info {
    // 如果为空就返回
    if (!info) {
        return;
    }
    // 获取包含的信息
    NSString *type = info[@"type"];
    // 首先,到最外层
    UIViewController *topView;
    topView = [self topViewController]; // 当前控制器
    [topView.navigationController popToRootViewControllerAnimated:NO]; // 跳到一级界面
    if ([type isEqualToString:@"commentpass"]) { // 足迹
        self.mainVC.selectedIndex = 0;  // 然后,选中第几个模块
        DiscoveryDetialViewController *VC = [[DiscoveryDetialViewController alloc] init];
        UINavigationController *nav = self.mainVC.childViewControllers[0];
        VC.hidesBottomBarWhenPushed = YES;
        [nav pushViewController:VC animated:YES];
    }
}

相关文章

  • iOS 点击推送跳转详情页

    系统 API :iOS < 7、 7 <= iOS < 10、 iOS >= 10app 状态:后台运行、 前台...

  • iOS应用跳转到appstore评分

    iOS应用跳转到appstore评分 标签(空格分隔): IOS 跳转到应用评价页 跳转到应用详情页 appid是...

  • One

    1.activityA跳转activityB然后再返回,他们的生命周期执行顺序 2.点击推送的通知启动商品详情页,...

  • vue三种传参方法

    例子:点击项目列表页,跳转到项目详情列表页 方法一 点击列表页li元素跳转到详情页,并把项目id传给详情页,以便于...

  • iOS点击推送通知跳转页面

    iOS的推送通知,除了带有title和content这些明文字段外,还可以夹带一些自定义参数。使用这些参数,我们就...

  • iOS 点击推送消息跳转页面

    看标题就应该知道这次的主题是讲点击推送的消息跳转页面的功能,那么有关证书配置及完整的接入推送功能这里就不细说了,不...

  • iOS极光推送 点击推送消息跳转页面

    最近在搞极光推送,之前用的百度推送,但是消息延迟的厉害,就换了极光,换就换吧,无所谓反正我不会,于是就开始看极光推...

  • 【知识总结】(2)远程推送

    推送SDK:极光推送 后台点击推送: iOS 10 以下收到推送点击触发 iOS 10 以上触发: 极光推送中使用...

  • iOS 推送通知-跳转到详情页

    ios推送分为两种,一种是本地推送,一种是远程推送。项目需要实现的就是通过远程推送来进入到指定的页面,要做远程推送...

  • H5判断是iOS还是android

    iOS跳转到app store的应用详情页android直接下载apk

网友评论

      本文标题:iOS 点击推送跳转详情页

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