从ios 11中的本地通知打开视图控制器 [英] Open a view controller from a local notification in ios 11

查看:82
本文介绍了从ios 11中的本地通知打开视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ios 11应用程序,该应用程序在给定时间使用本地推送通知来处理剩余部分.本地通知有效,并且在滑动时它们会打开我的应用程序的主视图.我的应用程序的主视图是uitableviewcontroller.提醒是表格视图中的行.

I have an ios 11 app that uses local push notifications for remainders at a given time. The local notifications work and when swiped they open up the main view of my app. My app's main view is a uitableviewcontroller. The reminders are rows in the table view.

如果单击提醒,则将打开self.presentview的新视图控制器...新视图将在表视图上弹出.我没有使用情节提要或Xib文件,而是通过编程方式进行的.

If you click on a reminder it open's a new view controller by self.presentview... The new view pops up over the table view. I am not using storyboards or xib files and doing it programmatically.

如何将提醒ID传递给推送通知并返回到应用程序,然后使该提醒ID打开第二个视图控制器?第二个视图控制器具有有关提醒的更多详细信息.

How do I pass the reminder id to the push notification and back to the app and then have that reminder id open the second view controller? The second view controller has more details about the reminder.

推荐答案

以anuraj的答案为基础.在 userInfo

Building upon the answer of anuraj. set the required details in userInfo

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

Then handle the navigation using the following method (in 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)
      }


    }

让我知道您是否需要任何帮助

Let me know if you need any help

这篇关于从ios 11中的本地通知打开视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆