Skip to content

Commit

Permalink
Fixed AppOpen auto closing on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Astrovic committed Oct 14, 2023
1 parent dadd863 commit d4ad124
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 11 deletions.
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
24 changes: 17 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,11 +324,17 @@ - (void)showAppOpenAd

if (canPresent) {
_isShowingAd = YES;
//[appOpenAd presentFromRootViewController:[[[TiApp app] controller] topPresentedController]];
// 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];
[appOpenAd presentFromRootViewController:rootViewController];

rootViewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
[rootViewController presentViewController:adViewController animated:YES completion:nil];
} else {
NSLog(@"[WARN] Cannot show App Open ad: %@", error.localizedDescription);
[self.proxy fireEvent:@"didFailToShowAd" withObject:@{ @"adUnitId" : adUnitId, @"error": error.localizedDescription }];
Expand Down Expand Up @@ -485,10 +494,11 @@ - (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 }];
}

@end
@end
11 changes: 8 additions & 3 deletions ios/admob.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
3AF5B7731C233383002E3DC7 /* TiAdmobTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 3AF5B7711C233383002E3DC7 /* TiAdmobTypes.h */; };
5E0B17A527F21AED001D0BD9 /* File.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E0B17A427F21AED001D0BD9 /* File.swift */; };
5E343CDF291BFA3600F047EB /* MetaAdapter.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E343CDE291BFA3600F047EB /* MetaAdapter.xcframework */; };
5E58AD4E2ADAE76000C78E7F /* StatusBarHiddenViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 5E58AD4C2ADAE76000C78E7F /* StatusBarHiddenViewController.h */; };
5E58AD4F2ADAE76000C78E7F /* StatusBarHiddenViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E58AD4D2ADAE76000C78E7F /* StatusBarHiddenViewController.m */; };
5E6743A427F4B84500BEE594 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E6743A327F4B84500BEE594 /* WebKit.framework */; };
5E6743A627F4B85800BEE594 /* libsqlite3.0.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E6743A527F4B85800BEE594 /* libsqlite3.0.tbd */; };
5E6743A827F4B86A00BEE594 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E6743A727F4B86A00BEE594 /* libz.tbd */; };
5E6743AE27F4BEA300BEE594 /* GoogleAppMeasurementIdentitySupport.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E6743AD27F4BEA300BEE594 /* GoogleAppMeasurementIdentitySupport.xcframework */; };

5ED7B66026EBC395007F4D90 /* FBAudienceNetwork.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5ED7B65F26EBC395007F4D90 /* FBAudienceNetwork.xcframework */; };
5EFC8F50263ABC430011A0C2 /* InMobiSDK.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5EFC8F4C263ABC430011A0C2 /* InMobiSDK.xcframework */; };
5EFC8F51263ABC430011A0C2 /* InMobiAdapter.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5EFC8F4D263ABC430011A0C2 /* InMobiAdapter.xcframework */; };
Expand All @@ -51,11 +52,12 @@
5E0B17A327F21AED001D0BD9 /* admob-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "admob-Bridging-Header.h"; sourceTree = "<group>"; };
5E0B17A427F21AED001D0BD9 /* File.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = File.swift; sourceTree = "<group>"; };
5E343CDE291BFA3600F047EB /* MetaAdapter.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = MetaAdapter.xcframework; path = platform/MetaAdapter.xcframework; sourceTree = "<group>"; };
5E58AD4C2ADAE76000C78E7F /* StatusBarHiddenViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StatusBarHiddenViewController.h; path = Classes/StatusBarHiddenViewController.h; sourceTree = "<group>"; };
5E58AD4D2ADAE76000C78E7F /* StatusBarHiddenViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = StatusBarHiddenViewController.m; path = Classes/StatusBarHiddenViewController.m; sourceTree = "<group>"; };
5E6743A327F4B84500BEE594 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/System/iOSSupport/System/Library/Frameworks/WebKit.framework; sourceTree = DEVELOPER_DIR; };
5E6743A527F4B85800BEE594 /* libsqlite3.0.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.0.tbd; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib/libsqlite3.0.tbd; sourceTree = DEVELOPER_DIR; };
5E6743A727F4B86A00BEE594 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib/libz.tbd; sourceTree = DEVELOPER_DIR; };
5E6743AD27F4BEA300BEE594 /* GoogleAppMeasurementIdentitySupport.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = GoogleAppMeasurementIdentitySupport.xcframework; path = platform/GoogleAppMeasurementIdentitySupport.xcframework; sourceTree = "<group>"; };

5ED7B65F26EBC395007F4D90 /* FBAudienceNetwork.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = FBAudienceNetwork.xcframework; path = platform/FBAudienceNetwork.xcframework; sourceTree = "<group>"; };
5EFC8F4C263ABC430011A0C2 /* InMobiSDK.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = InMobiSDK.xcframework; path = platform/InMobiSDK.xcframework; sourceTree = "<group>"; };
5EFC8F4D263ABC430011A0C2 /* InMobiAdapter.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = InMobiAdapter.xcframework; path = platform/InMobiAdapter.xcframework; sourceTree = "<group>"; };
Expand Down Expand Up @@ -112,7 +114,6 @@
0867D69AFE84028FC02AAC07 /* Frameworks */ = {
isa = PBXGroup;
children = (

5E343CDE291BFA3600F047EB /* MetaAdapter.xcframework */,
5E6743A727F4B86A00BEE594 /* libz.tbd */,
5E6743A527F4B85800BEE594 /* libsqlite3.0.tbd */,
Expand All @@ -134,6 +135,8 @@
08FB77AEFE84172EC02AAC07 /* Classes */ = {
isa = PBXGroup;
children = (
5E58AD4C2ADAE76000C78E7F /* StatusBarHiddenViewController.h */,
5E58AD4D2ADAE76000C78E7F /* StatusBarHiddenViewController.m */,
24DD6CF71134B3F500162E58 /* TiAdmobModule.h */,
24DD6CF81134B3F500162E58 /* TiAdmobModule.m */,
249BE66D11B47B2700AF41CF /* TiAdmobViewProxy.h */,
Expand Down Expand Up @@ -164,6 +167,7 @@
AA747D9F0F9514B9006C5449 /* TiAdmob_Prefix.pch in Headers */,
24DD6CF91134B3F500162E58 /* TiAdmobModule.h in Headers */,
249BE66F11B47B2700AF41CF /* TiAdmobViewProxy.h in Headers */,
5E58AD4E2ADAE76000C78E7F /* StatusBarHiddenViewController.h in Headers */,
3AF5B7731C233383002E3DC7 /* TiAdmobTypes.h in Headers */,
249BE67311B47B3800AF41CF /* TiAdmobView.h in Headers */,
);
Expand Down Expand Up @@ -225,6 +229,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
5E58AD4F2ADAE76000C78E7F /* StatusBarHiddenViewController.m in Sources */,
24DD6CFA1134B3F500162E58 /* TiAdmobModule.m in Sources */,
5E0B17A527F21AED001D0BD9 /* File.swift in Sources */,
249BE67011B47B2700AF41CF /* TiAdmobViewProxy.m in Sources */,
Expand Down
3 changes: 3 additions & 0 deletions ios/documentation/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

### v6.3.1
- Fixed AppOpen auto closing on iOS

### v6.3.0
- Added iphone methods `isGDPR()`, `canShowAds()`, `canShowPersonalizedAds()`
- Update Google Mobile Ads SDK 10.12.0 (https://github.com/CocoaPods/Specs/tree/master/Specs/5/9/a/Google-Mobile-Ads-SDK/10.12.0)
Expand Down
2 changes: 1 addition & 1 deletion ios/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 6.3.0
version: 6.3.1
architectures: arm64 x86_64
mac: false
description: AdMob module for ad delivery via AdMob
Expand Down

0 comments on commit d4ad124

Please sign in to comment.