Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 3 Current »

The wrapper can be linked from the XCode’s UI builder or be created programmatically in the view controller.

Link from the XCode’s UI builder.

Here is a short example that demonstrates the wrapper usage by creating it in the XCode’s UI Builder.

Screenshot 2024-06-19 at 10.35.18-20240619-063530.png

The adContainer is linked with the AdViewController, and provided to the RefineryAdFactory.shared.createBanner(...) method as a wrapper parameter.

class AdViewController: UIViewController {
    
    @IBOutlet var adContainer:UIView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let configurationID = ConfigBuilder.companion.BANNER_TEST_R89_CONFIG_ID
        // Passing the adContainer wrapper to the SDK, so it can display a banner ad in it.
        RefineryAdFactory.shared.createBanner(wrapper: adContainer, 
                                              configurationID: configurationID,
                                              lifecycleCallbacks: nil)
    }
}

Now the ad will be placed inside the adContainer.

Create Programmatically

Here is the equivalent example that demonstrates how to create a wrapper programmatically and display an ad in it.

class AdViewController: UIViewController {
    
    let adContainer:UIView = {
        let view = UIView()
        view.translatesAutoresizingMaskIntoConstraints = false
        return view
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Add and center the adContainer in it's parent
        view.addSubview(adContainer)
        NSLayoutConstraint.activate([
           adContainer.centerXAnchor.constraint(equalTo: view.centerXAnchor),
           adContainer.centerYAnchor.constraint(equalTo: view.centerYAnchor),
        ])
         // Passing the adContainer wrapper to the SDK, so it can display a banner ad in it.
        RefineryAdFactory.shared.createBanner(wrapper: adContainer, 
                                              configurationID: ConfigBuilder.companion.BANNER_TEST_R89_CONFIG_ID,
                                              lifecycleCallbacks: nil)
    }
}

Now the adContainer has been created programmatically. It is added and centered in its parent. In the next step, the instance of adContainer is provided to the RefineryAdFactory.shared.createBanner via wrapper argument, so the SDK will display the ad in it.

  • No labels