l'application iOS notifications lorsqu'une application est ouverte (comme whatsapp)

Im en train de recevoir les notifications avec un JSON et un message, donc ce que je voulais, c'était de la poignée de la notification et de l'afficher à l'utilisateur.

Lorsque l'application n'est pas en cours d'exécution ou en arrière-plan, le message s'affiche, mais lorsque l'application est ouverte il n'y a pas de notification. En fait, je reçois le json lorsque dans didReceiveRemoteNotification, mais ce que je veux, c'est une boîte de notification comme whatsapp ne.

Comme ceci:

l'application iOS notifications lorsqu'une application est ouverte (comme whatsapp)

J'ai ceci:

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
    print("Notification received: \(userInfo)")
    let notification = userInfo["aps"] as? NSDictionary
    let message = notification?.valueForKey("alert")
}

Et ce dans didfinishlaunchWithOptions

let readAction = UIMutableUserNotificationAction()
        readAction.identifier = "READ_IDENTIFIER"
        readAction.title = "Read"
        readAction.activationMode = UIUserNotificationActivationMode.Foreground
        readAction.destructive = false
        readAction.authenticationRequired = true

        let deleteAction = UIMutableUserNotificationAction()
        deleteAction.identifier = "DELETE_IDENTIFIER"
        deleteAction.title = "Delete"
        deleteAction.activationMode = UIUserNotificationActivationMode.Foreground
        deleteAction.destructive = true
        deleteAction.authenticationRequired = true

        let ignoreAction = UIMutableUserNotificationAction()
        ignoreAction.identifier = "IGNORE_IDENTIFIER"
        ignoreAction.title = "Ignore"
        ignoreAction.activationMode = UIUserNotificationActivationMode.Foreground
        ignoreAction.destructive = false
        ignoreAction.authenticationRequired = false

        let messageCategory = UIMutableUserNotificationCategory()
        messageCategory.identifier = "MESSAGE_CATEGORY"
        messageCategory.setActions([readAction, deleteAction], forContext: UIUserNotificationActionContext.Minimal)
        messageCategory.setActions([readAction, deleteAction, ignoreAction], forContext: UIUserNotificationActionContext.Default)

        let types: UIUserNotificationType = [UIUserNotificationType.Badge, UIUserNotificationType.Sound, UIUserNotificationType.Alert]

        application.registerUserNotificationSettings(
            UIUserNotificationSettings(
                forTypes: types,
                categories: (NSSet(array: [messageCategory])) as? Set<UIUserNotificationCategory>))

        UIApplication.sharedApplication().registerForRemoteNotifications()

        let notTypes:UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
        let noteSettings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: notTypes, categories: nil)

        UIApplication.sharedApplication().registerUserNotificationSettings(noteSettings)

Espère que quelqu'un pouvait l'aider. Merci pour tous

Essayez de reformuler votre question, "j'ai une chaîne et je veux le mettre dans un label".

OriginalL'auteur Norolim | 2015-09-30