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

问题描述 投票:0回答:1
 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和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引发此异常

这是我的问题。

我按照这个例子跟着它。为什么不?

enter image description here

ios swift admob google-admob
1个回答
2
投票

添加interstitial.delegate = self将解决您的问题

有关详细信息,请参阅this

© www.soinside.com 2019 - 2024. All rights reserved.