2017-07-26 61 views
0

我正在按照UA的docs執行Urban Airship的交互式通知。我已經成功註冊的類別和行動,像波紋管:Objective-C:應用內消息傳遞按鈕的動作

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

現在,我想建立一個應用程式消息與那些按鈕(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]; 
}); 

謝謝。

回答

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

+0

不錯!它的工作,謝謝你! –