0

我的应用程序完全用 SwiftUI 编写。如何在 SwiftUI 中实现此代码?当我点击按钮时,我需要开始做广告

    import AdColony



class ViewController: UIViewController, AdColonyInterstitialDelegate {

    weak var interstitial:AdColonyInterstitial?

    /* Class body ... */

    func requestInterstitial() {
        AdColony.requestInterstitial(inZone: Ads.shared.currentZone, options: nil, andDelegate: self)
    }

    // MARK:- AdColony Interstitial Delegate

    // Store a reference to the returned interstitial object
    func adColonyInterstitialDidLoad(_ interstitial: AdColonyInterstitial) {
        self.interstitial = interstitial
    }
    
    // Handle loading error
    func adColonyInterstitialDidFail(toLoad error: AdColonyAdRequestError) {
        print("Interstitial request failed with error: \(error.localizedDescription) and suggestion: \(error.localizedRecoverySuggestion!)")
    }
    
    // Handle expiring ads (optional)
    func adColonyInterstitialExpired(_ interstitial: AdColonyInterstitial) {
        // remove reference to stored ad
        self.interstitial = nil

        // you can request new ad
        self.requestInterstitial()
    }
    
}

广告投放:

if let interstitial = self.interstitial, !interstitial.expired {
    interstitial.show(withPresenting: self)
}
4

0 回答 0