Reputation: 8049
My case is something special, since this works me correctly if the application is opened in normal mode.
This is when I try to do so after receiving a push notification.
inside didReceive notification:
func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
i'm calling a function from my initial view controller(HOME)
That is just the view that is displayed when the application opens when you click on the notification
let homeVC : HomeViewController! = HomeViewController()
homeVC.goAdvertisement(id, data: dataInfo)
Within goAdvertisement
you can find:
self.performSegue(withIdentifier: "mySegue", sender: itemData)
And that is where the error occurs.
libc++abi.dylib: terminating with uncaught exception of type NSException
At first I thought that it could be that it was giving time to load the view so that I could execute the performSegue
, and try to give it a delay using:
func delay(delay:Double, closure:@escaping ()->()) {
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
closure()
}
}
self.delay(delay: 4, closure: {
let homeVC : HomeViewController! = HomeViewController()
homeVC.goAdvertisement(id, hardwareAd: dataInfo)
}
But it does not work
Another idea that I had, was to leave aside the performSegue
and try to use the present
.
let vc = self.storyboard?.instantiateViewController(withIdentifier: "myVcId") as! MyController
vc.data = itemData
self.present(vc, animated: true, completion: nil)
But this did not work either (The crash points to instantiateViewController
line)
Any help will be greatly appreciated, thanks.
UPDATE
Following APK APPS answer. Finally found a way.
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let homeVC: HomeViewController = storyboard.instantiateViewController(withIdentifier: "homeView") as! HomeViewController
let rootViewController = self.window!.rootViewController as! UINavigationController;
rootViewController.pushViewController(homeVC, animated: false);
Upvotes: 0
Views: 512
Reputation: 1519
From the
AppDelegate
class you can not performsegue
. So this line will never work from yourAppDelegate
class.
self.performSegue(withIdentifier: "mySegue", sender: itemData)
You Need to simple
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let scheduleController = storyboard.instantiateViewController(withIdentifier: "yourIdentiFier")
self.window!.rootViewController = scheduleController
self.window!.makeKeyAndVisible()
You can provide Identifier to you controller from your Main.storyboard
Follow these steps.
Show the Identical Inspector
Upvotes: 1