ios - iOS Swift AddMob 无法识别的选择器发送到实例
问题描述
import UIKit
import Firebase
class MyPage: UIViewController ,UITextViewDelegate,UINavigationControllerDelegate{
var interstitial: GADInterstitial!
fileprivate func createAndLoadInterstitial() {
interstitial = GADInterstitial(adUnitID: "ca-app-pub-3940256099942544/4411468910")
interstitial.delegate = self
let request = GADRequest()
// Request test ads on devices you specify. Your test device ID is printed to the console when
// an ad request is made.
request.testDevices = [ kGADSimulatorID, "2077ef9a63d2b398840261c8221a0c9a" ]
interstitial.load(request)
}
override func viewDidLoad() {
super.viewDidLoad()
createAndLoadInterstitial()
}
}
extension MyPage:GADInterstitialDelegate{
/// Tells the delegate an ad request succeeded.
func interstitialDidReceiveAd(_ ad: GADInterstitial) {
print("interstitialDidReceiveAd")
}
/// Tells the delegate an ad request failed.
func interstitial(_ ad: GADInterstitial, didFailToReceiveAdWithError error: GADRequestError) {
print("interstitial:didFailToReceiveAdWithError: \(error.localizedDescription)")
}
/// Tells the delegate that an interstitial will be presented.
func interstitialWillPresentScreen(_ ad: GADInterstitial) {
print("interstitialWillPresentScreen")
}
/// Tells the delegate the interstitial is to be animated off the screen.
func interstitialWillDismissScreen(_ ad: GADInterstitial) {
print("interstitialWillDismissScreen")
}
/// Tells the delegate the interstitial had been animated off the screen.
func interstitialDidDismissScreen(_ ad: GADInterstitial) {
print("interstitialDidDismissScreen")
}
/// Tells the delegate that a user click will open another app
/// (such as the App Store), backgrounding the current app.
func interstitialWillLeaveApplication(_ ad: GADInterstitial) {
print("interstitialWillLeaveApplication")
}
}
并添加 Build Setting Debug And Release -ObjC
除了这个,我还能做些什么吗?
目标 iOS 11 Swift 4.1 设备 - 我的 Iphone 5S(iOS 11.1) ,模拟器 IphoneX (IOS 11.4)
堆栈跟踪
GADDiskUsageStatisticsWithError + 11328
17 MyApp 0x100a78f6c GADDiskUsageStatisticsWithError + 3064
18 MyApp 0x100a78d98 GADDiskUsageStatisticsWithError + 2596
19 MyApp 0x100a51684 GADCategories_GADSlot_State + 5872
20 MyApp 0x100a08bac GADCategories_GADInterstitial_RewardBasedVideoAdGMSGAddition + 5980
21 libdispatch.dylib 0x18105d088 _dispatch_call_block_and_release + 24
22 libdispatch.dylib 0x18105d048 _dispatch_client_callout + 16
23 libdispatch.dylib 0x181069b74 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1016
24 CoreFoundation 0x181681eb0 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
25 CoreFoundation 0x18167fa8c __CFRunLoopRun + 2012
26 CoreFoundation 0x18159ffb8 CFRunLoopRunSpecific + 436
27 GraphicsServices 0x183437f84 GSEventRunModal + 100
28 UIKit 0x18ab742f4 UIApplicationMain + 208
29 MyApp 0x1007992e4 main (AppDelegate.swift:11)
30 libdyld.dylib 0x1810c256c start + 4
如果我只是加载 MyPage 会引发此异常
这是我的问题。
我遵循了这个例子并遵循了它。为什么不?
解决方案
添加interstitial.delegate = self
将解决您的问题
有关更多详细信息,请参阅此
推荐阅读
- java - Java 解密创建附加符号
- php - PHP函数从段落中删除第一句话
- javascript - Vue 和 Firebase RTDB 连接
- java - 在Android中有效地将图像上传到服务器
- google-chrome-devtools - Chrome DevTools:关闭 Lighthouse-Report
- python - Keras 生成器到 tf.data.Dataset
- c# - 当我为该条目设置变量并更改变量时,为什么列表中的条目会更改?
- python - CV 高度、宽度、通道到通道、高度、宽度
- asp.net - Asp.Net VB webform 如何将模板字段 Gridview 导出为 csv?
- php - WP Rest API 自定义端点在 GET 和 POST 上返回 false