/ / Popover öffnen, wenn die Anwendung von der Benachrichtigungsstelle nach dem Beenden der Anwendung gestartet wird - swift, uiviewcontroller, appdelegate

Popover öffnen, wenn die Anwendung nach dem Beenden der Anwendung vom Benachrichtigungstext gestartet wird - swift, uiviewcontroller, appdelegate

Ich versuche, Popover zu öffnen, wenn die Anwendung von der Benachrichtigungsstelle aus gestartet wird, nachdem die App beendet wurde. Ich binde daran, es zu tun AppDelegate. ich benutze LocalNotifications. Ich weiß, wie ich eine bestimmte Ansicht öffne, wenn ich Aktionsschaltflächen verwende, aber nicht, wie ich etwas öffne, wenn auf eine Benachrichtigungsstelle geklickt wird.

Bearbeiten: Meine Lösung funktioniert nur, wenn die App nicht beendet wird.

Edit2: Ist es der richtige Weg, dies zu tun ?:

Der Einfachheit halber versuche ich zu öffnen viewController im code brauche ich aber eigentlich warnmeldung, dafür verwende ich JSSAlertView

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.



if let TappedNotification = launchOptions?[UIApplicationLaunchOptionsLocalNotificationKey] as? NSDictionary {

print("The notification is (TappedNotification)")
let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewControlleripad : UIViewController = mainStoryboardIpad.instantiateViewControllerWithIdentifier("Main") as UIViewController
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.rootViewController = initialViewControlleripad
self.window?.makeKeyAndVisible()

}
}





return true

}

Ich habe dies versucht, um festzustellen, in welchem ​​Status sich die App befindet. Ich kann sie jedoch nicht testen, wenn die App beendet und über die Benachrichtigung geöffnet wird:

if application.applicationState == UIApplicationState.Active {
print("App already open")

} else {
print("App opened from Notification")
}

Ich habe versucht, dies hinzuzufügen else{ aber es öffnet keine bestimmte Ansicht:

let mainStoryboardIpad: UIStoryboard = UIStoryboard (Name: "Main", Bundle: nil)

 let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewControlleripad : UIViewController = mainStoryboardIpad.instantiateViewControllerWithIdentifier("Main") as UIViewController
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.rootViewController = initialViewControlleripad
self.window?.makeKeyAndVisible()

Ich möchte den gleichen Effekt wie Twitter oder Instagram, wenn die Benachrichtigungsstelle angeklickt wird und Sie zum Posten weiterleitet. Aber in meinem Fall möchte ich nur Popover (modal).

Antworten:

1 für die Antwort № 1

Wenn Ihre App beendet wird und Sie die Benachrichtigung erhalten und auf Benachrichtigung tippen, erhalten Sie diese Information, indem Sie dem Code folgen und den Code eingeben müssen didFinishLaunchingWithOptions Methode:

    if let TappedNotification = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary {

print("The notification is (TappedNotification)")
let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewControlleripad : UIViewController = mainStoryboardIpad.instantiateViewControllerWithIdentifier("Main") as UIViewController
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.rootViewController = initialViewControlleripad
self.window?.makeKeyAndVisible()

}

Wenn sich Ihre App nicht im Hintergrund befindet oder aktiv istIn diesem Modus legen Sie einen bestimmten Rootview-Controller für die Benachrichtigung fest. und zurück müssen Sie Ihren rootviewcontroller basierend auf Ihrem Anwendungsfluss ändern, sobald Sie von der Benachrichtigung View Controller zurück sind.

Nach Überprüfung Ihres Beispielcodes behebe ich mit folgenden Änderungen:

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
let tintColor = UIColor(red: 252/255, green: 72/255, blue: 49/255, alpha: 1)
window!.tintColor = tintColor

application.registerForRemoteNotifications()
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Alert , categories: nil))


let notification = launchOptions?[UIApplicationLaunchOptionsLocalNotificationKey] as! UILocalNotification!
if (notification != nil) {
print("The notification is (notification)")

let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewControlleripad : UIViewController = mainStoryboardIpad.instantiateViewControllerWithIdentifier("Main") as! NotificationViewController

self.window?.rootViewController = initialViewControlleripad
self.window?.makeKeyAndVisible()


let alert = UIAlertController(title: "Alert", message: "YES NOTIFICITO", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))
window!.rootViewController?.presentViewController(alert, animated: true, completion: nil)
return true


}else{

let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewControlleripad : UIViewController = mainStoryboardIpad.instantiateViewControllerWithIdentifier("first") as UIViewController
self.window?.rootViewController = initialViewControlleripad
self.window?.makeKeyAndVisible()

let alert = UIAlertController(title: "Alert", message: "NO NOTIFICIATION", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))
window!.rootViewController?.presentViewController(alert, animated: true, completion: nil)
return true
}

}