我在iOS应用中使用了adMob。但是,当我测试应用程序时,它会在模拟器中显示测试广告,但是当我尝试在我的设备上播放广告时(它不是开发者设备),那么我就不会收到任何广告。当我使用我的开发者设备时,我得到了#34;没有要显示的广告"。我已经设置了adMob使用的密钥。
这是我的代码:
-(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self datoUgeNummer];
// Initialize the banner at the bottom of the screen.
CGPoint origin = CGPointMake(0.0,
self.view.frame.size.height -
CGSizeFromGADAdSize(kGADAdSizeBanner).height);
// Use predefined GADAdSize constants to define the GADBannerView.
self.adBanner = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner origin:origin];
// Note: Edit SampleConstants.h to provide a definition for kSampleAdUnitID before compiling.
self.adBanner.adUnitID = @"ca-app-pub-4641309369865580/3940179951";
self.adBanner.delegate = self;
self.adBanner.rootViewController = self;
[self.view addSubview:self.adBanner];
[self.adBanner loadRequest:[self request]];
}
-(void)dealloc {
_adBanner.delegate = nil;
}
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
#pragma mark GADRequest generation
-(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;
}
#pragma mark GADBannerViewDelegate implementation
// We've received an ad successfully.
-(void)adViewDidReceiveAd:(GADBannerView *)adView {
NSLog(@"Received ad successfully");
}
- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error {
NSLog(@"Failed to receive ad with error: %@", [error localizedFailureReason]);
}
我是否还需要Google Analytics才能让adMob正常运作?
我希望你能理解我的英语,并能帮助我! :)