ammarahm-ed / react-native-admob-native-ads

A simple and robust library for creating & displaying Admob Native Advanced Ads in your React Native App using Native Views.
https://ammarahm-ed.github.io/react-native-admob-native-ads/docs/introduction/
MIT License
409 stars 138 forks source link

Custom targeting #392

Open JoaquinManeroJazusoft opened 2 weeks ago

JoaquinManeroJazusoft commented 2 weeks ago

could it be that custom targeting doesn't work? I need to know if it is my problem or the library currently does not work with custom targeting with google ad manager

JoaquinManeroJazusoft commented 1 week ago

After reviewing the native code, I could see that the targetOptions in android worked correctly, but not in iOS. This is because in the native iOS code the order was wrong, so what works for me is the following solution.

if ([allKeys containsObject:@"targets"]) {
        NSArray *array = [targetingOptions objectForKey:@"targets"];
        NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
        for (NSDictionary *object in array) {
            [dic setValue:[object valueForKey:@"value"] forKey:[object valueForKey:@"key"]];
        }
        [adRequest setCustomTargeting:dic];
    }