【问题标题】:OneSignal press push notification to go a view controller iOS SwiftOneSignal 按下推送通知去一个视图控制器 iOS Swift
【发布时间】:2016-01-07 03:03:57
【问题描述】:

我想在按下推送通知后导航到特定的视图控制器,如何在此处使用 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
    }
}
}

【问题讨论】:

标签: ios swift push-notification onesignal


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

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

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

    如果上面的代码不起作用,我建议尝试Opening viewController programatically in swift 的其他一些答案

    【讨论】:

    • 这段代码必须有segue标识符,我需要在代码中传递视图而不是故事板...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-12
    • 2015-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多