Back to top

iOS Banner Integration

Last Updated on: 14 Jul, 2022

Create a Banner Object

INFO

If you miss to Initialize the SDK, this method will fail to return a response.

To implement a Banner bidder object for GAM follow:

Swift

//1.import MesonWrapGAM
import MesonWrapGAM

//2.Create a GAMRequest object
private var gamRequest = GAMRequest()

//3.Create a MesonGAMBanner object and Init with adUnitId and adSize
private var mesonBanner: MesonGAMBanner?
  mesonBanner = MesonGAMBanner.init(adUnitId: #adUnitId, adSize: #adSize)

Objective-C

//1. import MesonWrapGAM
@import MesonWrapGAM;

  //2. Create and Init a GAMRequest object with credientials
@property(nonatomic,strong) GAMRequest *gamRequest;

//3. Create a MesonGAMBanner object and Init with adUnitId and adSize
@property(nonatomic,strong) MesonGAMBanner *mesonBanner;
  self.mesonBanner = [[MesonGAMBanner alloc] initWithAdUnitId: #adUnitId adSize:#adSize];

Initialize the SKStoreManager

Initialize the SKStoreManager as follows:

Swift

//Please import the MesonWrapSKAN for CocoaPods integration. For manual please import the files.
var mesonBannerSKStoreManager: MesonBannerSKStoreManager()

Objective-C

//Please import the MesonWrapSKAN for CocoaPods integration. For manual please import the files.

//Declare the property
@property(nonatomic,strong) MesonBannerSKStoreManager *mesonBannerSKStoreManager;

// Initilize the MesonBannerSKStoreManager
self.mesonBannerSKStoreManager = [[MesonBannerSKStoreManager alloc] init];

Implement a Delegate

To implement a delegate for GAM follow:

Swift

//Success or failure callbacks
extension <ClassName>: MesonGAMBidFetcherDelegate {
  func bidFetched(for ppmAd: GAMRequest) {
    // Create a GAMBannerView and call load with GAMRequest
  }
  func bidFailed(for ppmAd: GAMRequest, with error: Error) {
    // Create a GAMBannerView and call load with GAMRequest
  }
}

Objective-C

@interface <ClassName> () <MesonGAMBidFetcherDelegate> {
  //Success or failure callbacks
  - (void)bidFetchedFor:(GAMRequest *)ppmAd {
    // Create a GAMBannerView and call load with GAMRequest
  }
  - (void)bidFailedFor:(GAMRequest *)ppmAd error:(NSError *)error {
    // Create a GAMBannerView and call load with GAMRequest
  }
}

Fetch a Bid

To fetch a bid for GAM follow:

Swift

// Fetch the Bid using the MesonGAMBanner.fetchBid with delegate MesonGAMBidFetcherDelegate.
mesonBanner?.fetchBid(gamRequest: gamRequest, delegate: self)

Objective-C

// Fetch the Bid using the MesonGAMBanner fetchBid with delegate MesonGAMBidFetcherDelegate.
[self.mesonBanner fetchBidWithGamRequest:self.gamRequest delegate:self];

Submit Signed Clicks to SKAdNetwork

After successfully loading the Banner Ad, call the following from the load success callback of GAM Delegate:

Swift

self.mesonBannerSKStoreManager.start(adObject: <AdObject>, delegate: self)

Objective-C

[self.mesonBannerSKStoreManager startWithAdObject:<AdObjcet> delegate:self];

Implement the following delegate methods

Swift

extension <ClassName>: MesonSkStoreManagerDelegate {
    func didFailToLoad(error: Error) {
      // SKStore fails to load  
    }   
    func didFailToShow(error: Error) {
      // SKStore fails to show  
    }   
    func didShow(skStore: UIViewController) {
      // SKStore successfully shown with the view controller
    }   
    func willDismiss(skStore: UIViewController) {
      // Successfully closed the SKStore view controller
    }
}

Objective-C

@interface <ClassName> () <MesonSkStoreManagerDelegate> {
  - (void)didFailToLoadWithError:(NSError * _Nonnull)error {
    // SKStore fails to load
  }
  - (void)didFailToShowWithError:(NSError * _Nonnull)error {
    // SKStore fails to show
  }
  - (void)didShowWithSkStore:(UIViewController * _Nonnull)skStore {
    // SKStore successfully shown with the view controller
  }
  - (void)willDismissWithSkStore:(UIViewController * _Nonnull)skStore {
    // Successfully closed the SKStore view controller
  }
}

WHAT'S NEXT

Next, let's integrate Interstitial ad units, or Manage Demand and Configure your Ad Server.