美文网首页
点击推送通知进入固定页面

点击推送通知进入固定页面

作者: 我把今生当成了来世 | 来源:发表于2017-05-19 15:18 被阅读27次

来这里,了解很多问题,发掘更多。
👇👇👇 传送门->Have-a-problem👇👇👇

⚠️⚠️⚠️:以下内容来自于传送门链接👆👆👆

我目前的处理

  • APP未启动
  • APP已启动,在后台
  • iOS10点击推送

需要注意

iOS10 应用在前台的时候,推送通知会显示,所以可以直接点击,iOS10 以下的系统,我们目前先忽略的呢,如果有需要实现的可以自己定制就可以了,或者有一个第三方的哦,下面给出传送门

👇👇👇EBForeNotification👇👇👇

放大招(示例代码)

先说下:我的这个方法比较简单,如果你有更好的,希望可以分享下哦。

iOS10系统之前

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    // 极光
    JPUSHService.handleRemoteNotification(userInfo)
    completionHandler(.newData)
    
    // 这边判断应用是否在 前台 注意是不等于 .active
    if application.applicationState != .active {
        // 跳转到固定页面
        pushNoticeViewController()
    }
}

iOS10系统

@available(iOS 10.0, *)
func jpushNotificationCenter(_ center: UNUserNotificationCenter!, didReceive response: UNNotificationResponse!, withCompletionHandler completionHandler: (() -> Void)!) {
    if response.notification.request.trigger is UNPushNotificationTrigger {
        JPUSHService.handleRemoteNotification(response.notification.request.content.userInfo)
    }
    // 跳转到固定页面
    pushNoticeViewController()
    completionHandler()
}

跳转固定页面

func pushNoticeViewController() {
    let noticeVC = SXNoticeListViewController()
    let tabBarController: UITabBarViewController? = (self.window?.rootViewController as? UITabBarViewController)
    if tabBarController != nil {
        if (tabBarController?.selectedViewController?.childViewControllers.last) is SXNoticeListViewController {
            ((tabBarController?.selectedViewController?.childViewControllers.last) as! SXNoticeListViewController).tableView.mj_header.beginRefreshing()
        }else{
            (tabBarController?.selectedViewController?.childViewControllers.last)?.pushVC(noticeVC)
        }
    }
}

注意

以上内容为个人整理,如果有问题有出入或者你有更好的解决方法,还请赐教哦,感谢。
我的邮箱 coderjianfeng@foxmail.com 👉👉👉 github传送门

相关文章

网友评论

      本文标题:点击推送通知进入固定页面

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