Swift AdMob 广告尺寸错误
Swift AdMob ad wrong size
我在 may 应用程序中使用 AdMobs 智能横幅,我按照 Google 入门中的建议做了所有事情,除了横幅大小没有修复 320x50
,而是 screen widthx50
。在自动布局中,我为水平中心添加了 1 个约束,为屏幕宽度添加了 1 个约束。如果我 运行 在模拟器上我工作得很好但在设备上我收到这个错误:
<Google> Unable to set adSize property. Not enough space to show ad with custom size, {600, 50}. Please use a size that fits the current screen bounds of {320, 568}.
<Google> To get test ads on this device, call: request.testDevices = @[ @"bb3f8f97887" ];
<Google> Unable to set adSize property. Not enough space to show ad with custom size, {600, 50}. Please use a size that fits the current screen bounds of {320, 568}.
<Google> Invalid Request. Ad size will not fit on screen
如果我记录 GADBannerView 视图大小,我会得到这个(运行宁 iPhone 5):
Size: (0.0, 0.0, 320.0, 50.0)
这是我的代码:
@IBOutlet weak var bannerView: GADBannerView!
bannerView.adUnitID = "ca-app-pub-394/216"
bannerView.adSize = kGADAdSizeSmartBannerPortrait
bannerView.rootViewController = self
print("Size: ",bannerView.bounds)
bannerView.loadRequest(GADRequest())
这些是我的约束
您需要添加宽度限制。
按住 Ctrl 键从 AdView 拖动到父视图并 select 等宽。
对于 SwiftUI,确保添加视图框架
BannerAd(bannerID: "ca-app-pub")
.frame(width: 320, height: 50)
我在 may 应用程序中使用 AdMobs 智能横幅,我按照 Google 入门中的建议做了所有事情,除了横幅大小没有修复 320x50
,而是 screen widthx50
。在自动布局中,我为水平中心添加了 1 个约束,为屏幕宽度添加了 1 个约束。如果我 运行 在模拟器上我工作得很好但在设备上我收到这个错误:
<Google> Unable to set adSize property. Not enough space to show ad with custom size, {600, 50}. Please use a size that fits the current screen bounds of {320, 568}.
<Google> To get test ads on this device, call: request.testDevices = @[ @"bb3f8f97887" ];
<Google> Unable to set adSize property. Not enough space to show ad with custom size, {600, 50}. Please use a size that fits the current screen bounds of {320, 568}.
<Google> Invalid Request. Ad size will not fit on screen
如果我记录 GADBannerView 视图大小,我会得到这个(运行宁 iPhone 5):
Size: (0.0, 0.0, 320.0, 50.0)
这是我的代码:
@IBOutlet weak var bannerView: GADBannerView!
bannerView.adUnitID = "ca-app-pub-394/216"
bannerView.adSize = kGADAdSizeSmartBannerPortrait
bannerView.rootViewController = self
print("Size: ",bannerView.bounds)
bannerView.loadRequest(GADRequest())
这些是我的约束
您需要添加宽度限制。
按住 Ctrl 键从 AdView 拖动到父视图并 select 等宽。
对于 SwiftUI,确保添加视图框架
BannerAd(bannerID: "ca-app-pub")
.frame(width: 320, height: 50)