如何在一个信号iOS Swift中处理可点击推送通知

时间:2018-01-11 01:43:43

标签: ios swift onesignal

我已经从一个信号(附加数据)中获取数据。但我想通过单击推送通知本身来呈现视图控制器。有人能帮我吗。提前谢谢。

2 个答案:

答案 0 :(得分:2)

您是否查看了OneSignal关于深度链接的文档? https://documentation.onesignal.com/docs/links

Github上有一个可能对您有帮助的演示项目:https://github.com/OneSignal/OneSignal-iOS-SDK/tree/master/Examples

答案 1 :(得分:1)

在didFinishLaunchingWithOptions中添加此内容   此代码将检查是否使用appIcon启动应用程序或点击通知

 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)
            }
        }