Skip to content

Adding key value pairs

Vladas Drejeris edited this page Jun 4, 2021 · 5 revisions

Adding keywords to ad views

To add key-value pairs which will be used for targeting purposes please use the example below:

Swift

 adView.keyValues = [AFKeyValue(key: "gender", value: "male"), AFKeyValue(key: "age", value: "20-30")]
Objective-C
 adView.keyValues = @[AFKeyValue(@"gender", @"male"), AFKeyValue(@"age", @"20")];

If you were previously setting a dictionary to the "keyValues" property (SDK versions older than 2.7.2), you can use a convenience function to transform dictionary to key values array automatically:

Swift

 adView.keyValues = AFKeyValuesFromNSDictionary(["gender": "male", "age": "20"])
Objective-C
 adView.keyValues = AFKeyValuesFromNSDictionary(@{@"gender": @"male", @"age": @"20"});

Important, both key and value have a 200 character limit.

Clone this wiki locally