Burrito411
Burrito411

Reputation: 431

admob iOS: To get test ads on this device, call: request.testDevices = @[ GAD_SIMULATOR_ID ];

This is an interesting error. What should I put in the GAD_SIMULATOR_ID slot? What does that mean exactly? Here's my code, directly from Google's Admob tutorial:

bannerView = [[GADBannerView alloc] initWithFrame:CGRectMake(self.view.frame.size.height, 0.0, GAD_SIZE_320x50.width, GAD_SIZE_320x50.height)];
bannerView.adUnitID = @"my adunitid";
bannerView.rootViewController = self;
[self.view addSubview:bannerView];
GADRequest *request = [GADRequest request];
request.testDevices = @[ GAD_SIMULATOR_ID ];
NSLog(@"%@", GAD_SIMULATOR_ID); //This returns "Simulator" if you were wondering
[bannerView loadRequest:request];

Upvotes: 1

Views: 12823

Answers (5)

Henry95
Henry95

Reputation: 623

The documentation from AdMob is unclear on this, but here's the deal. First, understand that the main purpose of setting the testDevices property (type NSArray) is to avoid claiming impressions/clicks that happen when you're developing your app on test devices, which theoretically violates your agreement... although I don't think Google is going to sick their lawyers on you over a few test runs. It also ensures your app gets a fill when you send the request.

If you don't set test devices, AdMob ads will still work on simulator and anywhere else... they'll just be real ads instead of test ones. So if your AdMob implementation isn't working, don't get distracted by this; it's not the problem. You can easily verify that leaving 'testDevices' set in a shipping app won't interfere with normal ads being served.

To declare the simulator a test device, you don't substitute anything for "GAD_SIMULATOR_ID"; just set GAD_SIMULATOR_ID as an object in the array that you set as request.testDevices. Other objects are going to be strings from your actual test devices that will log in the console. If you have multiple view controllers showing ads, it would make sense to have a public method in your app delegate or an ad helper object that returns the testDevices array to any ad presenter that needs it. That would look something like this:

- (NSArray *)testDevices
{
    NSString *test_iPhone = @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    NSString *test_iPad = @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    NSArray *testDevices = [NSArray arrayWithObjects:GAD_SIMULATOR_ID, test_iPhone, test_iPad,  nil];
    return testDevices;
}

Upvotes: 2

sehaswaran
sehaswaran

Reputation: 151

I think, you haven't created a AdMob user and a Monetize app and got the publisher id to be replaced in kSampleAdUnitID in SampleConstants.h If you are using AdMob samples.

First create a AdMob user in http://www.google.com/ads/admob/

Once you login , Go to "Monetize" tab and click "Monetize New App".

Once you created, copy the Ad unit ID and paste in your project.

You should set this ad unit ID from your account before compiling.

For new AdMob, this is ca-app-pub-XXXXXXXXXXXXXXXX/NNNNNNNNNN

Upvotes: 1

user3048652
user3048652

Reputation:

For future Reference Boris's answer is correct. request.testDevices = @[ GAD_SIMULATOR_ID ]; And this will spit out test banners, but it only seem to do so on the ios emulator, and not if you are testing it on a real iphone/ipad

Upvotes: 0

jeet.chanchawat
jeet.chanchawat

Reputation: 2585

This is tested and working.

GADRequest *request = [GADRequest request];    
request.testDevices = [NSArray arrayWithObjects:GAD_SIMULATOR_ID,@"TheIDAppearingInLogs",nil];       
[adMobAd loadRequest:request];

Upvotes: 1

baris
baris

Reputation: 304

I don't think it's an error message. It just tells you to add the line 'request.testDevices = @[ GAD_SIMULATOR_ID ];', even though you already have (I get the same console output, but test ads show on the simulator as they should)

Upvotes: 1

Related Questions