我已经从OneSignal(附加数据)获取了数据。但是我想通过点击推送通知本身来呈现视图控制器。有人可以帮助我吗?提前致谢。
将以下代码添加到 didFinishLaunchingWithOptions 中,此代码将检查应用程序是通过应用图标启动还是通过点击通知启动:
self.window = UIWindow(frame: UIScreen.main.bounds)
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let tabBar = storyBoard.instantiateViewController(withIdentifier: "MainNavigationController")
as? UINavigationController
self.window?.rootViewController = tabBar
self.window?.makeKeyAndVisible()
if let notification = launchOptions?[.remoteNotification] as? [String: AnyObject] {
// 2
let aps = notification["aps"] as! [String: AnyObject]
let vc = storyBoard.instantiateViewController(withIdentifier: "EmergencyRequestViewController") as? EmergencyRequestViewController
tabBar?.pushViewController(vc!, animated: true)
}
}