To get test ads on this device, call: request.testDevices = [NSArray arrayWithObjects:GAD_SIMULATOR_ID, nil];

前端 未结 6 1251
走了就别回头了
走了就别回头了 2021-02-07 13:16

While i test Admob in simulator, it throws below error

To get test ads on this device, call: request.testDevices = [NSArray arrayWithObjects:GAD_SIMULATO

相关标签:
6条回答
  • 2021-02-07 13:57

    This works for me:

    (GADRequest *)request {
      GADRequest *request = [GADRequest request];
      // Make the request for a test ad. Put in an identifier for the simulator as well as any devices
      // you want to receive test ads.
      request.testDevices = @[
        // TODO: Add your device/simulator test identifiers here. Your device identifier is printed to
        // the console when the app is launched.
        GAD_SIMULATOR_ID
      ];
      return request;//thanks
    }  
    
    0 讨论(0)
  • 2021-02-07 13:57

    I am currently using this. Works for me even in the simulator. I got the error, but it isn't an error, I searched extensively and found out that it is more of an informative message.

    The main point will be to get the real ad showing when the testing mode is set to NO, and a "Success, you are now ready to travel the ad galaxy" message when the testing mode is set to YES. Therefore, if you have either of the results in the app, it should be fine. :)

    My code is as follows:

    GADBannerView *bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
    
    bannerView_.adUnitID = GOOGLE_UNIT_ID;
    
    GADRequest *request = [GADRequest request];
    
    bannerView_.delegate = self;
    
    bannerView_.rootViewController = self;
    
    // Make the request for a test ad. Put in an identifier for
    // the simulator as well as any devices you want to receive test ads.
    request.testDevices = [NSArray arrayWithObjects:
                           GAD_SIMULATOR_ID,
                           nil];
    
    // Initiate a generic request to load it with an ad.
    [bannerView_ loadRequest:request];
    

    I did not set the testing as YES. My Google AdMobs SDK version is 6.5.1

    Since you were mentioning that you need help for production, it should not be set to testing mode anyway, so you should probably run it without test mode.

    Looking at the question of whether running on simulator or real device does not matter, it should run on both the devices. I set the delegate to self in my codes, and therefore if you do the same, you can use the methods:

    - (void) adView: (GADBannerView*) view didFailToReceiveAdWithError: (GADRequestError*) error
    - (void) adViewDidReceiveAd: (GADBannerView*) view
    

    These can help you in checking if you have received the ads at all, even when running in simulator.

    Hope this helps! :)

    0 讨论(0)
  • 2021-02-07 14:01

    Since the newest update the request.testDevices has been replaced with:

    GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers
    

    I have gotten it to work with this:

    GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers = [(kGADSimulatorID as! String)]
    

    [EDIT]

    In my app delegate I am using this code:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
            
        // use this for production 
        GADMobileAds.sharedInstance().start(completionHandler: nil)
        // use this for testing 
        GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = [ kGADSimulatorID ]
            
        return true
    }
    

    This is for Swift 5, iOS 13 and Google-Mobile-Ads-SDK (7.58.0)

    0 讨论(0)
  • 2021-02-07 14:02

    You have to add your test devices. With Swift, just replace

    bannerView.load(GADRequest())
    

    with

    let request: GADRequest = GADRequest()
    request.testDevices = [kGADSimulatorID]
    bannerView.load(request)
    

    If you have an iPhone, then run the application too and it will tell you the ID.

    To get test ads on this device, call: request.testDevices = @[@"HERE IS THE ID"];

    ID added:

    let request: GADRequest = GADRequest()
    request.testDevices = ["PUT HERE THE ID", kGADSimulatorID]
    bannerView.load(request)
    
    0 讨论(0)
  • 2021-02-07 14:02

    I used to do this:

    GADRequest *request = [GADRequest request];
    
    // Make the request for a test ad. Put in an identifier for
    // the simulator as well as any devices you want to receive test ads.
    request.testDevices = [NSArray arrayWithObjects:GAD_SIMULATOR_ID, nil];
    [gAdBannerView loadRequest:request];
    

    where I define

    // Constant for getting test ads on the simulator using the testDevices method.
    #define GAD_SIMULATOR_ID @"Simulator"
    
    0 讨论(0)
  • 2021-02-07 14:07

    At finally fix the bug friends..

    I made mistake to generate adUnitID. So only i cannot get ad view.

    Now get one adUnitID from xxxx site for testing. And its working fine..

    adUnitID = @"a14dccd0fb24d45";
    

    Thanks for All Supporters.

    0 讨论(0)
提交回复
热议问题