Skip to content

Commit c7d64ee

Browse files
[firebase_admob] Use instance variables when loading ads (firebase#2382)
1 parent 9c6fb46 commit c7d64ee

File tree

7 files changed

+64
-28
lines changed

7 files changed

+64
-28
lines changed

packages/firebase_admob/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.9.3+2
2+
3+
* Fixed bug related to simultaneous ad loading behavior on iOS.
4+
15
## 0.9.3+1
26

37
* Modified README to reflect supporting Native Ads.

packages/firebase_admob/ios/Classes/FLTMobileAd.m

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@
99
static NSMutableDictionary *allAds = nil;
1010
static NSDictionary *statusToString = nil;
1111

12-
@implementation FLTMobileAd
13-
NSNumber *_mobileAdId;
14-
FlutterMethodChannel *_channel;
15-
FLTMobileAdStatus _status;
16-
double _anchorOffset;
17-
double _horizontalCenterOffset;
18-
int _anchorType;
12+
@implementation FLTMobileAd {
13+
NSNumber *_mobileAdId;
14+
@protected
15+
FlutterMethodChannel *_channel;
16+
FLTMobileAdStatus _status;
17+
double _anchorOffset;
18+
double _horizontalCenterOffset;
19+
int _anchorType;
20+
}
1921

2022
+ (void)initialize {
2123
if (allAds == nil) {
2224
allAds = [[NSMutableDictionary alloc] init];
2325
}
24-
_anchorType = 0;
25-
_anchorOffset = 0;
26-
_horizontalCenterOffset = 0;
2726

2827
if (statusToString == nil) {
2928
statusToString = @{
@@ -169,9 +168,10 @@ - (NSString *)description {
169168
}
170169
@end
171170

172-
@implementation FLTBannerAd
173-
GADBannerView *_banner;
174-
GADAdSize _adSize;
171+
@implementation FLTBannerAd {
172+
GADBannerView *_banner;
173+
GADAdSize _adSize;
174+
}
175175

176176
+ (instancetype)withId:(NSNumber *)mobileAdId
177177
adSize:(GADAdSize)adSize
@@ -238,8 +238,9 @@ - (void)adViewDidReceiveAd:(GADBannerView *)adView {
238238
}
239239
@end
240240

241-
@implementation FLTInterstitialAd
242-
GADInterstitial *_interstitial;
241+
@implementation FLTInterstitialAd {
242+
GADInterstitial *_interstitial;
243+
}
243244

244245
+ (instancetype)withId:(NSNumber *)mobileAdId channel:(FlutterMethodChannel *)channel {
245246
FLTMobileAd *ad = [FLTMobileAd getAdForId:mobileAdId];

packages/firebase_admob/ios/Classes/FLTRequestFactory.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
#import "GoogleMobileAds/GADExtras.h"
88
#import "GoogleMobileAds/GoogleMobileAds.h"
99

10-
@implementation FLTRequestFactory
11-
12-
NSDictionary *_targetingInfo;
10+
@implementation FLTRequestFactory {
11+
NSDictionary *_targetingInfo;
12+
}
1313

1414
- (instancetype)initWithTargetingInfo:(NSDictionary *)targetingInfo {
1515
self = [super init];

packages/firebase_admob/ios/Classes/FLTRewardedVideoAdWrapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// found in the LICENSE file.
44

55
#import <Flutter/Flutter.h>
6-
#import "GoogleMobileAds/GoogleMobileAds.h"
6+
#import <GoogleMobileAds/GoogleMobileAds.h>
77

88
typedef enum : NSUInteger {
99
FLTRewardedVideoAdStatusCreated,

packages/firebase_admob/ios/Classes/FLTRewardedVideoAdWrapper.m

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
@interface FLTRewardedVideoAdWrapper () <GADRewardBasedVideoAdDelegate>
1212
@end
1313

14-
@implementation FLTRewardedVideoAdWrapper
15-
16-
FlutterMethodChannel *_rewardedChannel;
17-
FLTRewardedVideoAdStatus _rewardedStatus;
14+
@implementation FLTRewardedVideoAdWrapper {
15+
FlutterMethodChannel *_rewardedChannel;
16+
FLTRewardedVideoAdStatus _rewardedStatus;
17+
}
1818

1919
+ (void)initialize {
2020
if (rewardedStatusToString == nil) {
@@ -79,10 +79,8 @@ - (NSString *)description {
7979

8080
- (void)rewardBasedVideoAd:(nonnull GADRewardBasedVideoAd *)rewardBasedVideoAd
8181
didRewardUserWithReward:(nonnull GADAdReward *)reward {
82-
NSDictionary *arguments = @{
83-
@"rewardAmount" : [NSNumber numberWithInt:[reward.amount intValue]],
84-
@"rewardType" : reward.type
85-
};
82+
NSDictionary *arguments =
83+
@{@"rewardAmount" : @(reward.amount.intValue), @"rewardType" : reward.type};
8684
[_rewardedChannel invokeMethod:@"onRewarded" arguments:arguments];
8785
}
8886

packages/firebase_admob/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: firebase_admob
22
description: Flutter plugin for Firebase AdMob, supporting
33
banner, interstitial (full-screen), and rewarded video ads
44
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_admob
5-
version: 0.9.3+1
5+
version: 0.9.3+2
66

77
flutter:
88
plugin:

packages/firebase_admob/test/firebase_admob_e2e.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import 'dart:async';
2+
import 'dart:io';
3+
14
import 'package:flutter_test/flutter_test.dart';
25
import 'package:e2e/e2e.dart';
36

@@ -35,4 +38,34 @@ void main() {
3538
await Future<void>.delayed(Duration(seconds: 10));
3639
expect(adLoaded, isTrue);
3740
});
41+
42+
// TODO(bparrishMines): Unskip on Android once tests work on Firebase TestLab.
43+
// See https://github.com/FirebaseExtended/flutterfire/issues/2384
44+
// ignore: missing_return
45+
testWidgets('Load two Ads Simultaneously', (WidgetTester tester) {
46+
final Completer<void> adCompleter1 = Completer<void>();
47+
final Completer<void> adCompleter2 = Completer<void>();
48+
49+
final BannerAd bannerAd1 = BannerAd(
50+
adUnitId: NativeAd.testAdUnitId,
51+
size: AdSize.banner,
52+
listener: (MobileAdEvent event) {
53+
if (event == MobileAdEvent.loaded) adCompleter1.complete();
54+
},
55+
);
56+
57+
final BannerAd bannerAd2 = BannerAd(
58+
adUnitId: NativeAd.testAdUnitId,
59+
size: AdSize.banner,
60+
listener: (MobileAdEvent event) {
61+
if (event == MobileAdEvent.loaded) adCompleter1.complete();
62+
},
63+
);
64+
65+
bannerAd1.load();
66+
bannerAd2.load();
67+
68+
expect(adCompleter1.future, completes);
69+
expect(adCompleter2.future, completes);
70+
}, skip: Platform.isAndroid);
3871
}

0 commit comments

Comments
 (0)