斯威夫特& Admob:没有广告可以展示

时间:2016-04-23 14:56:59

标签: ios swift admob

我正在尝试将AdMob添加到我的应用中。 我的应用程序构建: UITabBarController与1. UIViewController; 2. UITableViewController; 3. UIViewController; 4. UIViewController。

我实际上想要在3. UIViewController中添加来自Admob的横幅广告。

我使用了那段代码:

func adView(bannerView: GADBannerView!,
            didFailToReceiveAdWithError error: GADRequestError!) {
    print("adView:didFailToReceiveAdWithError: \(error.localizedDescription)")
}

它不起作用:广告未显示。 所以我使用了这个功能:

PREFIX station: https://api.data.gov/nrel/alt-fuel-stations/v1/nearest.json?api_key=???location=Denver+CO

SELECT *
WHERE
 { ?x station:network ?network like "null"
}

我得到了这个输出: adView:didFailToReceiveAdWithError:请求错误:无广告显示。

我真的认为这是由于 amobBan.rootViewController = self ,因为我在设置 3时显示了广告。 UIViewController 作为初始ViewController进入故事板。

请在Swift中找到答案。

4 个答案:

答案 0 :(得分:1)

迟到的答案,但这可能有助于其他人。

如果您在使用谷歌横幅广告(admob)的情况下遇到类似“没有广告展示”的问题,那么通过使视图宽度320固定来解决该问题。我通过制作广告宽度320和高度50解决了我的问题

希望这对其他人有帮助。

答案 1 :(得分:0)

Google's documentation is pretty straight forward so maybe you should take a look into it.

https://developers.google.com/admob/ios/banner

At first glance I have a question:

Are you configuring AdMob in your AppDelegate didFinishLaunching?

func application(_ application: UIApplication,
      didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Initialize the Google Mobile Ads SDK.
    // Sample AdMob app ID: ca-app-pub-3940256099942544~1458002511
    GADMobileAds.configure(withApplicationID: "YOUR_ADMOB_APP_ID")

    return true
  }

Some tips, like Payal Umraliya said, size is a pretty big deal in admob, so make sure adview has the same size of the ad you are requesting.

答案 2 :(得分:0)

添加测试设备-真实设备和模拟器。您可能会在Xcode输出窗格中找到测试设备字符串。

let request: GADRequest = GADRequest()
    request.testDevices = [ "661359a1bfeb6e588caf9c8133904d10", "96a6d0a80ffaa7094ad91b6648b6b50f", kGADSimulatorID ]
    bannerView.load(request)

答案 3 :(得分:0)