Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios GoogleMobileAds sdk的奇怪行为_Ios_Swift_Admob - Fatal编程技术网

Ios GoogleMobileAds sdk的奇怪行为

Ios GoogleMobileAds sdk的奇怪行为,ios,swift,admob,Ios,Swift,Admob,当我将此方法放入应用程序(application:UIApplication, 使用选项完成启动 GADMobileAds.configure(使用applicationid:“MYAPPID”) 我的广告果然出现了 但是,只要我将GADMobileAds.configure(withApplicationID:“MYAPPID”)移动到库框架内的一个helper方法,并调用该helper方法,广告就不会显示出来。而且控制台中没有日志显示出问题所在 有人知道为什么会这样吗?Swift 3.0 在

当我将此方法放入
应用程序(application:UIApplication,
使用选项完成启动

GADMobileAds.configure(使用applicationid:“MYAPPID”)

我的广告果然出现了

但是,只要我将
GADMobileAds.configure(withApplicationID:“MYAPPID”)
移动到库框架内的一个helper方法,并调用该helper方法,广告就不会显示出来。而且控制台中没有日志显示出问题所在


有人知道为什么会这样吗?

Swift 3.0

在中使用此选项

class ViewController: UIViewController , GADBannerViewDelegate{

     // put this line in viewdidload()
     let bannerview1 : GADBannerView = GADBannerView(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 50))
     bannerview1.adUnitID = "ca-app-pub-3940256099942544/2934735716"
     bannerview1.rootViewController = self
     bannerview1.delegate = self
     bannerview1.load(GADRequest())
     self.view.addSubview(bannerview1)

 // Delegates for adv error

    func adView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: GADRequestError) {
        print(error)
    }

}
一部分来自:

初始化谷歌移动广告SDK

在应用程序启动时,通过调用 中的configureWithApplicationID: 应用程序:didFinishLaunchingWithOptions:AppDelegate.m的方法或 AppDelegate.swift.Objective CSwift AppDelegate.m

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  // Use Firebase library to configure APIs
  [FIRApp configure];
  [GADMobileAds configureWithApplicationID:@"ca-app-pub-3940256099942544~1458002511"];
  return YES;
}
在应用程序启动时初始化Google Mobile Ads SDK允许SDK 尽早获取应用程序级别设置并执行配置任务 可能。这有助于减少初始ad请求的延迟。 初始化需要应用ID。应用ID是唯一标识符 当移动应用程序在AdMob控制台中注册时提供

所以,IMHO,您必须在应用程序启动时调用此配置函数


希望有帮助!

-(void)adView:(GADBannerView*)bannerView未能接收到WithError:(GADRequestError*)错误;使用此委托方法获取ADS错误错误为“无需加载ad”。但是调用
GADMobileAds.configure时没有错误(使用ApplicationID:“MYAPPID”)
直接在my App Delegate中。使用捆绑标识检查您的广告id他们是否正确您使用哪种广告,如bannner adv、GADInterstitial等?