我正在尝试使用MoPub教程中的测试ID测试mopub插页式广告,ios版本为10.2,MoPub输出
2017-01-15 13:47:46.801224 Twit Miner[23775:6627095] MOPUB: Looking for custom event class named MPHTMLInterstitialCustomEvent.
2017-01-15 13:47:46.801321 Twit Miner[23775:6627095] MOPUB: Loading MoPub HTML interstitial
2017-01-15 13:47:46.999975 Twit Miner[23775:6627095] MOPUB: MoPub HTML interstitial did load
但我没有看到任何插页式广告被展示。您可以在下面找到我的代码:
import UIKit
import MoPub
class ViewController: UIViewController
, MPInterstitialAdControllerDelegate
{
// TODO: Replace this test id with your personal ad unit id
var interstitial: MPInterstitialAdController =
MPInterstitialAdController(forAdUnitId: "77ce0b65cf81438eb255695afe3b1904")
override func viewDidLoad() {
super.viewDidLoad()
self.interstitial.delegate = self
// Pre-fetch the ad up front
self.interstitial.loadAd()
}
func interstitialDidLoadAd(interstitial: MPInterstitialAdController) {
// This sample automatically shows the ad as soon as it's loaded, but
// you can move this showFromViewController call to a time more
// appropriate for your app.
if (interstitial.ready) {
interstitial.showFromViewController(self)
}
}
}
即使log建议不然,当我设置断点时,我意识到interstitialDidLoadAd方法永远不会被调用。我认为这可能是由于ATS所以我将以下密钥添加到info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsForMedia</key>
<true/>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
</dict>
仍然没有运气,有人可以告诉我,我可能做错了吗?
答案 0 :(得分:0)
我意识到这可能为时已晚。
检查您是否有以下日志条目:
A location manager (0x143ebb150) was created on a dispatch queue
executing on a thread other than the main thread. It is the
developer's responsibility to ensure that there is a run loop running
on the thread on which the location manager object is allocated. In
particular, creating location managers in arbitrary dispatch queues
(not attached to the main queue) is not supported and will result in
callbacks not being received.
就在之前:
MOPUB: Interstitial controller is loading ad with MoPub server URL:
如果是这样,请尝试在主队列上调度loadAd
方法,如下所示。
<强>目标C 强>
dispatch_async(dispatch_get_main_queue(), ^{
[self.interstitial loadAd];
});
Swift 3
DispatchQueue.main.async {
self.interstitial.loadAd()
}