Native Ad
Before start loading Admob you should load Bidmachine ad and save it to store
import BidMachine
import BidMachineAdMobAdapter
func before() throws {
let configuration = try BidMachineSdk.shared.requestConfiguration(.native)
BidMachineSdk.shared.native(configuration) { [weak self] native, error in
AdMobAdapter.store(native)
self?.after()
}
}
@import BidMachine;
@import BidMachineApiCore;
@import BidMachineAdMobAdapter;
- (void)before {
[BidMachineSdk.shared native:nil :^(BidMachineNative *ad, NSError *error) {
[BDMAdMobAdapter store:ad];
[weakSelf after];
}];
}
Then you can create an admob object and load it
func after() {
let multipleAdOptions = GADMultipleAdsAdLoaderOptions()
multipleAdOptions.numberOfAds = 5
self.adLoader = GADAdLoader(
adUnitID: "unit id",
rootViewController: self,
adTypes: [.native],
options: [multipleAdOptions]
)
self.adLoader.delegate = self
self.adLoader.load(GADRequest())
}
- (void)after {
GADRequest *request = [GADRequest request];
[self.nativeLoader loadRequest:request];
}
- (GADAdLoader *)nativeLoader {
if (!_nativeLoader) {
_nativeLoader = [[GADAdLoader alloc] initWithAdUnitID:@UNIT_ID
rootViewController:self
adTypes:@[kGADAdLoaderAdTypeNative]
options:@[self.viewOptions, self.videoOptions, self.mediaOptions]];
_nativeLoader.delegate = self;
}
return _nativeLoader;
}
- (GADAdLoaderOptions *)videoOptions {
GADVideoOptions *options = GADVideoOptions.new;
options.startMuted = YES;
return options;
}
- (GADAdLoaderOptions *)mediaOptions {
GADNativeAdMediaAdLoaderOptions *options = GADNativeAdMediaAdLoaderOptions.new;
options.mediaAspectRatio = GADMediaAspectRatioLandscape;
return options;
}
- (GADAdLoaderOptions *)viewOptions {
GADNativeAdViewAdOptions *options = GADNativeAdViewAdOptions.new;
options.preferredAdChoicesPosition = GADAdChoicesPositionTopRightCorner;
return options;
}
Updated 12 months ago