Tom Calmon Tom Calmon - 2 years ago 114
Objective-C Question

Objective-C: In-App Messaging buttons' action

I'm implementing Urban Airship's Interactive Notifications, following UA's docs. I have succeeded registering category and actions, like bellow:

// 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]];

Now, I'm trying build an In-App Messaging with those buttons (post & cancel) and my buttons are already appearing when I set message's buttonGroup. Unfortunately, I've could not figure out how can I link custom actions for each button, I don't know which dictionary I should pass in message's buttonActions.

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];

Thank you.

Answer Source

It expects a dictionary of button IDs to a map of action names to values. Example:

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

           @"some_other_action_name": @"some other action value"

That will run my_custom_action_name and another_action_name when the in-app action_cancel button is tapped.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download