0

我使用此代码在横向游戏中显示 GADAppOpenAd ..但广告没有横向显示。

- (void)requestAppOpenAd {
  self.appOpenAd = nil;
  [GADAppOpenAd loadWithAdUnitID:ADMOB_APP_OPEN_ID
                         request:[GADRequest request]
                     orientation:UIInterfaceOrientationPortrait
               completionHandler:^(GADAppOpenAd *_Nullable appOpenAd, NSError *_Nullable error) {
                 if (error) {
                   NSLog(@"Failed to load app open ad: %@", error);
                   return;
                 }
                 self.appOpenAd = appOpenAd;
                 self.appOpenAd.fullScreenContentDelegate = self;

               }];
}

- (void)tryToPresentAd
{
    if(g_show_ads)
    {
        if (self.appOpenAd) {
          UIViewController *rootController = self.window.rootViewController;
          [self.appOpenAd presentFromRootViewController:rootController];
        } else {
          // If you don't have an ad ready, request one.
          [self requestAppOpenAd];
        }
    }
}
4

1 回答 1

0

这是横向模式的 GADAppOpenAd 完整代码。

在 .h 文件中

@property(strong, nonatomic) GADAppOpenAd* appOpenAd;

- (void)requestAppOpenAd;
- (void)tryToPresentAd;

在 .m 文件中

- (void)requestAppOpenAd {
  self.appOpenAd = nil;
  [GADAppOpenAd loadWithAdUnitID:@"ca-app-pub-2..your_ad_unit_id"
                         request:[GADRequest request]
                     orientation:UIInterfaceOrientationLandscapeLeft
               completionHandler:^(GADAppOpenAd *_Nullable appOpenAd, NSError *_Nullable error) {
                 if (error) {
                   NSLog(@"Failed to load app open ad: %@", error);
                   return;
                 }
                 self.appOpenAd = appOpenAd;
                 self.appOpenAd.fullScreenContentDelegate = self;
               }];
}

- (void)tryToPresentAd {
  if (self.appOpenAd) {
   // UIViewController *rootController = self.window.rootViewController;
    [self.appOpenAd presentFromRootViewController:self.viewController];
  } else {
    // If you don't have an ad ready, request one.
    [self requestAppOpenAd];
  }
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    [[GADMobileAds sharedInstance] startWithCompletionHandler:nil];
    [self requestAppOpenAd];
    ..
    ..
}
- (void)applicationDidBecomeActive:(UIApplication *)application 
{ 
      [self tryToPresentAd];
}

在此处输入图像描述

这是带有 GADAppOpenAd 的现场游戏,在游戏节目 GADAppOpenAd 中使用标签和标签。

鱼世界 3D - https://apps.apple.com/us/app/fish-world-game-sea-war-2021/id1548277003

于 2021-02-15T06:53:54.373 回答