2017-07-26 2 views
0

Je suis en train de mettre en œuvre les notifications interactives d'Urban Airship, conformément au docs de l'UA. J'ai réussi l'enregistrement catégorie et actions, comme ci-dessous:Objective-C: Action des boutons de la messagerie intégrée à l'application

// Define category options foreground and none 
UANotificationActionOptions optionsActions = (UANotificationActionOptionForeground); 
UANotificationActionOptions optionsNone = (UANotificationActionOptionNone); 
UANotificationCategoryOptions optionCategory = (UANotificationCategoryOptionCustomDismissAction); 

// Define cancel action for all categories 
UANotificationAction *actionCancel = [UANotificationAction actionWithIdentifier: @"action_cancel" 
                      title: @"Cancel" 
                     options: optionsNone]; 

// Define post action for the post category 
UANotificationAction *actionPost = [UANotificationAction actionWithIdentifier: @"action_post" 
                     title: @"Post" 
                     options: optionsActions]; 

// Actions of post category 
NSArray<UANotificationAction *> *actionsPost = @[actionPost, actionCancel]; 

// Define the post category 
UANotificationCategory *post = [UANotificationCategory categoryWithIdentifier: @"post_cancel" 
                     actions: actionsPost 
                  intentIdentifiers: @[] 
                     options: optionCategory]; 

// Set the custom categories 
[UAirship push].customCategories = [NSSet setWithArray:@[post]]; 

Maintenant, je suis en train de construire une messagerie In-App avec ces boutons (post & cancel) et mes boutons apparaissent déjà quand je mis buttonGroup du message. Malheureusement, je ne pouvais pas comprendre comment je peux lier des actions personnalisées pour chaque bouton, je ne sais pas quel dictionnaire je devrais passer dans buttonActions du message.

UAInAppMessage *message = [UAInAppMessage new]; 
message.displayType = UAInAppMessageDisplayTypeBanner; 
message.position = UAInAppMessagePositionTop; 

message.duration = 5.0; 

message.alert = @"My alert" 
message.primaryColor = [UIColor whiteColor]; 
message.secondaryColor = [UIColor blackColor]; 

UAInAppMessaging *inAppMessaging = [UAInAppMessaging new]; 

[message setButtonGroup: @"post_cancel"]; // this line ensure that my in-app messaging add my two registered buttons 
[message setButtonActions: /* WHICH DICTIONARY SHOULD I PASS? */ ]; 

dispatch_async(dispatch_get_main_queue(), ^{ 
    [inAppMessaging displayMessage: message]; 
}); 

Merci.

Répondre

1

Il attend un dictionnaire d'ID de bouton pour une carte de noms d'actions à des valeurs. Exemple:

@{ 
    @"action_cancel": 
     @{ 
      @"my_custom_action_name": @"custom action value", 
      @"another_action_name": @(YES) 
     }, 

    @"action_post": 
     @{ 
      @"some_other_action_name": @"some other action value" 
     } 
} 

Cela se déroulera my_custom_action_name et another_action_name lorsque le bouton en application action_cancel est exploité.

+0

Nice! Cela a fonctionné, merci! –