如何处理 One Signal iOS Swift 中可点击的推送通知

3

我已经从OneSignal(附加数据)获取了数据。但是我想通过点击推送通知本身来呈现视图控制器。有人可以帮助我吗?提前致谢。

2个回答

4

这个 https://github.com/OneSignal/OneSignal-iOS-SDK/tree/master/Examples 对我很有帮助。 - Rishi

0

将以下代码添加到 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)
            }
        }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接