1

我使用类来显示 AdMob 广告,它有 320x50 大小的视图,我只调用这个类的视图,我想在应用程序中显示我的广告,但是当我点击广告并想要返回时,它会返回到 AdMob 的类并调整为覆盖所有屏幕(自动调整大小已关闭)。有人对此有解决方案吗?由于我的其他 m 个文件是 mm,因此我使用这个具有小视图的 AdMob 类。文件,我无法让 AdMob 在 mm 文件中工作,而且当我需要显示广告时,它也很容易调用这个类的视图。我使用与官方网站中 AdMob 示例中相同的代码。

-(void)setAdMob{

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 = kSampleAdUnitID;
self.adBanner.delegate = self;
[self.adBanner setRootViewController:self];
[self.view addSubview:self.adBanner];
self.adBanner.center =
CGPointMake(self.view.center.x, self.adBanner.center.y);
self.adBanner.frame=CGRectMake(0, 0, self.adBanner.frame.size.width, self.adBanner.frame.size.height);
[self.adBanner loadRequest:[self createRequest]];
}

-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;

}

-(GADRequest *)createRequest {
GADRequest *request = [GADRequest request];

request.testDevices =
[NSArray arrayWithObjects:
 GAD_SIMULATOR_ID,
 // TODO: Add your device/simulator test identifiers here. They are
 // printed to the console when the app is launched.
 nil];

return request;

}

// 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]);}
4

0 回答 0