97 lines
2.6 KiB
Objective-C
97 lines
2.6 KiB
Objective-C
//
|
|
// EQNBaseViewController.m
|
|
// Earthquake Network
|
|
//
|
|
// Created by Busi Andrea on 16/08/2020.
|
|
// Copyright © 2020 Earthquake Network. All rights reserved.
|
|
//
|
|
|
|
#import "EQNBaseViewController.h"
|
|
@import GoogleMobileAds;
|
|
|
|
@interface EQNBaseViewController ()
|
|
@property (weak, nonatomic) IBOutlet UIView *bannerContainerView;
|
|
@property (strong, nonatomic) GADBannerView *bannerView;
|
|
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bannerContainerHeightConstraint;
|
|
@end
|
|
|
|
@implementation EQNBaseViewController
|
|
|
|
#pragma mark - View Lifecycle
|
|
|
|
- (void)viewDidLoad
|
|
{
|
|
[super viewDidLoad];
|
|
|
|
[self addBannerView];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
selector:@selector(didReceiveInAppNotification:)
|
|
name:IAPHelperPurchaseNotification object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
selector:@selector(didReceiveDownloadCompleteNotification:)
|
|
name:EQNNotificationDidDownloadData object:nil];
|
|
|
|
}
|
|
|
|
#pragma mark - Public
|
|
|
|
- (void)refreshUI
|
|
{
|
|
// nope
|
|
}
|
|
|
|
#pragma mark - Notification
|
|
|
|
- (void)didReceiveInAppNotification:(NSNotification *)notification
|
|
{
|
|
[self.bannerView removeFromSuperview];
|
|
self.bannerView = nil;
|
|
self.bannerContainerHeightConstraint.constant = 0;
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
[self refreshUI];
|
|
});
|
|
}
|
|
|
|
- (void)didReceiveDownloadCompleteNotification:(NSNotification *)notification
|
|
{
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
[self refreshUI];
|
|
});
|
|
}
|
|
|
|
#pragma mark - Private
|
|
|
|
- (void)addBannerView
|
|
{
|
|
self.bannerView = [self createBannerView];
|
|
if (self.bannerView == nil) {
|
|
self.bannerContainerHeightConstraint.constant = 0;
|
|
return;
|
|
}
|
|
|
|
self.bannerView.translatesAutoresizingMaskIntoConstraints = NO;
|
|
[self.view addSubview:self.bannerView];
|
|
|
|
[[self.bannerView.centerXAnchor constraintEqualToAnchor:self.bannerContainerView.centerXAnchor] setActive:YES];
|
|
[[self.bannerView.bottomAnchor constraintEqualToAnchor:self.bannerContainerView.safeAreaLayoutGuide.bottomAnchor] setActive:YES];
|
|
}
|
|
|
|
- (GADBannerView *)createBannerView
|
|
{
|
|
if ([EQNPurchaseUtility isProVersionEnabled]) {
|
|
return nil;
|
|
}
|
|
|
|
GADBannerView *bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
|
|
bannerView.adUnitID = EQN_ADMOB_ANNUNCIO_IDA;
|
|
bannerView.rootViewController = self;
|
|
bannerView.backgroundColor = [UIColor whiteColor];
|
|
[bannerView loadRequest:[GADRequest request]];
|
|
return bannerView;
|
|
}
|
|
|
|
@end
|