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
382 stars 130 forks source link

Successfully patched Failure to build "no visible @interface for 'GADRequestConfiguration' declares the selector 'tagForChildDirectedTreatment:'" #359

Open tslater opened 4 months ago

tslater commented 4 months ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-native-admob-native-ads@0.6.6 for the project I'm working on.

I was having build errors:

❌  (../node_modules/react-native-admob-native-ads/ios/RNAdMobManager/RNAdmobNativeAdsManager.m:70:63)

  68 |     if ([[config allKeys] containsObject:@"tagForChildDirectedTreatment"]) {
  69 |         NSNumber *tag = [config valueForKey:@"tagForChildDirectedTreatment"];
> 70 |         [[[GADMobileAds sharedInstance] requestConfiguration] tagForChildDirectedTreatment:tag.boolValue];
     |                                                               ^ no visible @interface for 'GADRequestConfiguration' declares the selector 'tagForChildDirectedTreatment:'
  71 |     };
  72 | 
  73 |     if ([[config allKeys] containsObject:@"tagForUnderAgeConsent"]) {

❌  (../node_modules/react-native-admob-native-ads/ios/RNAdMobManager/RNAdmobNativeAdsManager.m:75:63)

  73 |     if ([[config allKeys] containsObject:@"tagForUnderAgeConsent"]) {
  74 |         NSNumber *tagC = [config valueForKey:@"tagForUnderAgeConsent"];
> 75 |         [[[GADMobileAds sharedInstance] requestConfiguration] tagForUnderAgeOfConsent:tagC.boolValue];
     |                                                               ^ no visible @interface for 'GADRequestConfiguration' declares the selector 'tagForUnderAgeOfConsent:'
  76 |     };
  77 | 
  78 |     if ([[config allKeys] containsObject:@"testDeviceIds"]) {
› Compiling react-native-admob-native-ads Pods/react-native-admob-native-ads » 

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-admob-native-ads/react-native-admob-native-ads.podspec b/node_modules/react-native-admob-native-ads/react-native-admob-native-ads.podspec
index 975b6d9..1d9ded1 100755
--- a/node_modules/react-native-admob-native-ads/react-native-admob-native-ads.podspec
+++ b/node_modules/react-native-admob-native-ads/react-native-admob-native-ads.podspec
@@ -27,5 +27,5 @@ Pod::Spec.new do |s|
   }

   s.dependency 'React-Core'
-  s.dependency 'Google-Mobile-Ads-SDK'
+  s.dependency 'Google-Mobile-Ads-SDK', '10.14.0'
 end
tcaish commented 3 months ago

Having this same problem on an expo-managed project. Would love to see this fixed.

MamoshiSE commented 3 months ago

Having the same issue, tried patching the package exactly like you do but I keep getting the error: "CocoaPods could not find compatible versions for pod "Google-Mobile-Ads-SDK".

RNGoogleMobileads depends on Google-Mobile-Ads-SDK (11.0.1) how did you get around that? If I set the sdk to 11.0.1 from 10.14.0 then the initial error starts showing again.

Sun-Woo-Kim commented 2 months ago

@tslater @tcaish @MamoshiSE Hi, I fixed issue. Try this and please review it.

https://github.com/ammarahm-ed/react-native-admob-native-ads/pull/363

zoobibackups commented 1 week ago

still have same issue when use with react-native-google-moblie-ads

bthurlow commented 5 days ago

@zoobibackups

Support for Google-Mobile-Ads-SDK v11 RNAdmobNativeAdsManager.m

#import "RNAdmobNativeAdsManager.h"
#import "RNNativeAdMobUtils.h"
#import "CacheManager.h"

@import GoogleMobileAds;

#ifdef MEDIATION_FACEBOOK
@import FBAudienceNetwork;
#endif

@implementation RNAdmobNativeAdsManager

RCT_EXPORT_MODULE();

RCT_EXPORT_METHOD(isTestDevice:resolver:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject){

}

RCT_EXPORT_METHOD(registerRepository:(NSDictionary *)config resolver:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject){

    NSDictionary *result = [CacheManager.sharedInstance registerRepo:config];
    BOOL isSuccess = ((NSNumber *)[result objectForKey:@"success"]).boolValue;
    if (isSuccess){
        NSString* repo = [result objectForKey:@"repo"];
        [CacheManager.sharedInstance requestAds:repo];
    }
    resolve(result);
}

RCT_EXPORT_METHOD(hasAd:(NSString *)repo resolver:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject){

    resolve([CacheManager.sharedInstance hasAd:repo]);
}

RCT_EXPORT_METHOD(unRegisterRepository:(NSString *) id resolver:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject){
    [CacheManager.sharedInstance unRegisterRepo:id];
}

RCT_EXPORT_METHOD(resetCache:resolver:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject){
    [CacheManager.sharedInstance resetCache];
}

RCT_EXPORT_METHOD(setRequestConfiguration:(NSDictionary *)config resolver:(RCTPromiseResolveBlock)resolve
    rejecter:(RCTPromiseRejectBlock)reject)
{
    if ([[config allKeys] containsObject:@"maxAdContentRating"]) {
        NSString *rating = [config valueForKey:@"maxAdContentRating"];
        if ([rating isEqualToString:@"G"]) {
            [[[GADMobileAds sharedInstance] requestConfiguration] setMaxAdContentRating:GADMaxAdContentRatingGeneral];
        } else  if ([rating isEqualToString:@"PG"]) {
            [[[GADMobileAds sharedInstance] requestConfiguration] setMaxAdContentRating:GADMaxAdContentRatingParentalGuidance];
        } else  if ([rating isEqualToString:@"MA"]) {
            [[[GADMobileAds sharedInstance] requestConfiguration] setMaxAdContentRating:GADMaxAdContentRatingMatureAudience];
        } else  if ([rating isEqualToString:@"T"]) {
            [[[GADMobileAds sharedInstance] requestConfiguration] setMaxAdContentRating:GADMaxAdContentRatingTeen];
        } else if ([rating isEqualToString:@""] || [rating isEqualToString:@"UNSPECIFIED"]) {
            [[[GADMobileAds sharedInstance] requestConfiguration] setMaxAdContentRating:NULL];
        }
    };

    if ([[config allKeys] containsObject:@"tagForChildDirectedTreatment"]) {
        NSNumber *tag = [config valueForKey:@"tagForChildDirectedTreatment"];
        if(tag.boolValue){
            [[[GADMobileAds sharedInstance] requestConfiguration] tagForChildDirectedTreatment];
        }
    };

    if ([[config allKeys] containsObject:@"tagForUnderAgeConsent"]) {
        NSNumber *tagC = [config valueForKey:@"tagForUnderAgeConsent"];
        if(tagC.boolValue){
            [[[GADMobileAds sharedInstance] requestConfiguration] tagForUnderAgeOfConsent];
        }
    };

    if ([[config allKeys] containsObject:@"testDeviceIds"]) {
//        NSArray *testDevices = RNAdMobProcessTestDevices([config valueForKey:@"testDeviceIds"],GADSimulatorID);
        NSArray *testDevices = [config valueForKey:@"testDeviceIds"];
        [[[GADMobileAds sharedInstance] requestConfiguration] setTestDeviceIdentifiers:testDevices];
    };

    if ([[config allKeys] containsObject:@"trackingAuthorized"]) {
        #ifdef MEDIATION_FACEBOOK
        NSNumber *trackingAuthorized = [config valueForKey:@"trackingAuthorized"];
        [FBAdSettings setAdvertiserTrackingEnabled:trackingAuthorized];
        #endif
    };

    GADMobileAds *ads = [GADMobileAds sharedInstance];
    [ads startWithCompletionHandler:^(GADInitializationStatus *status) {
        NSDictionary *adapterStatuses = [status adapterStatusesByClassName];
        NSMutableArray *adapters = [NSMutableArray array];
        for (NSString *adapter in adapterStatuses) {
            GADAdapterStatus *adapterStatus = adapterStatuses[adapter];
            NSDictionary *dict = @{
                @"name":adapter,
                @"state":@(adapterStatus.state),
                @"description":adapterStatus.description
            };
            [adapters addObject:dict];
        }
        resolve(adapters);
    }];
}

RCT_EXPORT_METHOD(isTestDevice:(RCTPromiseResolveBlock)resolve
                  rejecter:(RCTPromiseRejectBlock)reject) {
    resolve(@TRUE);
}

@end