我GoolgeInteractiveMediaAds
在 tvOS 中使用该框架。在这个过程的最开始,我从代表那里得到一个错误,上面写着:Error loading ads: nil
. 我还加载了用 Objective C 编写的示例 Google 项目,该项目运行没有错误。在这个阶段几乎没有代码,我比较了这两个项目,并没有发现在AppDelegate
and方面有任何区别Info.plist
(唯一的区别是 Swift 项目从故事板开始)。
以下是代码的总和。当运行setUpAdsLoader
立即遇到您在底部看到的错误委托时。将他们的示例 Objective C 项目缩减为这些行,不会产生此错误。
import UIKit
import GoogleInteractiveMediaAds
class ViewController: UIViewController, IMAAdsLoaderDelegate {
private var adsLoader: IMAAdsLoader?
override func viewDidLoad() {
super.viewDidLoad()
setUpAdsLoader()
}
func setUpAdsLoader() {
self.adsLoader = IMAAdsLoader(settings: nil)
self.adsLoader!.delegate = self
}
func adsLoader(_ loader: IMAAdsLoader!, adsLoadedWith adsLoadedData: IMAAdsLoadedData!) {
// Grab the instance of the IMAAdsManager and set ourselves as the delegate
//adsManager = adsLoadedData.adsManager
//adsManager!.delegate = self
// Create ads rendering settings and tell the SDK to use the in-app browser.
let adsRenderingSettings = IMAAdsRenderingSettings()
adsRenderingSettings.webOpenerPresentingController = self
// Initialize the ads manager.
//adsManager!.initialize(with: adsRenderingSettings)
}
func adsLoader(_ loader: IMAAdsLoader!, failedWith adErrorData: IMAAdLoadingErrorData!) {
print("Error loading ads: \(String(describing: adErrorData.adError.message))")
}
}
更新:我创建了相同的测试项目,但这次使用的是 Objective C。工作没有错误。很难相信问题出在语言上,但我想知道这两种语言之间是否存在任何 Xcode 设置差异会导致这种情况?