繁体   English   中英

iOS Swift AddMob无法识别的选择器已发送到实例

[英]iOS Swift AddMob unrecognized selector sent to instance

 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")
    }
}

并添加构建设置调试和发布-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将解决您的问题

查看以获取更多详细信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM