Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/firebase_admob/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.6.1

* listener on MobileAd shouldn't be final.
* Ad listeners can to be set in or out of Ad initialization.

## 0.6.0

* Add nonPersonalizedAds option to MobileAdTargetingInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ private void callShowAd(int id, MethodCall call, Result result) {
result.success(Boolean.TRUE);
}

private void callIsAdLoaded(int id, MethodCall call, Result result) {
MobileAd ad = MobileAd.getAdForId(id);
if (ad == null) {
result.error("no_ad_for_id", "isAdLoaded failed, no add exists for id=" + id, null);
return;
}
result.success(ad.status == MobileAd.Status.LOADED ? Boolean.TRUE : Boolean.FALSE);
}

private void callShowRewardedVideoAd(MethodCall call, Result result) {
if (rewardedWrapper.getStatus() == RewardedVideoAdWrapper.Status.LOADED) {
rewardedWrapper.show();
Expand Down Expand Up @@ -208,6 +217,9 @@ public void onMethodCall(MethodCall call, Result result) {
case "disposeAd":
callDisposeAd(id, call, result);
break;
case "isAdLoaded":
callIsAdLoaded(id, call, result);
break;
default:
result.notImplemented();
}
Expand Down
19 changes: 19 additions & 0 deletions packages/firebase_admob/ios/Classes/FirebaseAdMobPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,23 @@ - (void)callShowAd:(NSNumber *)mobileAdId
result([NSNumber numberWithBool:YES]);
}

- (void)callIsAdLoaded:(NSNumber *)mobileAdId
call:(FlutterMethodCall *)call
result:(FlutterResult)result {
FLTMobileAd *ad = [FLTMobileAd getAdForId:mobileAdId];
if (ad == nil) {
NSString *message = [NSString
stringWithFormat:@"isAdLoaded failed, no ad exists for id=%d", mobileAdId.intValue];
result([FlutterError errorWithCode:@"no_ad_for_id" message:message details:nil]);
return;
}
if (ad.status == LOADED) {
result([NSNumber numberWithBool:YES]);
} else {
result([NSNumber numberWithBool:NO]);
}
}

- (void)callShowRewardedVideoAd:(FlutterMethodCall *)call result:(FlutterResult)result {
if (self.rewardedWrapper.status != FLTRewardedVideoAdStatusLoaded) {
result([FlutterError errorWithCode:@"ad_not_loaded"
Expand Down Expand Up @@ -270,6 +287,8 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
result:result];
} else if ([call.method isEqualToString:@"showAd"]) {
[self callShowAd:mobileAdId call:call result:result];
} else if ([call.method isEqualToString:@"isAdLoaded"]) {
[self callIsAdLoaded:mobileAdId call:call result:result];
} else if ([call.method isEqualToString:@"disposeAd"]) {
[self callDisposeAd:mobileAdId call:call result:result];
} else {
Expand Down
8 changes: 7 additions & 1 deletion packages/firebase_admob/lib/firebase_admob.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ abstract class MobileAd {
final String adUnitId;

/// Called when the status of the ad changes.
final MobileAdListener listener;
MobileAdListener listener;

/// An internal id that identifies this mobile ad to the native AdMob plugin.
///
Expand Down Expand Up @@ -228,6 +228,12 @@ abstract class MobileAd {
_allAds[id] = null;
return _invokeBooleanMethod("disposeAd", <String, dynamic>{'id': id});
}

Future<bool> isLoaded() {
return _invokeBooleanMethod("isAdLoaded", <String, dynamic>{
'id': id,
});
}
}

/// A banner ad for the [FirebaseAdMobPlugin].
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_admob/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: firebase_admob
description: Firebase AdMob plugin for Flutter applications.
author: Flutter Team <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/firebase_admob
version: 0.6.0
version: 0.6.1

flutter:
plugin:
Expand Down