美文网首页
swift3.0 推送页面跳转

swift3.0 推送页面跳转

作者: 嗯哼丶傻大个是你 | 来源:发表于2017-04-27 12:04 被阅读0次

在AppDelegate

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    
    window = UIWindow(frame: UIScreen.main.bounds)
    let tabBarVC = TBTabBarController()
    window!.rootViewController = tabBarVC
    window!.makeKeyAndVisible()
    
    let set = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
    UIApplication.shared.registerUserNotificationSettings(set)
    
    
    // 程序被杀死时跳转页面
    if let options = launchOptions {
      if let notification = options[UIApplicationLaunchOptionsKey.localNotification] as? UILocalNotification  {
        let userInfo = notification.userInfo
        let apsInfo = userInfo?["id"] as? String
        // 展示推送的信息
        let alert = UIAlertView(title: "\(userInfo!)", message: nil, delegate: nil, cancelButtonTitle: "确定")
        alert.show()
        if apsInfo == "detail" {
          //页面跳转
          let VC = UIStoryboard(name: "Discover", bundle: nil).instantiateViewController(withIdentifier: "Message") as! MessageDetailViewController
          VC.isForNotification = true
          let nc = TBNavigationController(rootViewController: VC)
          self.window?.rootViewController?.present(nc, animated: true, completion: nil)
        }
      }
    }
    return true
  }

本地通知页面跳转

func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
    //程序后台
    if UIApplication.shared.applicationState == UIApplicationState.inactive {
      guard let userInfos = notification.userInfo else {
        return
      }
      let apsInfo = userInfos["id"] as? String
      print(userInfos)
      if apsInfo == "detail" {
        let VC = UIStoryboard(name: "Discover", bundle: nil).instantiateViewController(withIdentifier: "Message") as! MessageDetailViewController
        let nc = TBNavigationController(rootViewController: VC)
        VC.isForNotification = true
        self.window?.rootViewController?.present(nc, animated: true, completion: nil)
      }
    }
    //程序前台
    if application.applicationState == UIApplicationState.active {
      guard let userInfo = notification.userInfo else {
        return
      }
//      let alert = UIAlertView(title: "\(userInfo)", message: nil, delegate: nil, cancelButtonTitle: "确定")
//      alert.show()
    }
  }

远程推送

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
    let tabBarVC = TBTabBarController()
    window!.rootViewController = tabBarVC
// 程序进入后台
    if UIApplication.shared.applicationState == UIApplicationState.inactive {
      if TBUser.currentUser.logined {
          let apsInfo = userInfo["aps"] as! NSDictionary
          print(userInfo)
      }
    }
  }

在viewController

let noti = UILocalNotification()
    noti.repeatInterval = NSCalendar.Unit.minute
    noti.fireDate = Date().addingTimeInterval(-1*60)   // 每分钟推送一次
    noti.timeZone = NSTimeZone.default
    noti.alertBody = "推送消息"
    noti.alertTitle = "test"
    noti.soundName = UILocalNotificationDefaultSoundName
    noti.userInfo = ["id": "detail"]
    noti.applicationIconBadgeNumber = 1
    noti.alertAction = "跳转"
    UIApplication.shared.scheduleLocalNotification(noti)

移除所有通知

  UIApplication.shared.cancelAllLocalNotifications()

有兴趣的话 可以下载Demo: https://github.com/BJGX/LocalNotification

相关文章

  • swift3.0 推送页面跳转

    在AppDelegate 本地通知页面跳转 远程推送 在viewController 移除所有通知 有兴趣的话 可...

  • 消息推送---跳转到指定页面

    最近在弄友盟推送,点击推送的消息,打开App,不管在哪个页面都要跳转对应的页面。其中在跳转对应的页面这块卡了,在这...

  • Android推送之弹窗显示+推送点击处理

    推送弹窗 兼容8.0 推送点击处理 当点击推送时,会跳转到pendingintent指定的页面。但是页面太多,我们...

  • 检查app是否具有推送权限

    检查app是否具有推送权限 检查是否有推送权限 跳转到登录页面

  • 2022-05-30

    极光多厂商离线推送,点击只能跳转app首页,不能跳转指定页面 现象:应用集成极光推送,在线和厂商离线都测试好好的。...

  • 极光推送跳转到具体详情

    极光推送点击推送跳转到详情,使用这个方法 极光会传递具体信息过来 自己打印看具体信息,然后根据自己需要跳转具体页面

  • iOS推送跳转不同的指定页面

    在接受推送信息之中获取要跳转页面的字符串,再将字符串转化为对象,进行该页面的跳转 Class c =NSClass...

  • iOS推送跳转不同的指定页面

    在接受推送信息之中获取要跳转页面的字符串,再将字符串转化为对象,进行该页面的跳转 Class c =NSClass...

  • Android 推送 - Activity 跳转控制处理

    PushHandlerPro - Github Android 点击推送逻辑处理,以及页面跳转判断等 需求 主要功...

  • iOS应用内跳转系统推送设置页

    判断用户是否打开了推送 然后如果用户没有打开推送按钮跳转到应用相关设置页面 参考资料 iOS应用内跳转到指定系统设置页

网友评论

      本文标题:swift3.0 推送页面跳转

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