ADBannerView 未显示
ADBannerView not showing up
我正在尝试将 iAd Banner 放入我的游戏中!我已经在游戏中担任主角很长一段时间,等待正常的 Apple iAd 广告出现,但它没有出现。它根本没有出现在我的屏幕上!
我是不是做错了什么?
还是最终会出现?
import iAd
var iAdBanner = ADBannerView()
var bannerVisible = false
class GameViewController: UIViewController, ADBannerViewDelegate{
override func viewDidLoad() {
super.viewDidLoad()
if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
// Configure the view.
let skView = self.view as SKView
/* Set the scale mode to scale to fit the window */
scene.scaleMode = .AspectFill
skView.presentScene(scene)
iAdBanner.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.width, 50)
iAdBanner.delegate = self
bannerVisible = false
}
}
// Show banner, if Ad is successfully loaded.
func bannerViewDidLoadAd(banner: ADBannerView!) {
if(bannerVisible == false) {
// Add banner Ad to the view
if(iAdBanner.superview == nil) {
self.view.addSubview(iAdBanner)
}
// Move banner into visible screen frame:
UIView.beginAnimations("iAdBannerShow", context: nil)
banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height)
UIView.commitAnimations()
bannerVisible = true
}
}
// Hide banner, if Ad is not loaded.
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
if(bannerVisible == true) {
// Move banner below screen frame:
UIView.beginAnimations("iAdBannerHide", context: nil)
banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height)
UIView.commitAnimations()
bannerVisible = false
}
}
您还没有将横幅视图添加到您的视图中。您在 bannerViewDidLoadAd
中调用了 self.view.addSubview(iAdBanner)
,在添加横幅视图之前不会调用它。您需要事先添加横幅视图(例如 viewDidLoad
)。
此外,您无法将横幅视图框架更改为您想要的任何大小。
阅读 iAD 编程指南中的 Banner View Sizes(实际上阅读了整个指南)。它有代码片段(虽然在 ObjC 中不是 Swift)。
它清楚地写着:
iAd supports different banner sizes for portrait and landscape apps.
The exact size of advertisements depends on the device the banner is
being shown on. On an iPhone, a portrait advertisement is 320 x 50
points and 480 x 32 points for a landscape advertisement. On an iPad,
a portrait advertisement is 768 x 66 points and 1024 x 66 points for a
landscape advertisement. In the future, additional sizes may be
exposed by iAd.
在下一段中:
To ensure that advertisements are displayed properly, a banner view
must always be sized to match one of the built-in advertising sizes.
The ADBannerView class enforces this by preventing you from changing
the frame directly. Instead, you change a banner view’s frame by
setting the currentContentSizeIdentifier property. Changing the value
stored in this property resizes the banner view’s frame to the match
the size for the provided identifier.
可能会检查您的故事板 --> 您的 viewcontroller 包含 iAd --> 查看属性检查器选项卡 --> 关注“延伸边缘”,并取消选中此属性。希望这有帮助。感谢阅读此答案。
我正在尝试将 iAd Banner 放入我的游戏中!我已经在游戏中担任主角很长一段时间,等待正常的 Apple iAd 广告出现,但它没有出现。它根本没有出现在我的屏幕上!
我是不是做错了什么?
还是最终会出现?
import iAd
var iAdBanner = ADBannerView()
var bannerVisible = false
class GameViewController: UIViewController, ADBannerViewDelegate{
override func viewDidLoad() {
super.viewDidLoad()
if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
// Configure the view.
let skView = self.view as SKView
/* Set the scale mode to scale to fit the window */
scene.scaleMode = .AspectFill
skView.presentScene(scene)
iAdBanner.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.width, 50)
iAdBanner.delegate = self
bannerVisible = false
}
}
// Show banner, if Ad is successfully loaded.
func bannerViewDidLoadAd(banner: ADBannerView!) {
if(bannerVisible == false) {
// Add banner Ad to the view
if(iAdBanner.superview == nil) {
self.view.addSubview(iAdBanner)
}
// Move banner into visible screen frame:
UIView.beginAnimations("iAdBannerShow", context: nil)
banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height)
UIView.commitAnimations()
bannerVisible = true
}
}
// Hide banner, if Ad is not loaded.
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
if(bannerVisible == true) {
// Move banner below screen frame:
UIView.beginAnimations("iAdBannerHide", context: nil)
banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height)
UIView.commitAnimations()
bannerVisible = false
}
}
您还没有将横幅视图添加到您的视图中。您在 bannerViewDidLoadAd
中调用了 self.view.addSubview(iAdBanner)
,在添加横幅视图之前不会调用它。您需要事先添加横幅视图(例如 viewDidLoad
)。
此外,您无法将横幅视图框架更改为您想要的任何大小。
阅读 iAD 编程指南中的 Banner View Sizes(实际上阅读了整个指南)。它有代码片段(虽然在 ObjC 中不是 Swift)。
它清楚地写着:
iAd supports different banner sizes for portrait and landscape apps. The exact size of advertisements depends on the device the banner is being shown on. On an iPhone, a portrait advertisement is 320 x 50 points and 480 x 32 points for a landscape advertisement. On an iPad, a portrait advertisement is 768 x 66 points and 1024 x 66 points for a landscape advertisement. In the future, additional sizes may be exposed by iAd.
在下一段中:
To ensure that advertisements are displayed properly, a banner view must always be sized to match one of the built-in advertising sizes. The ADBannerView class enforces this by preventing you from changing the frame directly. Instead, you change a banner view’s frame by setting the currentContentSizeIdentifier property. Changing the value stored in this property resizes the banner view’s frame to the match the size for the provided identifier.
可能会检查您的故事板 --> 您的 viewcontroller 包含 iAd --> 查看属性检查器选项卡 --> 关注“延伸边缘”,并取消选中此属性。希望这有帮助。感谢阅读此答案。