【问题标题】:Open specific viewcontroller when opening app from push notification [duplicate]从推送通知打开应用程序时打开特定的视图控制器[重复]
【发布时间】:2016-04-23 17:38:13
【问题描述】:

顾名思义:当用户通过滑动推送通知启动应用程序时,如何打开特定的视图控制器?

谢谢!

【问题讨论】:

标签: ios swift notifications push


【解决方案1】:

执行以下操作,

在您的应用程序主视图控制器“viewDidLoad”方法中添加一个观察者,

NSNotificationCenter.defaultCenter().addObserver(self,
        selector: "SomeNotificationAct:",
        name: "SomeNotification",
        object: nil)

并且还要添加一个方法

func SomeNotificationAct(notification: NSNotification){     
    dispatch_async(dispatch_get_main_queue()) {
     self.performSegueWithIdentifier("NotificationView", sender: self)
    }
}

并在您应用的 Appdelegate 类的“didReceiveRemoteNotification”方法中添加以下代码

 func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]){

     NSNotificationCenter.defaultCenter().postNotificationName("SomeNotification", object:nil, userInfo:someData)
}

【讨论】:

  • 什么是someData?在 func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]){ NSNotificationCenter.defaultCenter().postNotificationName("SomeNotification", object:nil, userInfo:someData) }
猜你喜欢
  • 2013-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-13
  • 2014-01-12
  • 1970-01-01
相关资源
最近更新 更多