Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed AppOpen auto closing on iOS #354

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 8 additions & 0 deletions ios/Classes/StatusBarHiddenViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#import <UIKit/UIKit.h>
#import <GoogleMobileAds/GoogleMobileAds.h>

@interface StatusBarHiddenViewController : UIViewController

@property (nonatomic, strong) GADAppOpenAd *ad;

@end
16 changes: 16 additions & 0 deletions ios/Classes/StatusBarHiddenViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#import "StatusBarHiddenViewController.h"

@implementation StatusBarHiddenViewController

- (BOOL)prefersStatusBarHidden {
return YES;
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];

// Present the ad here
[self.ad presentFromRootViewController:self];
}

@end
31 changes: 31 additions & 0 deletions ios/Classes/TiAdmobModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#import "TiHost.h"
#import "TiUtils.h"

#import <AdColonyAdapter/AdColonyAdapter.h>

#import <MTGSDK/MTGSDK.h>

#import <GoogleMobileAds/GoogleMobileAds.h>
//#import <PersonalizedAdConsent/PersonalizedAdConsent.h>
#import <UserMessagingPlatform/UserMessagingPlatform.h>
Expand Down Expand Up @@ -52,6 +56,7 @@ - (NSString *)moduleId
* Inspired by @bocops code: https://github.com/bocops/UMP-workarounds/blob/main/detect_outdated_consent/android/java/detect_outdated_consent.java
*/
- (void)deleteTCStringIfOutdated {

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

// IABTCF string is stored in userDefaults
Expand Down Expand Up @@ -385,6 +390,32 @@ - (void)setInMobi_updateGDPRConsent:(id)updateGDPRConsent
[GADMInMobiConsent updateGDPRConsent:consentObject];
}

-(void)setConsentMediations:(id)mediationsConsentEnabled
{
ENSURE_TYPE(mediationsConsentEnabled, NSNumber);
AdColonyAppOptions *options = GADMediationAdapterAdColony.appOptions;

if ([TiUtils boolValue:mediationsConsentEnabled]) {

[options setPrivacyFrameworkOfType:ADC_CCPA isRequired:YES];
[options setPrivacyConsentString:@"1" forType:ADC_CCPA];

[[MTGSDK sharedInstance] setConsentStatus:YES];
[[MTGSDK sharedInstance] setDoNotTrackStatus:NO];

NSLog(@"[DEBUG] Ti.AdMob: setConsentMediations --> true");
} else {

[options setPrivacyFrameworkOfType:ADC_CCPA isRequired:NO];
[options setPrivacyConsentString:@"1" forType:ADC_CCPA];

[[MTGSDK sharedInstance] setConsentStatus:NO];
[[MTGSDK sharedInstance] setDoNotTrackStatus:YES];

NSLog(@"[DEBUG] Ti.AdMob: setConsentMediations --> false");
}
}

#pragma mark Constants

MAKE_SYSTEM_PROP(TRACKING_AUTHORIZATION_STATUS_NOT_DETERMINED, 0);
Expand Down
24 changes: 24 additions & 0 deletions ios/Classes/TiAdmobModuleAssets.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* This is a generated file. Do not edit or your changes will be lost
*/
#import "TiAdmobModuleAssets.h"

extern NSData* filterDataInRange(NSData* thedata, NSRange range);

@implementation TiAdmobModuleAssets

- (NSData *)moduleAsset
{


return nil;
}

- (NSData *)resolveModuleAsset:(NSString *)path
{


return nil;
}

@end
27 changes: 20 additions & 7 deletions ios/Classes/TiAdmobView.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#import "TiApp.h"
#import "TiUtils.h"

#import "StatusBarHiddenViewController.h"

@implementation TiAdmobView {
BOOL _isLoadingAd;
BOOL _isShowingAd;
Expand Down Expand Up @@ -294,6 +296,7 @@ - (void)requestAppOpenAd
}];
}

StatusBarHiddenViewController *adViewController;
- (void)showAppOpenAd
{
// If the app open ad is already showing, do not show the ad again.
Expand All @@ -310,7 +313,7 @@ - (void)showAppOpenAd

// If the app open ad is not available yet, invoke the callback then load the ad.
if (![self isAdAvailable]) {
NSLog(@"[ERROR] The App Open Ad is not available. Did you call load() method?");
NSLog(@"[ERROR] The App Open Ad is not available. Did you call load() method?");
[self.proxy fireEvent:@"didFailToReceiveAd" withObject:@{ @"adUnitId" : adUnitId, @"error": [NSString stringWithFormat:@"The App Open Ad is not available. Did you call load() method?"]}];
appOpenAd = nil;
return;
Expand All @@ -321,10 +324,19 @@ - (void)showAppOpenAd

if (canPresent) {
_isShowingAd = YES;
//[appOpenAd presentFromRootViewController:[[[TiApp app] controller] topPresentedController]];

UIViewController *rootViewController = [[[TiApp app] controller] topPresentedController];
[appOpenAd presentFromRootViewController:rootViewController];
// Create an instance of StatusBarHiddenViewController
adViewController = [[StatusBarHiddenViewController alloc] init];
adViewController.modalPresentationStyle = UIModalPresentationOverFullScreen;

// Set the ad property
adViewController.ad = appOpenAd;

// Present the ad view controller
UIViewController *rootViewController = [[[TiApp app] controller] topPresentedController];
rootViewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
[rootViewController presentViewController:adViewController animated:YES completion:nil];

[self.proxy fireEvent:@"onAdShowedFullScreenContent" withObject:@{ @"adUnitId": adUnitId }];

} else {
NSLog(@"[WARN] Cannot show App Open ad: %@", error.localizedDescription);
Expand Down Expand Up @@ -485,8 +497,9 @@ - (void)adWillDismissFullScreenContent:(id<GADFullScreenPresentingAd>)ad
- (void)adDidDismissFullScreenContent:(id<GADFullScreenPresentingAd>)ad
{
if ([ad isKindOfClass:[GADAppOpenAd class]]) {
_isShowingAd = NO;
appOpenAd = nil;
[adViewController dismissViewControllerAnimated:YES completion:nil];
_isShowingAd = NO;
appOpenAd = nil;
}
[self.proxy fireEvent:@"didDismissScreen" withObject:@{ @"adUnitId": adUnitId }];
}
Expand Down
Loading