2

按下推送通知后,我想导航到特定的视图控制器,如何在此处使用 OneSignal 推送通知进行操作?

 _ = OneSignal(launchOptions: launchOptions, appId: "b2f7f966-d8cc-11e4-bed1-df8f05be55ba") { (message, additionalData, isActive) in
        NSLog("OneSignal Notification opened:\nMessage: %@", message)

if additionalData != nil {
   NSLog("additionalData: %@", additionalData)
   // Check for and read any custom values you added to the notification
   // This done with the "Additonal Data" section the dashbaord.
   // OR setting the 'data' field on our REST API.
    if let customKey = additionalData["newid"] as! Int {
        //The navigation to a view controller code should be goes here...
        //I've no idea how to do it, I've tried some ways from stackoverflow also didn't work for me
    }
}
}
4

2 回答 2

1

您可以使用 jkasten 提议的 segue,或者:

let controller = self.storyboard!.instantiateViewControllerWithIdentifier("storyboardID") as! ClassOfYourView
self.presentViewController(controller, animated: true, completion: nil)

无论哪种方式,您仍然需要创建一个 storyboardID。

于 2016-02-25T10:38:29.927 回答
0

有几种方法可以做到这一点,其中之一是从你的“newid”if 语句中调用它。

self.performSegueWithIdentifier("GoToViewController", sender:self)

如果上面的代码不起作用,我建议您尝试从以编程方式在 swift 中以编程方式打开视图控制器的其他一些答案

于 2016-01-09T05:00:46.267 回答