ios - 从 iOS 11 中的本地通知打开 View Controller

标签 ios swift push-notification swift4 ios11

我有一个 ios 11 应用程序,它在给定时间使用本地推送通知来获取剩余内容。本地通知有效,当滑动时,它们会打开我的应用程序的主视图。我的应用程序的主视图是 uitableviewcontroller。提醒是表格 View 中的行。

如果您单击提醒,它会通过 self.presentview 打开一个新的 View Controller ...新 View 会在 TableView 上弹出。我没有使用 Storyboard 或 xib 文件并以编程方式执行此操作。

如何将提醒 ID 传递到推送通知并返回到应用程序,然后让该提醒 ID 打开第二个 View Controller ?第二个 View Controller 具有有关提醒的更多详细信息。

最佳答案

基于 anuraj 的回答。在userInfo中设置所需的详细信息

然后使用以下方法处理导航(在 appDelegate.swift 中)

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {

      print("didReceiveRemoteNotificationfetchCompletionHandler \(userInfo)")
      let id = userInfo["reminderID"] as! String
      /// HANDLE NAVIGATION HERE
      if let tableVC = self.window?.rootViewController as? yourTableViewControllerClass {
        let reminderDetailsVC = yourReminderDetailsVC()
        reminderDetailsVC.reminderID = id
        tableVC.present(reminderDetailsVC, animated: true)
      }


    }

如果您需要任何帮助,请告诉我

关于ios - 从 iOS 11 中的本地通知打开 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51626479/

相关文章:

swift - 将任意长度的数组绑定(bind)到 SQLite 查询

快速访问 self.init

swift - 在 Swift 3 中, 'private class Foo' 和 'fileprivate class Foo' 在成员变量方面有区别吗?

ios - 获取自应用程序上次打开以来收到的所有推送通知

objective-c - 在 iOS 中没有报摊的应用程序处于非事件状态时在后台下载文件

ios - react native GridView : Flexbox wrap not working

javascript - 上传到 Cloudinary API - 文件参数无效

ios - 应用程序是从图标或通知打开的

ios - TLauncher View 将项目移动到另一个页面

ios - 我想创建 CustomCell 但它给出了一些错误,如何解决它?错误描述如下