Native Ads
With the release of MAS 4.6, you can now use Native Ads in your games! Here are a few things you need to know in order to get started with this ad type:
- Native ads in MAS are available in 3 sizes: Small, Medium, or Custom. Small has a ratio of 3:1, and Medium has a ratio of 6:5. See the table below for recommended sizes.
- Custom means you show Native Ad in a way that’s consistent with its existing UI design, please click here to follow the custom native ad integration instruction.
- Currently, you may only use 1 size of Native Ad for your game, which you can specify during the submission of your game. Should you need to change the size, please contact the support team via the support chat.
Small Size (3:1) | Medium Size (6:5) |
300 x 100 | 600 x 500 |
1. Init Yodo1MasNativeAdView
Yodo1MasNativeAdView *nativeAdView = [[Yodo1MasNativeAdView alloc] init]; nativeAdView.frame = CGRectMake(0, 0, 375, 200); // TODO: Add nativeAdView to your view hierarchy.
let nativeAdView = Yodo1MasNativeAdView() bnativeAdView.frame = CGRect(x: 0, y: 0, width: 375, height: 200) // TODO: Add bnativeAdView to your view hierarchy.
2. Load an ad
Once the Yodo1MasNativeAdView
is in place, the next step is to load an ad. That’s done with the loadAd()
method in the Yodo1MasNativeAdView
class.
Here’s an example that shows how to load an ad in the viewDidLoad
method of an UIViewController
:
#import #import "Yodo1Mas.h" #import "Yodo1MasNativeAdView.h" @interface MainController () @property (nonatomic, strong) Yodo1MasNativeAdView *nativeAdView; @end @implementation MainController - (void)viewDidLoad { [super viewDidLoad]; [[Yodo1Mas sharedInstance] initWithAppKey:@"YourAppKey" successful:^{ } fail:^(NSError * _Nonnull error) { }]; _nativeAdView = [[Yodo1MasNativeAdView alloc] init]; _nativeAdView.frame = CGRectMake(0, 0, 375, 200); [_nativeAdView loadAd]; [self.view addSubview:_nativeAdView]; } @end
import UIKit import Yodo1MasCore class MainController : UIViewController { var nativeAdView: Yodo1MasNativeAdView! override func viewDidLoad() { super.viewDidLoad() Yodo1Mas.sharedInstance().initWithAppKey("YourAppKey") { } fail: { error in } nativeAdView = Yodo1MasNativeAdView() nativeAdView.frame = CGRect(x: 0, y: 0, width: 375, height: 200) nativeAdView.loadAd() self.view.addSubview(nativeAdView) } }
That’s it! Your app is now ready to display native ads.
3. Ad events
To further customize the behavior of your ad, you can hook onto a number of events in the ad’s lifecycle: loading, opening, closing, and so on. You can listen for these events through the Yodo1MasNativeAdViewDelegate
.
#import #import "Yodo1Mas.h" #import "Yodo1MasNativeAdView.h" @interface MainController () @property (nonatomic, strong) Yodo1MasNativeAdView *nativeAdView; @end @implementation MainController - (void)viewDidLoad { [super viewDidLoad]; [[Yodo1Mas sharedInstance] initWithAppKey:@"YourAppKey" successful:^{ } fail:^(NSError * _Nonnull error) { }]; _nativeAdView = [[Yodo1MasNativeAdView alloc] init]; _nativeAdView.frame = CGRectMake(0, 0, 375, 200); _nativeAdView.adDelegate = self; [_nativeAdView loadAd]; [self.view addSubview:_nativeAdView]; } #pragma mark - Yodo1MasNativeAdViewDelegate - (void)onNativeAdLoaded:(Yodo1MasNativeAdView *)nativeView { } - (void)onNativeAdFailedToLoad:(Yodo1MasNativeAdView *)nativeView withError:(Yodo1MasError *)error { } @end
import UIKit import Yodo1MasCore class MainController: UIViewController { var nativeAdView: Yodo1MasNativeAdView! override func viewDidLoad() { super.viewDidLoad() Yodo1Mas.sharedInstance().initWithAppKey("YourAppKey") { } fail: { error in } nativeAdView = Yodo1MasNativeAdView() nativeAdView.frame = CGRect(x: 0, y: 0, width: 375, height: 200) nativeAdView.adDelegate = self nativeAdView.loadAd() self.view.addSubview(nativeAdView) } } extension MainController: Yodo1MasNativeAdViewDelegate { // MARK: Yodo1MasNativeAdViewDelegate func onNativerAdLoaded(_ nativeView: Yodo1MasNativeAdView) { } func onNativeAdFailed(toLoad nativeView: Yodo1MasNativeAdView, withError error: Yodo1MasError) { } }