swift - 从推送打开 View Controller 时,汉堡菜单不会加载

标签 swift parse-platform push-notification

我有一个当前使用推送通知的应用程序,我们已开始尝试通过 JSON 推送打开该应用程序的特定页面。

这是可能打开的页面之一的代码:

//Extract the notification data
    if let notificationPayload = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary {
        // Get which page to open
        let viewload = notificationPayload["view"] as? NSString
        let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
        //Load correct view
                    if viewload == "videos" {
            let mainStoryboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let initialViewController : UIViewController = mainStoryboard.instantiateViewControllerWithIdentifier("Videos") as! UIViewController
            self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
            self.window?.rootViewController = initialViewController
            self.window?.makeKeyAndVisible()
        }
    }

问题是这样做会跳过允许在侧面打开汉堡菜单的 View Controller 。

有没有办法打开汉堡菜单 Controller 并从推送中加载正确的 View ?

如果您需要更多信息,请告诉我,我会根据需要发布更新

最佳答案

您通常不应该创建新窗口并设置 Root View Controller 。至少如果您不将 Root View Controller 设置为应用程序的真正根 VC 并要求它显示推送中的特定内容,则至少不会。

通常,您的根 VC 应该了解可能需要显示特定的 VC(来自推送或其他地方),并为应用程序委托(delegate)提供执行此操作的方法。这可以通过转发请求直到某个 VC 可以处理它来实现,它可能只是将其推送到导航 Controller 上,它可能会发布通知,或者它可能会呈现一个模式。

有很多潜在的选项,您需要决定哪个适合您的应用,但重要的是它与您现有的 View 层次结构相关联,而不是替换它。

关于swift - 从推送打开 View Controller 时,汉堡菜单不会加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31113484/

相关文章:

ios - 以编程方式从带有动画的 customCell 类的 tableView 中删除一行

ios - 如何向 UITableViewCell 添加触摸识别器?

node.js - 解析服务器设置用户 ACL 并分配角色

android - 是否有理由继续使用 IntentService 来处理 GCM 消息?

android - 使用 Android 和 iOS 在 Nodejs 中推送通知系统

Swift:为什么 JSONDecoder (Codable/Decodable) 不调用结构体的 init() 方法?

swift - 检查 Swift 闭包中的某些语句

安卓应用程序 : Unable to Login with Facebook in Development mode

swift - 将自动计时器 PFObject 添加到 Parse.com 类

windows-phone-7 - 可本地化的推送通知