gpt4 book ai didi

ios - Swift iAd - 超过 10 个 ADBannerView 警告和 CGAffineTransformInvert 实例 : singular matrix output

转载 作者:IT王子 更新时间:2023-10-29 05:29:40 26 4
gpt4 key购买 nike

所以我尝试在我的应用程序中设置一个简单的 iAd 横幅,但我在输出中收到以下两个警告:

WARNING: More than 10 instances of ADBannerView or ADInterstitialView 
currently exist. This is a misuse of the iAd API, and ad performance will
suffer as a result. This message is printed only once.

<Error>: CGAffineTransformInvert: singular matrix.

这就是我用来实现我的 ADBannerView 的东西:

var adBannerView = ADBannerView()

func loadAds() {
adBannerView = ADBannerView(frame: CGRect.zeroRect)
adBannerView.center = CGPoint(x: adBannerView.center.x, y: view.bounds.size.height - adBannerView.frame.size.height / 2)
adBannerView.delegate = self
adBannerView.hidden = true
view.addSubview(adBannerView)
}

//BannerView did load ad
func bannerViewDidLoadAd(banner: ADBannerView!) {
adBannerView.hidden = false
}
//BannerView failed to load
func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
adBannerView.hidden = true
}

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
loadAds()
//(rest of the code is from here onwards)

我尝试添加这个来阻止第一个错误:(没用)

//BannerView will disappear
override func viewWillDisappear(animated: Bool) {
adBannerView.removeFromSuperview()
adBannerView.delegate = nil
}

最佳答案

问题是每次加载 View 时都会创建一个新的 ADBannerView 实例。我们需要做的是在我们的 AppDelegate.swift 中创建一个 ADBannerView,然后将这个 ADBannerView 呈现在我们想要的任何 View 上iAd 横幅。这也称为 Shared iAd Banner .在这个例子中,我在我的 AppDelegate.swift 中创建了一个 ADBannerView,然后将它添加到我的 ViewController.swift 的 View 中。

AppDelegate.swift

import UIKit
import iAd // Import iAd

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, ADBannerViewDelegate { // Include the delegate for our banner

var window: UIWindow?
var adBannerView = ADBannerView() // Create our one ADBannerView

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Set delegate and hide banner initially
adBannerView.delegate = self
adBannerView.hidden = true
return true
}

func bannerViewDidLoadAd(banner: ADBannerView!) {
print("bannerViewDidLoadAd")
adBannerView.hidden = false
}

func bannerViewActionDidFinish(banner: ADBannerView!) {
print("bannerViewActionDidFinish")
}

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
print("didFailToReceiveAdWithError: \(error)")
adBannerView.hidden = true
}

ViewController.swift

import UIKit

class ViewController: UIViewController {

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate // Create reference to our app delegate

override func viewWillAppear(animated: Bool) {
// Position
appDelegate.adBannerView.center = CGPoint(x: view.frame.midX,
y: view.frame.height - appDelegate.adBannerView.frame.height / 2)
// Add to view
view.addSubview(appDelegate.adBannerView)
}

不要忘记从您之前添加的 viewWillDisappear(animated: Bool) 函数中删除代码。如果您单击横幅然后将其关闭,将调用此函数并从我们的 View 中删除我们的横幅并将我们的横幅委托(delegate)设置为 nil 过早会导致问题。

关于ios - Swift iAd - 超过 10 个 ADBannerView 警告和 CGAffineTransformInvert 实例 : singular matrix output,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28514758/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com