Open specific viewcontroller when opening app from push notification [duplicate]

时光怂恿深爱的人放手 提交于 2019-12-21 02:59:14

问题


As the title implies: how do I open a specific viewcontroller when a user starts the app by swiping on a push notification?

Thanks!


回答1:


Do the following,

in your apps main view controller "viewDidLoad" method add an observer,

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

And also add a method

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

and add the below code in your "didReceiveRemoteNotification" method of Appdelegate class of your app

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

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


来源:https://stackoverflow.com/questions/34856605/open-specific-viewcontroller-when-opening-app-from-push-notification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!