【问题标题】:Objective-C: In-App Messaging buttons' actionObjective-C:应用内消息按钮的动作
【发布时间】:2017-07-26 19:29:01
【问题描述】:

我正在按照 UA 的 docs 实施 Urban Airship 的交互式通知。我已成功注册类别和操作,如下所示:

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

现在,我正在尝试使用这些按钮(发布和取消)构建应用内消息,当我设置消息的 buttonGroup 时,我的按钮已经出现。不幸的是,我无法弄清楚如何为每个按钮链接自定义操作,我不知道应该在消息的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];
});

谢谢。

【问题讨论】:

    标签: ios objective-c iphone urbanairship.com


    【解决方案1】:

    它需要一个按钮 ID 字典到动作名称到值的映射。示例:

    @{
      @"action_cancel":
           @{
               @"my_custom_action_name": @"custom action value",
               @"another_action_name": @(YES)
           },
    
       @"action_post":
           @{
               @"some_other_action_name": @"some other action value"
           }
    }
    

    当点击应用内的action_cancel 按钮时,这将运行my_custom_action_nameanother_action_name

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-10
      • 2012-05-11
      • 2012-10-21
      • 1970-01-01
      相关资源
      最近更新 更多