“函数调用”自定义变量,可以调用应用中的某个类方法,传入对应参数键的值。比如某商城App,在点击购买某商品的事件中只设置了商品名称的信息。现在希望点击购买时,上报商品库存的信息,那么可以用如下方式实现。
RoomTypeVariable.h
#import <DTMSDK/DTMSDK.h>
NS_ASSUME_NONNULL_BEGIN
@interface RoomTypeVariable : CustomVariable
@end
RoomTypeVariable.m
#import "RoomTypeVariable.h"
@implementation RoomTypeVariable
- (NSString *)getValue:(NSDictionary<NSString *,NSObject *> *)params {
NSString *value = @"";
if (params == nil) {
NSLog(@"RoomTypeVariable execute: param null");
} else {
if ([params.allKeys containsObject:key]) {
NSObject *obj = params[@"goodname"];
value = [obj isKindOfClass:[NSString class]] ? (NSString *) obj : @"UNKNOWN";
}
}
return value;
}
@end 
