Files
eqn.ios/Sources/Earthquake Network/Models/EQNAdsUtility.m
T
2020-10-15 08:40:03 +02:00

46 lines
1.5 KiB
Objective-C

//
// EQNAdsUtility.m
// Earthquake Network
//
// Created by Busi Andrea on 15/10/2020.
// Copyright © 2020 Earthquake Network. All rights reserved.
//
#import "EQNAdsUtility.h"
@implementation EQNAdsUtility
#pragma mark - Public
+ (GADBannerView *)ottieniBannerWithController:(UIViewController *)controller position:(BOOL)isButton
{
if ([EQNPurchaseUtility isProVersionEnabled]) {
return nil;
}
GADBannerView *bannerView = [[GADBannerView alloc]
initWithAdSize:kGADAdSizeBanner];
bannerView.adUnitID = EQN_ADMOB_ANNUNCIO_IDA;
bannerView.rootViewController = controller;
bannerView.backgroundColor = [UIColor whiteColor];
[bannerView loadRequest:[GADRequest request]];
[self addBanner:bannerView toController:controller isTopAnchored:isButton];
return bannerView;
}
#pragma mark - Private
+ (void)addBanner:(UIView *)bannerView toController:(UIViewController *)controller isTopAnchored:(BOOL)isButton
{
bannerView.translatesAutoresizingMaskIntoConstraints = NO;
[controller.view addSubview:bannerView];
[[bannerView.centerXAnchor constraintEqualToAnchor:controller.view.centerXAnchor] setActive:YES];
NSLayoutAnchor *parentAnchor = isButton ? controller.view.safeAreaLayoutGuide.bottomAnchor : controller.view.safeAreaLayoutGuide.topAnchor;
NSLayoutAnchor *bannerAnchor = isButton ? bannerView.bottomAnchor : bannerView.topAnchor;
[[bannerAnchor constraintEqualToAnchor:parentAnchor] setActive:YES];
}
@end