2016-02-22 1 views
1

Je migre de parse.com à dirigeable urbaine, j'ai presque fini et tout fonctionne, mais une chose. Lorsque mon application est en cours d'ouverture et qu'une notification push est envoyée, la vue d'alerte NE s'affiche PAS. Si je mets l'application sur l'arrière-plan ou près l'application que je avec succèsreçoivent la notification .Urban Airship ne montre pas d'alerte dans l'application

J'ai essayer différentes choses pour le faire fonctionner, j'essayer d'ajouter:

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { 
    UAirship.push().appRegisteredForRemoteNotificationsWithDeviceToken(deviceToken) 
} 

func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) { 
    UAirship.push().appRegisteredUserNotificationSettings() 
} 

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { 
    UAirship.push().appReceivedRemoteNotification(userInfo, applicationState: application.applicationState) 
} 

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) { 
    UAirship.push().appReceivedRemoteNotification(userInfo, 
     applicationState:application.applicationState, 
     fetchCompletionHandler:completionHandler) 
} 

func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [NSObject : AnyObject], completionHandler:() -> Void) { 
    UAirship.push().appReceivedActionWithIdentifier(identifier!, 
     notification: userInfo, 
     applicationState: application.applicationState, 
     completionHandler: completionHandler) 
} 

func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [NSObject : AnyObject], withResponseInfo responseInfo: [NSObject : AnyObject], completionHandler:() -> Void) { 

    UAirship.push().appReceivedActionWithIdentifier(identifier!, 
     notification: userInfo, 
     responseInfo: responseInfo, 
     applicationState: application.applicationState, 
     completionHandler: completionHandler) 
} 

Et changer le UAConfig à automatiqueconfigurationdésactivé:

 let config: UAConfig = UAConfig.defaultConfig() 
    config.automaticSetupEnabled = false 
    UAirship.takeOff(config) 

I ont également ajouté à mon AppDelegate ceci:

class AppDelegate: UIResponder, UIApplicationDelegate, UAPushNotificationDelegate { 

Et mettrecette:

 UAirship.push().userNotificationTypes = [.Alert, .Badge, .Sound] 
    UAirship.push().pushNotificationDelegate = self 

Mais rientravaillé, je suis vraiment frustré par cela parce que je ne peux pas le faire fonctionner et moi, la documentation du Urban Airship, ce n'est pas clair à ce sujet.

Si je ne me trompe pas, cela devrait fonctionner par défaut, sans faire tout cela, mais ce n'est pas le cas.

J'espère que quelqu'un peut me aider, voici mon code complet sans toutes les modifications:

class AppDelegate: UIResponder, UIApplicationDelegate { 

var window: UIWindow? 

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


    // Populate AirshipConfig.plist with your app's info from 
    // https://go.urbanairship.com 
    // or set runtime properties here. 
    let config: UAConfig = UAConfig.defaultConfig() 
    UAirship.takeOff(config) 

    UAirship.push().userPushNotificationsEnabled = true 

    // Clear badge 
    UAirship.push().resetBadge() 

    return true 
}[...]} 

J'utilise Swift 2, XCode 7.2.1 et iOS8 et Urban Airship 6.4.x

Merci

Répondre

2

Si vous souhaitez déclencher un affichage d'alerte lorsqu'une notification de premier plan est reçue, vous devrez mettre en œuvre la UAPushNotificationDelegate et gérer l'y alerte. La présentation d'une alerte lorsqu'une notification de premier plan est reçue n'est pas un comportement par défaut dans le SDK Urban Airship.

push délégué de notification

Créer une classe qui implémente UAPushNotificationDelegate et et comprend la méthode en option receivedForegroundNotification ou la méthode displayNotificationAlert.

class PushNotificationDelegate : NSObject, UAPushNotificationDelegate { 

    func receivedForegroundNotification(notification: [NSObject : AnyObject], fetchCompletionHandler completionHandler: ((UIBackgroundFetchResult) -> Void)) { 
     // Called when the app receives a foreground notification. Includes the notification dictionary. 

     // Call the completion handler 
     completionHandler(UIBackgroundFetchResult.NoData) 
    } 

    func displayNotificationAlert(alertMessage: String) { 
     // Called when an alert notification is received in the foreground. Includes a simple string to be displayed as an alert. 
    } 


} 

Set délégué

UAirship.push().pushNotificationDelegate = customPushDelegate 

Vous pouvez consulter documentation de Urban Airship pour le délégué de notification push.

+0

Il me manque quelque chose d'autre, parce que ça ne marche toujours pas:/ – Lucas

+0

Comment configurez-vous le délégué de notification push? Il doit être réglé après 'UAirship.takeOff (config)'. – gatlinhebert

+0

C'est comme ça. Je reçois le push sur mon iPhone, mais l'alerte n'est pas affichée. Dois-je créer une alerte à l'intérieur de ces méthodes? – Lucas