swift - 不快速从应用程序委托重定向到另一个视图控制器
问题描述
我有一个推送通知,点击它,我需要重定向到另一个视图控制器而不是主视图控制器。我已经在应用程序委托方法中为它编写了代码。它不会重定向到提及情节提要名称的特定视图控制器。
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler:
@escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
// Print message ID.
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
// Print full message.
print(userInfo)
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let presentViewController = storyBoard.instantiateViewController(withIdentifier: "MessageViewController") as! MessageViewController
self.window?.rootViewController?.present(presentViewController, animated: true, completion: nil)
completionHandler()
}
它不会重定向到 MessageViewController,而是仅重定向到默认的主视图控制器。
上述代码中的错误可能是什么?
解决方案
推荐阅读
- sql-server - 尝试按字母数字值排序时传递给 LEFT 或 SUBSTRING 函数的长度参数无效
- python - 将 2D numpy 数组转换为一个 Dataframe 行
- javascript - 使用正则表达式从代码中提取全局浮点数
- optimization - 可以在函数之间应用公共子表达式消除吗?
- java - 如何使用 Java 中的 iText 库遍历 PDF 的内部结构?
- build - 在插件包中包含依赖项(汇总)
- react-native - 向 FlatList 添加数据会清除整个列表
- java - 从文件 Graphics2D 添加 CustomFont - Java
- ios - 将裁剪后的 UIImage 保存到 CGPath
- html - 从 CSS 访问 HTML 中的子类时遇到问题