ios 要在此设备上获取测试广告,请调用: request.testDevices = [NSArray arrayWithObjects:GAD_SIMULATOR_ID, nil];

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19527478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 02:30:45  来源:igfitidea点击:

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

iosobjective-cadmob

提问by Balaji G

While i test Admob in simulator, it throws below error

当我在模拟器中测试 Admob 时,它抛出以下错误

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

要在此设备上获取测试广告,请调用: request.testDevices = [NSArray arrayWithObjects:GAD_SIMULATOR_ID, nil];

My Code

我的代码

bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
bannerView_.adUnitID = @"8de66ecc3525495d";

bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];

GADRequest *request = [[GADRequest alloc] init];
request.testing = YES;
[bannerView_ loadRequest:request];

Guide me to archive it. Thanks in Advance..

指导我存档。提前致谢..

采纳答案by Balaji G

At finally fix the bug friends..

终于修复bug啦。。

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

我错误地生成了adUnitID。所以只有我无法获得广告视图。

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

现在从 xxxx 站点获取一个adUnitID进行测试。它的工作正常..

adUnitID = @"a14dccd0fb24d45";

Thanks for All Supporters.

感谢所有支持者。

回答by Paul Spiesberger

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

您必须添加测试设备。使用 Swift,只需替换

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.

如果您有 iPhone,也可以运行该应用程序,它会告诉您 ID。

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

要在此设备上获取测试广告,请致电: request.testDevices = @[@"HERE IS THE ID"];

ID added:

身添加:

let request: GADRequest = GADRequest()
request.testDevices = ["PUT HERE THE ID", kGADSimulatorID]
bannerView.load(request)

回答by Ashok Kumar

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
}  

回答by Tad Scritchfield

Since the newest update the request.testDeviceshas been replaced with:

自最新更新request.testDevices以来,已替换为:

GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers

I have gotten it to work with this:

我已经得到它的工作:

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

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

这适用于 Swift 5、iOS 13 和 Google-Mobile-Ads-SDK (7.58.0)

回答by Mick

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"

回答by faterpig

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. :)

重点是在测试模式设置为 NO 时显示真实广告,并在测试模式设置为 YES 时显示“成功,您现在准备好穿越广告星系”消息。因此,如果您在应用程序中有任何一个结果,应该没问题。:)

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

我没有将测试设置为 YES。我的 Google AdMobs SDK 版本是 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:

看看是在模拟器上运行还是在真实设备上运行的问题并不重要,它应该在两个设备上运行。我在我的代码中将委托设置为 self ,因此如果您这样做,您可以使用以下方法:

- (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! :)

希望这可以帮助!:)