BannerAds

public class BannerAds

This class is the entry point for displaying banner ads.

To start, create a banner by providing a valid placement id in the create(placementId:size:viewController:) method. Then call getView(forPlacementId:fromViewController:) to obtain the view to add to the view hierarchy. And that’s it! You don’t need to do anything else, as banners will refresh automatically while visible.

Note

You can only create one banner per placement id. Subsequent calls with the same placement id will be ignored.

  • Adds a delegate for handling all banner ads events.

    The delegate must adopt the BannerAdsDelegate protocol. The delegate is not retained.

    Declaration

    Swift

    public func addDelegate(_ delegate: BannerAdsDelegate)

    Parameters

    delegate

    the delegate that will listen to all banner ad events.

  • Removes a delegate that was previously handling banner ads events.

    Declaration

    Swift

    public func removeDelegate(_ delegate: BannerAdsDelegate)

    Parameters

    delegate

    the delegate to be removed.

  • Creates and loads a new banner ad.

    Declaration

    Swift

    public func create(placementId: String, size: Banner.Size, viewController: UIViewController? = nil)

    Parameters

    placementId

    The placement id of the banner ad.

    size

    Size of the banner ad. See Size for the available sizes.

    viewController

    Some networks require a viewController to be able to load or display a full sized ad when a banner is clicked. If no controller is provided, the sdk will try to obtain the active viewController.

  • Manually refreshes a banner ad.

    The usage of this method is optional, as banner ads refresh automatically.

    Declaration

    Swift

    public func load(placementId: String)

    Parameters

    placementId

    The placement id of the ad to be refreshed.

  • Sets the ad space for the specified placementId.

    Declaration

    Swift

    public func setAdSpace(_ adSpace: String?, forPlacementId placementId: String)

    Parameters

    adSpace

    The space in your app from where the ad will be shown (eg: dashboard, settings). Set nil to reset adSpace. Used for tracking.

    placementId

    The placement id of the banner ad.

  • Obtain the banner view that should be added to the view hierarchy.

    You can call this method at any time after creating a banner ad.

    Throws

    A BannerError in case there was a problem (for instance, if the banner ad was never created).

    Declaration

    Swift

    public func getView(forPlacementId placementId: String, fromViewController viewController: UIViewController? = nil) throws -> UIView

    Parameters

    placementId

    The placement id of the ad.

    viewController

    Some networks require to be passed the viewController which will contain the banner view. If no controller is provided, the sdk will try to obtain the active viewController.

    Return Value

    The banner view to be added to the view hierarchy.