Skip to content

Commit 7e00b0d

Browse files
authored
Fullscreen close button (#663)
* Hide status bar when showing full screen ad on iOS. Fix for #191
1 parent ef8df97 commit 7e00b0d

File tree

5 files changed

+51
-15
lines changed

5 files changed

+51
-15
lines changed

.github/workflows/google_mobile_ads.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
cd packages/google_mobile_ads/ios
6868
pod lib lint --allow-warnings
6969
env:
70-
DEVELOPER_DIR: /Applications/Xcode_13.4.1.app/Contents/Developer
70+
DEVELOPER_DIR: /Applications/Xcode_14.0.1.app/Contents/Developer
7171

7272
flutter:
7373
runs-on: ubuntu-latest

.github/workflows/scripts/build-example.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ fi
3232

3333
if [ "$ACTION" == "ios" ]
3434
then
35+
flutter pub get;
36+
pod repo update;
3537
melos exec -c 1 --scope="$GOOGLEMOBILEADS_PLUGIN_SCOPE_EXAMPLE" -- \
3638
flutter build ios --no-codesign --simulator --debug --target="$TARGET_FILE" --dart-define=CI=true
3739
exit

packages/google_mobile_ads/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* adSourceInstanceId
77
* adSourceInstanceName
88
* adSourceName
9+
* Fixes [close button issue on iOS](https://github.com/googleads/googleads-mobile-flutter/issues/191)
910
## 2.0.1
1011
* Bug fix for [issue 580](https://github.com/googleads/googleads-mobile-flutter/issues/580).
1112
Adds a workaround on Android to wait for the ad widget to become visible

packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,9 @@ - (void)adView:(nonnull GADBannerView *)banner
591591

592592
#pragma mark - FLTFullScreenAd
593593

594-
@implementation FLTFullScreenAd
594+
@implementation FLTFullScreenAd {
595+
BOOL _statusBarVisibilityBeforeAdShow;
596+
}
595597

596598
@synthesize manager;
597599

@@ -616,6 +618,14 @@ - (void)ad:(nonnull id<GADFullScreenPresentingAd>)ad
616618

617619
- (void)adWillPresentFullScreenContent:
618620
(nonnull id<GADFullScreenPresentingAd>)ad {
621+
// Manually hide the status bar. This is a fix for
622+
// https://github.com/googleads/googleads-mobile-flutter/issues/191
623+
#pragma clang diagnostic push
624+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
625+
_statusBarVisibilityBeforeAdShow =
626+
UIApplication.sharedApplication.statusBarHidden;
627+
[UIApplication.sharedApplication setStatusBarHidden:YES];
628+
#pragma clang diagnostic pop
619629
[manager adWillPresentFullScreenContent:self];
620630
}
621631

@@ -626,6 +636,11 @@ - (void)adDidDismissFullScreenContent:
626636

627637
- (void)adWillDismissFullScreenContent:
628638
(nonnull id<GADFullScreenPresentingAd>)ad {
639+
#pragma clang diagnostic push
640+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
641+
[UIApplication.sharedApplication
642+
setStatusBarHidden:_statusBarVisibilityBeforeAdShow];
643+
#pragma clang diagnostic pop
629644
[manager adWillDismissFullScreenContent:self];
630645
}
631646

packages/google_mobile_ads/ios/Tests/FLTRewardedAdTest.m

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,11 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request
7171
});
7272
// Stub setting of FullScreenContentDelegate to invoke delegate callbacks.
7373
NSError *error = OCMClassMock([NSError class]);
74+
__block id<GADFullScreenContentDelegate> fullScreenContentDelegate;
7475
OCMStub([rewardedClassMock setFullScreenContentDelegate:[OCMArg any]])
7576
.andDo(^(NSInvocation *invocation) {
76-
id<GADFullScreenContentDelegate> delegate;
77-
[invocation getArgument:&delegate atIndex:2];
78-
XCTAssertEqual(delegate, ad);
79-
[delegate adDidRecordImpression:rewardedClassMock];
80-
[delegate adDidRecordClick:rewardedClassMock];
81-
[delegate adDidDismissFullScreenContent:rewardedClassMock];
82-
[delegate adWillPresentFullScreenContent:rewardedClassMock];
83-
[delegate adWillDismissFullScreenContent:rewardedClassMock];
84-
[delegate ad:rewardedClassMock
85-
didFailToPresentFullScreenContentWithError:error];
77+
[invocation getArgument:&fullScreenContentDelegate atIndex:2];
78+
XCTAssertEqual(fullScreenContentDelegate, ad);
8679
});
8780
GADResponseInfo *responseInfo = OCMClassMock([GADResponseInfo class]);
8881
OCMStub([rewardedClassMock responseInfo]).andReturn(responseInfo);
@@ -110,6 +103,12 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request
110103
handler(adValue);
111104
return YES;
112105
}]]);
106+
107+
// Setup mock for UIApplication.sharedInstance
108+
id uiApplicationClassMock = OCMClassMock([UIApplication class]);
109+
OCMStub(ClassMethod([uiApplicationClassMock sharedApplication]))
110+
.andReturn(uiApplicationClassMock);
111+
113112
// Call load and check expected interactions with mocks.
114113
[ad load];
115114

@@ -154,12 +153,31 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request
154153
presentFromRootViewController:[OCMArg isEqual:mockRootViewController]
155154
userDidEarnRewardHandler:[OCMArg any]]);
156155

157-
// Verify full screen callbacks.
156+
[fullScreenContentDelegate adWillPresentFullScreenContent:rewardedClassMock];
158157
OCMVerify([mockManager adWillPresentFullScreenContent:[OCMArg isEqual:ad]]);
159-
OCMVerify([mockManager adDidDismissFullScreenContent:[OCMArg isEqual:ad]]);
160-
OCMVerify([mockManager adWillDismissFullScreenContent:[OCMArg isEqual:ad]]);
158+
// Verify that we hide status bar
159+
#pragma clang diagnostic push
160+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
161+
OCMVerify([uiApplicationClassMock setStatusBarHidden:YES]);
162+
#pragma clang diagnostic pop
163+
164+
[fullScreenContentDelegate adDidRecordImpression:rewardedClassMock];
161165
OCMVerify([mockManager adDidRecordImpression:[OCMArg isEqual:ad]]);
166+
167+
[fullScreenContentDelegate adDidRecordClick:rewardedClassMock];
162168
OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:ad]]);
169+
170+
[fullScreenContentDelegate adDidDismissFullScreenContent:rewardedClassMock];
171+
OCMVerify([mockManager adDidDismissFullScreenContent:[OCMArg isEqual:ad]]);
172+
173+
[fullScreenContentDelegate adWillDismissFullScreenContent:rewardedClassMock];
174+
OCMVerify([mockManager adWillDismissFullScreenContent:[OCMArg isEqual:ad]]);
175+
#pragma clang diagnostic push
176+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
177+
OCMVerify([uiApplicationClassMock setStatusBarHidden:NO]);
178+
#pragma clang diagnostic pop
179+
180+
[ad ad:rewardedClassMock didFailToPresentFullScreenContentWithError:error];
163181
OCMVerify([mockManager
164182
didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad]
165183
error:[OCMArg isEqual:error]]);

0 commit comments

Comments
 (0)