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