Das ist meine didReceiveRemoteNotification
Methode Benachrichtigungen behandeln drücken, wenn sie meinen iOS-App erhalten din:Swift: Wie Push-Benachrichtigung speichern, wenn App läuft?
func showNotificationDetails(userInfo: [NSObject : AnyObject], application:UIApplication) {
print("showNotificationDetails")
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let notificationController = storyboard.instantiateViewControllerWithIdentifier("DynamicEventsViewController") as! DynamicEventsViewController
notificationController.isLoadedFromNotification = true
notificationController.eventTitle = userInfo["aps"]!["alert"] as! String
notificationController.eventDescription = userInfo["aps"]!["message"] as! String
notificationController.isLoadedFromNotification = true
if let tabBarController = self.window?.rootViewController {
tabBarController.presentViewController(notificationController, animated: true, completion: nil)
}
application.applicationIconBadgeNumber -= 1
//application.cancelAllLocalNotifications()
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
let state:UIApplicationState = application.applicationState
if (state == UIApplicationState.Inactive || state == UIApplicationState.Background) {
self.showNotificationDetails(userInfo, application: application)
}
}
Das Problem ist, dass, wenn die Anwendung ausgeführt wird und eine Meldung eintrifft, dann wird es nicht gespeichert und es wird gelöscht damit der Benutzer es später nicht sehen kann. Wie soll ich auf die richtige Weise vorgehen, um die Benachrichtigung zu behalten, bis der Benutzer sie liest?
Sie können Alarm mit Benachrichtigung anzeigen, wenn die App im Vordergrund ist –
Es ist genau das, was ich getan hatte, aber mein Chef will nicht, dass ich das tue, weil er sagt, dass es nicht korrekt ist! – user1576208
speichern Sie nur Benachrichtigungsdaten und Sie können lokale Benachrichtigung verwenden. Wenn die App im Hintergrund läuft, prüfen Sie, ob eine gespeicherte Benachrichtigung verfügbar ist, und zeigen Sie dann eine lokale Benachrichtigung an. –