Buildbox 3 Beta Ios: Integrated Banner And Interstitial Ads (heyzap) With Custom Options

Discussion in 'Buildbox 3.0' started by particles, Oct 16, 2018.

  1. particles

    particles Avid Boxer

    Joined:
    Aug 31, 2018
    Messages:
    337
    Likes Received:
    242
    @volcank Exact problem I had, removed banner. If you want to remove banner after game over UI.
    Just try to remove at Banner in

    AdIntegrator.mm
    //
    -(void)hideBanner{
    // Remove the banner.
    NSLog(@"[Ads] hide banner");

    }
     
    volcank likes this.
  2. volcank

    volcank Serious Boxer

    Joined:
    Oct 8, 2015
    Messages:
    795
    Likes Received:
    393
    Oh man this is great thank you btw exactly where do I write this code in ad integrator a simple like after this line would do for me! I am code retarded sorry
     
  3. volcank

    volcank Serious Boxer

    Joined:
    Oct 8, 2015
    Messages:
    795
    Likes Received:
    393
    @particles Hi sorry I just checked the code I got from you and it already has the code you just shared only it doesn't have
    // Remove the banner.

    line. seems it is only an explanation. Does it work like this thank you!
     
  4. particles

    particles Avid Boxer

    Joined:
    Aug 31, 2018
    Messages:
    337
    Likes Received:
    242
    volcank likes this.
  5. volcank

    volcank Serious Boxer

    Joined:
    Oct 8, 2015
    Messages:
    795
    Likes Received:
    393
    Thank you so much now one more thing do I replace that whole code with
    -(void)hideBanner{
    // Remove the banner.
    NSLog(@"[Ads] hide banner");

    }


    Or do I replace the part where it starts with void showbanner options at top. Because in that code it syas Heyzap banner options etc. Do I remove them and replace it with the code you just shared? Thank you @particles
     
  6. particles

    particles Avid Boxer

    Joined:
    Aug 31, 2018
    Messages:
    337
    Likes Received:
    242
    This one is only for AdMob without HeyZap.
     
    volcank likes this.
  7. particles

    particles Avid Boxer

    Joined:
    Aug 31, 2018
    Messages:
    337
    Likes Received:
    242
    If you in discord then I can try to help you by chatting.
     
    volcank likes this.
  8. volcank

    volcank Serious Boxer

    Joined:
    Oct 8, 2015
    Messages:
    795
    Likes Received:
    393
    Oh ok! I was trying to do heyzap sorry :( Any ways of making this with heyzap adintegrator? Anyways sorry for too much bugging in here will try to find a way.
     
  9. particles

    particles Avid Boxer

    Joined:
    Aug 31, 2018
    Messages:
    337
    Likes Received:
    242
    Yes, Can do in similar way for HeyZap too.
     
    volcank likes this.
  10. volcank

    volcank Serious Boxer

    Joined:
    Oct 8, 2015
    Messages:
    795
    Likes Received:
    393
    Yes thank you! Will see what I can do with it!
     
  11. volcank

    volcank Serious Boxer

    Joined:
    Oct 8, 2015
    Messages:
    795
    Likes Received:
    393
    Hi @particles missed this message. Sure I can discord where will I find you? Is there a server you have already? Thank you!
     
    particles likes this.
  12. particles

    particles Avid Boxer

    Joined:
    Aug 31, 2018
    Messages:
    337
    Likes Received:
    242
    Done. See its easier in discord for certain issues.
     
    volcank likes this.
  13. volcank

    volcank Serious Boxer

    Joined:
    Oct 8, 2015
    Messages:
    795
    Likes Received:
    393
    Yes man! Thank you so much for all the help and support!
     
    particles likes this.
  14. itzonator

    itzonator Serious Boxer

    Joined:
    Dec 18, 2017
    Messages:
    595
    Likes Received:
    230
    Well, @particles, @volcank this is not quite a solution for the ads. When replace the ShowBanner and Hide Banner functions, the game crash from this code: https://gist.github.com/skparticles/d0cff5b1495c2701fab4c71bed5e7fe4

    When remove from HideBanner function:

    Code:
      if(self.bannerView)
            [self.bannerView removeFromSuperview];
    Banner is showing everywhere, including the Game UI

    @particles, can you share the entire AdIntegrator.mm code, not only Show Banner and HideBanner functions?

    Here's my code:
    [This code below shows the banner at the beginning, but as soon as the game ends on Game Over banner is removed forever. So the banner shows just the beginning and that's it. I'd like to show the banner on menus, not on Game UI]

    Code:
    #import "AdIntegrator.h"
    //@import GoogleMobileAds;
    #import "GoogleMobileAds/GoogleMobileAds.h"
    
    
    static NSString *AD_APPLICATION_ID = @"XXXXXXXXXXX";
    static NSString *BANNER_LIVE_ID =  @"XXXXXXXX";
    static NSString *INTERSTIAL_LIVE_ID = @"XXXXxxxxxxxxx";
    static NSString *TEST_DEVICE = @"XXXXX" ;
    
    @interface AdIntegrator()<GADBannerViewDelegate,GADInterstitialDelegate>
    
    @property(nonatomic, strong) id<UILayoutSupport> bottomLayoutGuide;
    @end
    
    
    @implementation AdIntegrator
    
    
    + (id)shared{
        static AdIntegrator* integrator = nil;
        @synchronized(self){
            if(integrator == nil){
                integrator = [[self alloc] init];
            }
        }
        return integrator;
    }
    
    #pragma mark Core Methods
    
    - (void)initAds{
    
    
        [GADMobileAds configureWithApplicationID:AD_APPLICATION_ID];
        self.interstitial = [self createAndLoadInterstitial];
    
    
        NSLog(@"[Ads] initialization");
    }
    
    - (GADInterstitial *)createAndLoadInterstitial {
        GADInterstitial *interstitial;
        NSString *adId = INTERSTIAL_LIVE_ID;
        interstitial = [[GADInterstitial alloc]
                        initWithAdUnitID:adId];
    
        GADRequest *interstitialRequest = [GADRequest request];
        interstitialRequest.testDevices = @[TEST_DEVICE];
        [interstitial loadRequest:interstitialRequest];
        interstitial.delegate = self;
        [interstitial loadRequest:[GADRequest request]];
        return interstitial;
    }
    
    
    -(void)showInterstitialAdmob{
        if (self.interstitial.isReady) {
            [self.interstitial presentFromRootViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
        } else {
            NSLog(@"Ad wasn't ready");
        }
    }
    
    
    -(void)showBanner{
    
        UIView *view = [UIApplication sharedApplication].keyWindow.rootViewController.view;
    
        if(self.bannerView)
        {
            return;
        }
        self.bottomLayoutGuide = [UIApplication sharedApplication].keyWindow.rootViewController.bottomLayoutGuide;
        self.bannerView = [[GADBannerView alloc]
                           initWithAdSize:kGADAdSizeBanner];
    
        self.bannerView.translatesAutoresizingMaskIntoConstraints = NO;
        [view addSubview:self.bannerView];
        [view addConstraints:@[
                               [NSLayoutConstraint constraintWithItem:self.bannerView
                                                            attribute:NSLayoutAttributeBottom
                                                            relatedBy:NSLayoutRelationEqual
                                                               toItem:self.bottomLayoutGuide
                                                            attribute:NSLayoutAttributeTop
                                                           multiplier:1
                                                             constant:0],
                               [NSLayoutConstraint constraintWithItem:self.bannerView
                                                            attribute:NSLayoutAttributeCenterX
                                                            relatedBy:NSLayoutRelationEqual
                                                               toItem:view
                                                            attribute:NSLayoutAttributeCenterX
                                                           multiplier:1
                                                             constant:0]
                               ]];
        self.bannerView.adUnitID = @"xxxxxxxxxxxxxx";
        self.bannerView.rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
        [self.bannerView loadRequest:[GADRequest request]];
    
    
        NSLog(@"[Ads] show banner");
    }
    
    -(void)hideBanner{
        NSLog(@"[Ads] hide banner");
        if(self.bannerView)
            [self.bannerView removeFromSuperview];
    
    }
    
    
    
    
    -(bool)isBannerVisible{
        return true;
    }
    
    -(bool)isRewardedVideoAvialable{
        return true;
    }
    
    -(void)showInterstitial{
    
        [self showInterstitialAdmob];
        NSLog(@"[Ads] show interstitial");
    }
    
    /// Tells the delegate the interstitial had been animated off the screen.
    - (void)interstitialDidDismissScreen:(GADInterstitial *)ad {
        NSLog(@"interstitialDidDismissScreen");
        self.interstitial = [self createAndLoadInterstitial];
    }
    /// Tells the delegate an ad request succeeded.
    - (void)interstitialDidReceiveAd:(GADInterstitial *)ad {
        NSLog(@"interstitialDidReceiveAd");
    }
    
    /// Tells the delegate an ad request failed.
    - (void)interstitial:(GADInterstitial *)ad
    didFailToReceiveAdWithError:(GADRequestError *)error {
        NSLog(@"interstitial:didFailToReceiveAdWithError: %@", [error localizedDescription]);
    }
    
    /// Tells the delegate that an interstitial will be presented.
    - (void)interstitialWillPresentScreen:(GADInterstitial *)ad {
        NSLog(@"interstitialWillPresentScreen");
    }
    
    /// Tells the delegate the interstitial is to be animated off the screen.
    - (void)interstitialWillDismissScreen:(GADInterstitial *)ad {
        NSLog(@"interstitialWillDismissScreen");
    }
    
    /// Tells the delegate that a user click will open another app
    /// (such as the App Store), backgrounding the current app.
    - (void)interstitialWillLeaveApplication:(GADInterstitial *)ad {
        NSLog(@"interstitialWillLeaveApplication");
    }
    /// Tells the delegate an ad request loaded an ad.
    - (void)adViewDidReceiveAd:(GADBannerView *)adView {
        NSLog(@"adViewDidReceiveAd");
    }
    
    /// Tells the delegate an ad request failed.
    - (void)adView:(GADBannerView *)adView
    didFailToReceiveAdWithError:(GADRequestError *)error {
        NSLog(@"adView:didFailToReceiveAdWithError: %@", [error localizedDescription]);
    }
    
    /// Tells the delegate that a full-screen view will be presented in response
    /// to the user clicking on an ad.
    - (void)adViewWillPresentScreen:(GADBannerView *)adView {
        NSLog(@"adViewWillPresentScreen");
    }
    
    /// Tells the delegate that the full-screen view will be dismissed.
    - (void)adViewWillDismissScreen:(GADBannerView *)adView {
        NSLog(@"adViewWillDismissScreen");
    }
    
    /// Tells the delegate that the full-screen view has been dismissed.
    - (void)adViewDidDismissScreen:(GADBannerView *)adView {
        NSLog(@"adViewDidDismissScreen");
    }
    
    /// Tells the delegate that a user click will open another app (such as
    /// the App Store), backgrounding the current app.
    - (void)adViewWillLeaveApplication:(GADBannerView *)adView {
        NSLog(@"adViewWillLeaveApplication");
    }
    
    
    
    
    
    -(void)showRewardedVideo{
        NSLog(@"[Ads] show rewarded video");
    }
    
    -(void)buttonActivated:(NSString*) name{
    
    
    
    }
    -(bool)buttonVisible:(NSString*)name{
        return true;
    }
    #pragma mark Integration
    
    @end
    

    WITH THIS CODE BELOW, Game Crash:

    Code:
    #import "AdIntegrator.h"
    //@import GoogleMobileAds;
    #import "GoogleMobileAds/GoogleMobileAds.h"
    
    
    static NSString *AD_APPLICATION_ID = @"xxxxxxxxx";
    static NSString *BANNER_LIVE_ID =  @"xxxxxxxxx";
    static NSString *INTERSTIAL_LIVE_ID = @"xxxxxxxx";
    static NSString *TEST_DEVICE = @"XXXXX" ;
    
    @interface AdIntegrator()<GADBannerViewDelegate,GADInterstitialDelegate>
    
    @property(nonatomic, strong) id<UILayoutSupport> bottomLayoutGuide;
    @end
    
    
    @implementation AdIntegrator
    
    
    + (id)shared{
        static AdIntegrator* integrator = nil;
        @synchronized(self){
            if(integrator == nil){
                integrator = [[self alloc] init];
            }
        }
        return integrator;
    }
    
    #pragma mark Core Methods
    
    - (void)initAds{
    
    
        [GADMobileAds configureWithApplicationID:AD_APPLICATION_ID];
        self.interstitial = [self createAndLoadInterstitial];
    
    
        NSLog(@"[Ads] initialization");
    }
    
    - (GADInterstitial *)createAndLoadInterstitial {
        GADInterstitial *interstitial;
        NSString *adId = INTERSTIAL_LIVE_ID;
        interstitial = [[GADInterstitial alloc]
                        initWithAdUnitID:adId];
    
        GADRequest *interstitialRequest = [GADRequest request];
        interstitialRequest.testDevices = @[TEST_DEVICE];
        [interstitial loadRequest:interstitialRequest];
        interstitial.delegate = self;
        [interstitial loadRequest:[GADRequest request]];
        return interstitial;
    }
    
    
    -(void)showInterstitialAdmob{
        if (self.interstitial.isReady) {
            [self.interstitial presentFromRootViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
        } else {
            NSLog(@"Ad wasn't ready");
        }
    }
    
    -(void)showBanner{
        UIView *view = [UIApplication sharedApplication].keyWindow.rootViewController.view;
        if(!self.bannerView)
        {
            self.bottomLayoutGuide = [UIApplication sharedApplication].keyWindow.rootViewController.bottomLayoutGuide;
            self.bannerView = [[GADBannerView alloc]
                               initWithAdSize:kGADAdSizeBanner];
            self.bannerView.translatesAutoresizingMaskIntoConstraints = NO;
            [view addConstraints:@[
                                   [NSLayoutConstraint constraintWithItem:self.bannerView
                                                                attribute:NSLayoutAttributeBottom
                                                                relatedBy:NSLayoutRelationEqual
                                                                   toItem:self.bottomLayoutGuide
                                                                attribute:NSLayoutAttributeTop
                                                               multiplier:1
                                                                 constant:0],
                                   [NSLayoutConstraint constraintWithItem:self.bannerView
                                                                attribute:NSLayoutAttributeCenterX
                                                                relatedBy:NSLayoutRelationEqual
                                                                   toItem:view
                                                                attribute:NSLayoutAttributeCenterX
                                                               multiplier:1
                                                                 constant:0]
                                   ]];
            self.bannerView.adUnitID = xxxxxxxx;
            self.bannerView.rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
        }
        [self.bannerView loadRequest:[GADRequest request]];
        [view addSubview:self.bannerView];
    }
    -(void)hideBanner{
        NSLog(@"[Ads] hide banner");
        if(self.bannerView)
            [self.bannerView removeFromSuperview];
    }
    
    
    
    -(bool)isBannerVisible{
        return true;
    }
    
    -(bool)isRewardedVideoAvialable{
        return true;
    }
    
    -(void)showInterstitial{
    
        [self showInterstitialAdmob];
        NSLog(@"[Ads] show interstitial");
    }
    
    /// Tells the delegate the interstitial had been animated off the screen.
    - (void)interstitialDidDismissScreen:(GADInterstitial *)ad {
        NSLog(@"interstitialDidDismissScreen");
        self.interstitial = [self createAndLoadInterstitial];
    }
    /// Tells the delegate an ad request succeeded.
    - (void)interstitialDidReceiveAd:(GADInterstitial *)ad {
        NSLog(@"interstitialDidReceiveAd");
    }
    
    /// Tells the delegate an ad request failed.
    - (void)interstitial:(GADInterstitial *)ad
    didFailToReceiveAdWithError:(GADRequestError *)error {
        NSLog(@"interstitial:didFailToReceiveAdWithError: %@", [error localizedDescription]);
    }
    
    /// Tells the delegate that an interstitial will be presented.
    - (void)interstitialWillPresentScreen:(GADInterstitial *)ad {
        NSLog(@"interstitialWillPresentScreen");
    }
    
    /// Tells the delegate the interstitial is to be animated off the screen.
    - (void)interstitialWillDismissScreen:(GADInterstitial *)ad {
        NSLog(@"interstitialWillDismissScreen");
    }
    
    /// Tells the delegate that a user click will open another app
    /// (such as the App Store), backgrounding the current app.
    - (void)interstitialWillLeaveApplication:(GADInterstitial *)ad {
        NSLog(@"interstitialWillLeaveApplication");
    }
    /// Tells the delegate an ad request loaded an ad.
    - (void)adViewDidReceiveAd:(GADBannerView *)adView {
        NSLog(@"adViewDidReceiveAd");
    }
    
    /// Tells the delegate an ad request failed.
    - (void)adView:(GADBannerView *)adView
    didFailToReceiveAdWithError:(GADRequestError *)error {
        NSLog(@"adView:didFailToReceiveAdWithError: %@", [error localizedDescription]);
    }
    
    /// Tells the delegate that a full-screen view will be presented in response
    /// to the user clicking on an ad.
    - (void)adViewWillPresentScreen:(GADBannerView *)adView {
        NSLog(@"adViewWillPresentScreen");
    }
    
    /// Tells the delegate that the full-screen view will be dismissed.
    - (void)adViewWillDismissScreen:(GADBannerView *)adView {
        NSLog(@"adViewWillDismissScreen");
    }
    
    /// Tells the delegate that the full-screen view has been dismissed.
    - (void)adViewDidDismissScreen:(GADBannerView *)adView {
        NSLog(@"adViewDidDismissScreen");
    }
    
    /// Tells the delegate that a user click will open another app (such as
    /// the App Store), backgrounding the current app.
    - (void)adViewWillLeaveApplication:(GADBannerView *)adView {
        NSLog(@"adViewWillLeaveApplication");
    }
    
    
    
    
    
    -(void)showRewardedVideo{
        NSLog(@"[Ads] show rewarded video");
    }
    
    -(void)buttonActivated:(NSString*) name{
    
    
    
    }
    -(bool)buttonVisible:(NSString*)name{
        return true;
    }
    #pragma mark Integration
    
    @end
    
     

    Attached Files:

    Last edited: May 7, 2019
  15. particles

    particles Avid Boxer

    Joined:
    Aug 31, 2018
    Messages:
    337
    Likes Received:
    242
  16. itzonator

    itzonator Serious Boxer

    Joined:
    Dec 18, 2017
    Messages:
    595
    Likes Received:
    230
  17. Karim MS

    Karim MS Boxer

    Joined:
    Mar 20, 2020
    Messages:
    5
    Likes Received:
    5
    particles likes this.
  18. particles

    particles Avid Boxer

    Joined:
    Aug 31, 2018
    Messages:
    337
    Likes Received:
    242
    Hi @Karim MS , I haven't touch any of the mediation tools after that. Once I free, will try to do.
     
    Karim MS likes this.

Share This Page