【问题标题】:How to show GADAppOpenAd ( GoogleMobileAds App Open Ad ) in landscape mode?如何以横向模式显示 GADAppOpenAd(GoogleMobileAds 应用打开广告)?
【发布时间】:2021-02-15 06:49:10
【问题描述】:

我使用此代码在横向游戏中显示 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];
        }
    }
}

【问题讨论】:

    标签: ios iphone xcode admob googlemobileads


    【解决方案1】:

    这是横向模式的 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 中按标签退出和按标签进入。

    Fish World 3D - https://apps.apple.com/us/app/fish-world-game-sea-war-2021/id1548277003

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多