I come from Android development, where navigation within the app when a user presses a notification is very simple. From anywhere, you can easily get to the relevant data.
In iOS, it seems that this is not the case. My app has quite a few view controllers and also many areas where a UIAlertController will pop up.
I am literally tracking the state of my application through keeping references to the UIAlertControllers and variables that tell me if the UIAlertController is being displayed or not. I'm also tracking what the current ViewController that the user is viewing is. Based on this, when a user presses a notification, I go through the state and many if-statements to figure out what ViewControllers need to be dismissed, and once they're dismissed, I follow through with the notification.
In fact, I can't even navigate the user properly sometimes because my view controllers get stuck on UIActivityViewControllers for sharing which Apple has control over.
Here is an example of what I have to do when dealing with notifications:
func handleNotification() {
if oneViewController.alertDisplayed {
oneViewController.alertDisplayed = false
oneViewController.someAlert.dismissViewControllerAnimated(false, completion: {
self.oneViewController.handleNotification()
})
} else if twoViewController.anotherAlertDisplayed {
twoViewController.anotherAlertDisplayed = false
twoViewController.anotherAlert.dismissViewControllerAnimated(false, completion: {
self.oneViewController.handleNotification()
})
} else if threeViewController.evenMoreAlertDisplayed {
threeViewController.evenMoreAlertDisplayed = false
...
}
}
That process continue another 10 or so times and I really hope that isn't the way I'll have to tackle notifications.
How should I go about this?
Aucun commentaire:
Enregistrer un commentaire