Git Product home page Git Product logo

bidmachine-google-mobile-ads-ios-adapters's Introduction

BidMachine iOS

BidMachine IOS AdMob Bidding Sample

Getting Started

Add following lines into your project Podfile

NOTE: In 2.5 + version needed use BidMachineAdMobAdapter spec name

target 'Target' do
  project 'Project.xcodeproj'
  pod 'BidMachineAdMobAdapter', '~> 2.5.0'
end

Initialize sdk

WARNING: Before initialize AdMob sdk you should start BM sdk.

    [BidMachineSdk.shared populate:^(id<BidMachineInfoBuilderProtocol> builder) {
            [builder withTestMode:YES];
            [builder withLoggingMode:YES];
            [builder withBidLoggingMode:YES];
            [builder withEventLoggingMode:YES];
    }];
    
    [BidMachineSdk.shared initializeSdk: @"1"];

    [[GADMobileAds sharedInstance] startWithCompletionHandler:^(GADInitializationStatus * _Nonnull status) {
            NSDictionary *statuses = status.adapterStatusesByClassName;
            NSLog(@"%@", [statuses.allKeys componentsJoinedByString:@","]);
    }];

Banner implementation

Before start loading Admob you should load Bidmachine ad and save it to store

NOTE: For some banners you should use some placment (BidMachinePlacementFormatBanner320x50, BidMachinePlacementFormatBanner300x250)

@import BidMachine;
@import BidMachineApiCore;
@import BidMachineAdMobAdapter;

- (void)before {
    __weak typeof(self) weakSelf = self;
    id<BidMachineRequestConfigurationProtocol> config = [BidMachineSdk.shared requestConfiguration:BidMachinePlacementFormatBanner320x50 error:nil];
    [BidMachineSdk.shared banner:config :^(BidMachineBanner *ad, NSError *error) {
        [BidMachineAdMobAdapter store:ad]; 
        [weakSelf after];
    }];
}

- (void)after {
    self.bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner]; // kGADAdSizeMediumRectangle
    self.bannerView.delegate = self;
    self.bannerView.adUnitID = @UNIT_ID;
    self.bannerView.rootViewController = self;
    self.bannerView.translatesAutoresizingMaskIntoConstraints = YES;
    self.bannerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    GADRequest *request = [GADRequest request];
    [self.bannerView loadRequest:request];
}

Interstitial implementation

Before start loading Admob you should load Bidmachine ad and save it to store

@import BidMachine;
@import BidMachineApiCore;
@import BidMachineAdMobAdapter;

- (void)before {
    __weak typeof(self) weakSelf = self;
    [BidMachineSdk.shared interstitial:nil :^(BidMachineInterstitial *ad, NSError *error) {
        [BidMachineAdMobAdapter store:ad];
        [weakSelf after];
    }];
}

- (void)after {
    GADRequest *request = [GADRequest request];
    [GADInterstitialAd loadWithAdUnitID:@UNIT_ID request:request completionHandler:^(GADInterstitialAd * _Nullable interstitialAd, NSError * _Nullable error) {
        if (error) {
            // fail load
        } else {
            self.interstitial = interstitialAd;
            self.interstitial.fullScreenContentDelegate = self;
        }
    }];
}

Rewarded implementation

Before start loading Admob you should load Bidmachine ad and save it to store

@import BidMachine;
@import BidMachineApiCore;
@import BidMachineAdMobAdapter;

- (void)before {
   __weak typeof(self) weakSelf = self;
    [BidMachineSdk.shared rewarded:nil :^(BidMachineRewarded *ad, NSError *error) {
        [BidMachineAdMobAdapter store:ad];
        [weakSelf after];
    }];
}

- (void)after {
    GADRequest *request = [GADRequest request];
    [GADRewardedAd loadWithAdUnitID:@UNIT_ID request:request completionHandler:^(GADRewardedAd * _Nullable rewardedAd, NSError * _Nullable error) {
        if (error) {
            // fail load
        } else {
            self.rewarded = rewardedAd;
            self.rewarded.fullScreenContentDelegate = self;
        }
    }];
}

Native ad implementation

Before start loading Admob you should load Bidmachine ad and save it to store

@import BidMachine;
@import BidMachineApiCore;
@import BidMachineAdMobAdapter;

- (void)before {
    [BidMachineSdk.shared native:nil :^(BidMachineNative *ad, NSError *error) {
        [BidMachineAdMobAdapter store:ad];
        [weakSelf after];
    }];
}

- (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;
}

bidmachine-google-mobile-ads-ios-adapters's People

Contributors

aliaksandrharbachou avatar assasinsc avatar harturkm avatar staskochkin avatar yaroslavskachkov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bidmachine-google-mobile-ads-ios-adapters's Issues

Issues with podspec

Hi,
There are a couple issues with the latest podspec: https://github.com/CocoaPods/Specs/blob/master/Specs/9/f/e/GoogleMobileAds-BidMachine-Adapters/1.9.2.0/GoogleMobileAds-BidMachine-Adapters.podspec.json

  1. Lack of arm64 support for simulator SDK:
  "pod_target_xcconfig": {
    "VALID_ARCHS": "arm64 armv7 armv7s x86_64",
    "VALID_ARCHS[sdk=iphoneos*]": "arm64 armv7 armv7s",
    "VALID_ARCHS[sdk=iphonesimulator*]": "x86_64"
  },

Fix: "VALID_ARCHS[sdk=iphonesimulator*]": "x86_64 arm64" (assumes that all this pod's dependencies that use frameworks support arm64 in their iOS simulator SDK framework)

  1. user_target_xcconfig should probably be removed:
  "user_target_xcconfig": {
    "VALID_ARCHS": "arm64 armv7 armv7s x86_64",
    "VALID_ARCHS[sdk=iphoneos*]": "arm64 armv7 armv7s",
    "VALID_ARCHS[sdk=iphonesimulator*]": "x86_64"
  },

https://guides.cocoapods.org/syntax/podspec.html#user_target_xcconfig

This attribute is not recommended as Pods should not pollute the build settings of the user project and this can cause conflicts.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.