Skip to content

Commit

Permalink
Added iOS side of MediationExtras parsing. Marked FLTMediationNetwork…
Browse files Browse the repository at this point in the history
…ExtrasProvider as deprecated. Updated CHANGELOG.
  • Loading branch information
LTPhantom committed Feb 16, 2024
1 parent 10edc61 commit 91c553b
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 96 deletions.
4 changes: 4 additions & 0 deletions packages/google_mobile_ads/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Next Version
* Adds `MediationExtras` class to include parameters when using mediation through the implementation of `FlutterMediationExtras` in Android and `FlutterMediationExtras` in iOS
* Deprecates `MediationNetworkExtrasProvider` and `FLTMediationNetworkExtrasProvider`.

## 4.0.0
* The minimum supported Flutter version is now 3.7.0.
* Removes `visibility_detector` as a dependency, and the workaround added in
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#import "FLTGoogleMobileAdsCollection_Internal.h"
#import "FLTGoogleMobileAdsPlugin.h"
#import "FLTGoogleMobileAdsReaderWriter_Internal.h"
#import "FLTMediationExtras.h"
#import "FLTMobileAds_Internal.h"
#import "FLTNativeTemplateColor.h"
#import "FLTNativeTemplateFontStyle.h"
Expand All @@ -35,6 +36,9 @@ @interface FLTTestAdSizeFactory : FLTAdSizeFactory
@property(readonly) GADAdSize testAdSize;
@end

@interface _FlutterMediationExtras : NSObject<FlutterMediationExtras>
@end

@implementation FLTGoogleMobileAdsReaderWriterTest {
FlutterStandardMessageCodec *_messageCodec;
FLTGoogleMobileAdsReaderWriter *_readerWriter;
Expand Down Expand Up @@ -260,6 +264,8 @@ - (void)testEncodeDecodeFluidAdSize {
}

- (void)testEncodeDecodeAdRequest {
id<FlutterMediationExtras> mediationExtras = [[_FlutterMediationExtras alloc] init];
mediationExtras.extras = @{@"test_key": @"test_value"};
FLTAdRequest *request = [[FLTAdRequest alloc] init];
request.keywords = @[ @"apple" ];
request.contentURL = @"banana";
Expand All @@ -268,6 +274,8 @@ - (void)testEncodeDecodeAdRequest {
request.neighboringContentURLs = contentURLs;
request.mediationExtrasIdentifier = @"identifier";
request.adMobExtras = @{@"key" : @"value"};
NSArray<id<FlutterMediationExtras>> *mediationExtrasArray = @[mediationExtras];
request.mediationExtras = mediationExtrasArray;
NSData *encodedMessage = [_messageCodec encode:request];

FLTAdRequest *decodedRequest = [_messageCodec decode:encodedMessage];
Expand All @@ -279,9 +287,12 @@ - (void)testEncodeDecodeAdRequest {
@"identifier");
XCTAssertEqualObjects(decodedRequest.adMobExtras, @{@"key" : @"value"});
XCTAssertEqualObjects(decodedRequest.requestAgent, @"request-agent");
XCTAssertEqualObjects(decodedRequest.mediationExtras[0].extras, @{@"test_key": @"test_value"});
}

- (void)testEncodeDecodeGAMAdRequest {
id<FlutterMediationExtras> mediationExtras = [[_FlutterMediationExtras alloc] init];
mediationExtras.extras = @{@"test_key": @"test_value"};
FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init];
request.keywords = @[ @"apple" ];
request.contentURL = @"banana";
Expand All @@ -293,6 +304,8 @@ - (void)testEncodeDecodeGAMAdRequest {
request.pubProvidedID = @"pub-id";
request.mediationExtrasIdentifier = @"identifier";
request.adMobExtras = @{@"key" : @"value"};
NSArray<id<FlutterMediationExtras>> *mediationExtrasArray = @[mediationExtras];
request.mediationExtras = mediationExtrasArray;
NSData *encodedMessage = [_messageCodec encode:request];

FLTGAMAdRequest *decodedRequest = [_messageCodec decode:encodedMessage];
Expand All @@ -309,6 +322,7 @@ - (void)testEncodeDecodeGAMAdRequest {
@"identifier");
XCTAssertEqualObjects(decodedRequest.adMobExtras, @{@"key" : @"value"});
XCTAssertEqualObjects(decodedRequest.requestAgent, @"request-agent");
XCTAssertEqualObjects(decodedRequest.mediationExtras[0].extras, @{@"test_key": @"test_value"});
}

- (void)testEncodeDecodeRewardItem {
Expand Down Expand Up @@ -780,3 +794,13 @@ - (GADAdSize)currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:
return GADAdSizeFromCGSize(CGSizeMake(width.doubleValue, 0));
}
@end

@implementation _FlutterMediationExtras

@synthesize extras;

- (id<GADAdNetworkExtras> _Nonnull)getMediationExtras {
return OCMProtocolMock(@protocol(GADAdNetworkExtras));
}

@end
2 changes: 1 addition & 1 deletion packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
DEPRECATED_MSG_ATTRIBUTE("Use mediationExtras instead.");
@property NSDictionary<NSString *, NSString *> *_Nullable adMobExtras;
@property NSString *_Nonnull requestAgent;
@property NSArray<FlutterMediationExtras> *_Nullable mediationExtras;
@property NSArray<id<FlutterMediationExtras>> *_Nullable mediationExtras;

- (GADRequest *_Nonnull)asGADRequest:(NSString *_Nonnull)adUnitId;
@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@
mediationNetworkExtrasProvider
registry:
(id<FlutterPluginRegistry> _Nonnull)
registry;
registry __deprecated;

/*
* Unregisters any FLTMediationNetworkExtrasProvider that was associated with
* the FLTGoogleMobileAdsPlugin in registry.
*/
+ (void)unregisterMediationNetworkExtrasProvider:
(id<FlutterPluginRegistry> _Nonnull)registry;
(id<FlutterPluginRegistry> _Nonnull)registry __deprecated;

/**
* Adds a `FLTNativeAdFactory` used to create a `GADNativeAdView`s from a Native
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,10 @@ - (void)writeValue:(id)value {
[self writeValue:request.adMobExtras];
[self writeValue:request.mediationExtras];
} else if ([value conformsToProtocol:@protocol(FlutterMediationExtras)]) {
// Left empty since there's no need to write it back to the dart layer
[self writeByte:FLTAdmobFieldMediationExtras];
NSObject<FlutterMediationExtras> *fltExtras = value;
[self writeValue:NSStringFromClass([fltExtras class])];
[self writeValue:fltExtras.extras];
} else if ([value isKindOfClass:[FLTRewardItem class]]) {
[self writeByte:FLTAdMobFieldRewardItem];
FLTRewardItem *item = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@protocol FlutterMediationExtras

// Pair of key-values to be stored received from the dart layer.
@property NSMutableDictionary *_Nullable extras;
@property NSDictionary<NSString *, id> *_Nullable extras;

/**
* Parses the values in @c extras to the required protocol to append Mediation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* An implementation of this protocol can be passed to FLTGoogleMobileAdsPlugin
* using registerMediationNetworkExtrasProvider
*/
__attribute__ ((deprecated))
@protocol FLTMediationNetworkExtrasProvider
@required

Expand Down

0 comments on commit 91c553b

Please sign in to comment.