To load a banner, create a MAAdView object that corresponds to your ad unit and call its loadAd method.
To show that ad, add the MAAdView object as a subview of your view hierarchy.
Implement MAAdViewAdDelegate so that you are notified when your ad is ready.
This also notifies you of other ad-related events.
To load a banner, create a MAAdView object that corresponds to your ad unit and call its loadAd method.
To show that ad, add the MAAdView object as a subview of your view hierarchy.
Implement MAAdViewAdDelegate so that you are notified when your ad is ready.
This also notifies you of other ad-related events.
To load a banner, create a UIViewRepresentable object, a wrapper that lets you integrate MAAdView, a UIKit view type object, into your SwiftUI view hierarchy.
Also provide a custom Coordinator class for the wrapper object that conforms to MAAdViewAdDelegate.
This notifies you when your ad is ready, and notifies you of other ad-related events.
Inside the wrapper’s makeUIView method, create a MAAdView object that corresponds to your ad unit.
Call its loadAd method.
To show that ad, add the UIViewRepresentable wrapper object inside your SwiftUI view hierarchy.
To load an MREC ad, create a MAAdView object corresponding to your ad unit and call its loadAd method.
To show the ad, add the MAAdView object as a subview of your view hierarchy.
Implement MAAdViewAdDelegate so that you are notified when your ad is ready.
This also notifes you of other ad-related events.
To load an MREC ad, create a MAAdView object corresponding to your ad unit and call its loadAd method.
To show the ad, add the MAAdView object as a subview of your view hierarchy.
Implement MAAdViewAdDelegate so that you are notified when your ad is ready.
This also notifies you of other ad-related events.
To load an MREC ad, first create a UIViewRepresentable object, a wrapper that lets you integrate MAAdView, a UIKit view type object, into your SwiftUI view hierarchy.
Also provde a custom Coordinator class for the wrapper object that conforms to MAAdViewAdDelegate.
This notifies you when your ad is ready, and notifies you of other ad-related events.
Inside the wrapper’s makeUIView method, create a MAAdView object that corresponds to your ad unit and call its loadAd method.
To show that ad, add the UIViewRepresentable wrapper object inside your SwiftUI view hierarchy.
You may no longer need a MAAdView instance.
This may happen, for example, if the user purchases ad removal.
Deallocate such a MAAdView instance in order to free resources.
Do not deallocate the MAAdView instance if you use multiple instances with the same Ad Unit ID.
Adaptive banners are responsive banners with heights that derive from the device type and the width of the banner.
You integrate adaptive banners in a similar way to how you integrate regular banners.
However, you must set the height to the value returned by MAAdFormat.banner.adaptiveSize.height rather than to a constant like 50 or 90.
Before you load the ad, set the banner extra parameter adaptive_banner to true as shown in the code below:
For more specific integrations you can set a custom width by using the local extra parameters API (as of Google adapter version 10.2.0.2 and Google Ad Manager adapter version 10.2.0.1).
You can fetch the appropriate height for your custom adaptive banner by using the adaptive size API.
Adaptive banners are anchored by default.
Alternatively, you can enable inline adaptive banners, which are meant to appear in scrolling content.
Inline adaptive banners are typically larger and taller than anchored adaptive banners.
They have variable heights that can extend to the full height of the device screen.
Inline adaptive banners are supported starting with Android adapter version 23.2.0.1 and iOS adapter version 11.7.0.1. To enable, set the extra local parameter adaptive_banner_type to inline, as shown in the code below:
You may want to set a maximum height, in points, for your inline adaptive banners.
You can do this with code like the following, which uses a height of 100 points as an example:
You may need to configure your UI in a way that depends on the adaptive banner size.
If so, you can retrieve the width and height of the loaded ad, in points, with code like the following:
You may want to stop auto-refresh for an ad.
You may want to do this, for instance, when you hide a banner ad or you want to manually refresh.
Stop auto-refresh for a banner or MREC ad with the following code: