From 4966287e8b8014b612748e211c6da73539aa27b3 Mon Sep 17 00:00:00 2001 From: Aldo Becerril Date: Thu, 8 Aug 2024 14:17:11 -0700 Subject: [PATCH 01/15] Updating iOS rootViewController use from loading time to showing time for Fullscreen ads --- .../google_mobile_ads/example/ios/Podfile | 3 +- .../ios/Runner.xcodeproj/project.pbxproj | 89 +++++++++++++++++++ .../example/ios/Runner/Info.plist | 2 +- .../ios/RunnerTests/FLTAppOpenAdTest.m | 6 +- .../RunnerTests/FLTGamInterstitialAdTest.m | 6 +- .../ios/RunnerTests/FLTGoogleMobileAdsTest.m | 5 -- .../ios/RunnerTests/FLTInterstitialAdTest.m | 6 +- .../ios/RunnerTests/FLTRewardedAdTest.m | 6 +- .../FLTRewardedInterstitialAdTest.m | 6 +- .../Classes/FLTAdInstanceManager_Internal.h | 3 +- .../Classes/FLTAdInstanceManager_Internal.m | 5 +- .../ios/Classes/FLTAd_Internal.h | 12 +-- .../ios/Classes/FLTAd_Internal.m | 38 +++----- .../ios/Classes/FLTGoogleMobileAdsPlugin.m | 47 ++++++---- 14 files changed, 144 insertions(+), 90 deletions(-) diff --git a/packages/google_mobile_ads/example/ios/Podfile b/packages/google_mobile_ads/example/ios/Podfile index 1cad84c20..fcc8b3e03 100644 --- a/packages/google_mobile_ads/example/ios/Podfile +++ b/packages/google_mobile_ads/example/ios/Podfile @@ -28,7 +28,6 @@ require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelpe flutter_ios_podfile_setup target 'Runner' do - use_frameworks! use_modular_headers! flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) @@ -36,7 +35,7 @@ target 'Runner' do inherit! :search_paths # Matches test_spec dependency. - pod 'OCMock', '3.6' + pod 'OCMock', '3.9.3' end end diff --git a/packages/google_mobile_ads/example/ios/Runner.xcodeproj/project.pbxproj b/packages/google_mobile_ads/example/ios/Runner.xcodeproj/project.pbxproj index 3d588697c..ed5150ba5 100644 --- a/packages/google_mobile_ads/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/google_mobile_ads/example/ios/Runner.xcodeproj/project.pbxproj @@ -37,6 +37,8 @@ 9E61AA6029BBE8FD00801A83 /* FLTNativeTemplateStyleTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E61AA5B29BBE8FD00801A83 /* FLTNativeTemplateStyleTest.m */; }; 9E61AA6129BBE8FD00801A83 /* FLTNativeTemplateFontStyleTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E61AA5C29BBE8FD00801A83 /* FLTNativeTemplateFontStyleTest.m */; }; 9E61AA6229BBE8FD00801A83 /* FLTNativeTemplateColorTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E61AA5D29BBE8FD00801A83 /* FLTNativeTemplateColorTest.m */; }; + C032D0C69E82A86DA475F8FE /* libPods-RunnerTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 72FE6B99C77221F59BD2657E /* libPods-RunnerTests.a */; }; + CB51B8C665175A2D77BE7B0B /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 552A358A77902B418501B0E8 /* libPods-Runner.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -65,8 +67,13 @@ /* Begin PBXFileReference section */ 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; + 27B7088677C69B9B87E86B96 /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 44F3DED22B745BEE004D7117 /* FLTMediationExtras.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = FLTMediationExtras.h; path = ../../ios/Classes/FLTMediationExtras.h; sourceTree = ""; }; + 5088939374F111D280B15613 /* Pods-RunnerTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.release.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.release.xcconfig"; sourceTree = ""; }; + 552A358A77902B418501B0E8 /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 72FE6B99C77221F59BD2657E /* libPods-RunnerTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RunnerTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 7382CA922D972355676543EB /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; @@ -150,6 +157,7 @@ 9EF4E6FE26392B230007E4FE /* FLTGoogleMobileAdsCollection_Internal.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FLTGoogleMobileAdsCollection_Internal.m; path = ../../ios/Classes/FLTGoogleMobileAdsCollection_Internal.m; sourceTree = ""; }; 9EF4E6FF26392B230007E4FE /* FLTMobileAds_Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = FLTMobileAds_Internal.h; path = ../../ios/Classes/FLTMobileAds_Internal.h; sourceTree = ""; }; 9EFEAB4E29B0019F000A063B /* GoogleMobileAds.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = GoogleMobileAds.xcframework; path = "Pods/Google-Mobile-Ads-SDK/Frameworks/GoogleMobileAdsFramework/GoogleMobileAds.xcframework"; sourceTree = ""; }; + B01820B337C2EF12599D0744 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -157,6 +165,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + CB51B8C665175A2D77BE7B0B /* libPods-Runner.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -164,6 +173,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + C032D0C69E82A86DA475F8FE /* libPods-RunnerTests.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -173,6 +183,10 @@ 194BB02CA5CDABA098EA0B10 /* Pods */ = { isa = PBXGroup; children = ( + B01820B337C2EF12599D0744 /* Pods-Runner.debug.xcconfig */, + 7382CA922D972355676543EB /* Pods-Runner.release.xcconfig */, + 27B7088677C69B9B87E86B96 /* Pods-RunnerTests.debug.xcconfig */, + 5088939374F111D280B15613 /* Pods-RunnerTests.release.xcconfig */, ); path = Pods; sourceTree = ""; @@ -183,6 +197,8 @@ 9EFEAB4E29B0019F000A063B /* GoogleMobileAds.xcframework */, 9EB9FE57280F853D00DDBB4F /* UserMessagingPlatform.xcframework */, 9EA7213525BB6464008D57E3 /* GoogleMobileAds.xcframework */, + 552A358A77902B418501B0E8 /* libPods-Runner.a */, + 72FE6B99C77221F59BD2657E /* libPods-RunnerTests.a */, ); name = Frameworks; sourceTree = ""; @@ -368,12 +384,14 @@ isa = PBXNativeTarget; buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; buildPhases = ( + E92B7B87E1A00D5F29391D09 /* [CP] Check Pods Manifest.lock */, 9740EEB61CF901F6004384FC /* Run Script */, 97C146EA1CF9000F007C117D /* Sources */, 97C146EB1CF9000F007C117D /* Frameworks */, 97C146EC1CF9000F007C117D /* Resources */, 9705A1C41CF9048500538489 /* Embed Frameworks */, 3B06AD1E1E4923F5004D2608 /* Thin Binary */, + 88D22564A698FDC5B3114D86 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -388,6 +406,7 @@ isa = PBXNativeTarget; buildConfigurationList = 9E61AA1E29BBE51900801A83 /* Build configuration list for PBXNativeTarget "RunnerTests" */; buildPhases = ( + A1476C20D685A26F4507611D /* [CP] Check Pods Manifest.lock */, 9E61AA1229BBE51900801A83 /* Sources */, 9E61AA1329BBE51900801A83 /* Frameworks */, 9E61AA1429BBE51900801A83 /* Resources */, @@ -479,6 +498,30 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed\n/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin\n"; }; + 88D22564A698FDC5B3114D86 /* [CP] Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh", + "${PODS_CONFIGURATION_BUILD_DIR}/Google-Mobile-Ads-SDK/GoogleMobileAdsResources.bundle", + "${PODS_CONFIGURATION_BUILD_DIR}/GoogleUserMessagingPlatform/UserMessagingPlatformResources.bundle", + "${PODS_CONFIGURATION_BUILD_DIR}/google_mobile_ads/google_mobile_ads.bundle", + "${PODS_CONFIGURATION_BUILD_DIR}/webview_flutter_wkwebview/webview_flutter_wkwebview_privacy.bundle", + ); + name = "[CP] Copy Pods Resources"; + outputPaths = ( + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/GoogleMobileAdsResources.bundle", + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/UserMessagingPlatformResources.bundle", + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/google_mobile_ads.bundle", + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/webview_flutter_wkwebview_privacy.bundle", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; alwaysOutOfDate = 1; @@ -494,6 +537,50 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build\n"; }; + A1476C20D685A26F4507611D /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-RunnerTests-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; + E92B7B87E1A00D5F29391D09 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -732,6 +819,7 @@ }; 9E61AA1C29BBE51900801A83 /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 27B7088677C69B9B87E86B96 /* Pods-RunnerTests.debug.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; @@ -758,6 +846,7 @@ }; 9E61AA1D29BBE51900801A83 /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 5088939374F111D280B15613 /* Pods-RunnerTests.release.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; diff --git a/packages/google_mobile_ads/example/ios/Runner/Info.plist b/packages/google_mobile_ads/example/ios/Runner/Info.plist index 924f1d9a8..36a0058fe 100644 --- a/packages/google_mobile_ads/example/ios/Runner/Info.plist +++ b/packages/google_mobile_ads/example/ios/Runner/Info.plist @@ -21,7 +21,7 @@ CFBundleVersion 1 GADApplicationIdentifier - ca-app-pub-3940256099942544~1458002511 + ca-app-pub-3212738706492790~4234003410 LSRequiresIPhoneOS SKAdNetworkItems diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m index 511e39706..dfc65a59d 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m @@ -61,7 +61,6 @@ - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request FLTAppOpenAd *ad = [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" request:request - rootViewController:mockRootViewController adId:@1]; ad.manager = mockManager; @@ -128,7 +127,7 @@ - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request return TRUE; }]]); - [ad show]; + [ad showFromRootViewController:mockRootViewController]; OCMVerify([appOpenClassMock presentFromRootViewController:[OCMArg isEqual:mockRootViewController]]); @@ -162,12 +161,9 @@ - (void)testFailedToLoadGAMRequest { // Helper for testing failed to load. - (void)testFailedToLoad:(FLTAdRequest *)request { - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); FLTAppOpenAd *ad = [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" request:request - rootViewController:mockRootViewController adId:@1]; ad.manager = mockManager; diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m index c02b34fb1..c3d55f8d7 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m @@ -40,7 +40,6 @@ - (void)testLoadShowInterstitialAd { FLTGAMInterstitialAd *ad = [[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId" request:request - rootViewController:mockRootViewController adId:@1]; ad.manager = mockManager; @@ -118,7 +117,7 @@ - (void)testLoadShowInterstitialAd { }]]); // Show the ad - [ad show]; + [ad showFromRootViewController:mockRootViewController]; OCMVerify([interstitialClassMock presentFromRootViewController:[OCMArg isEqual:mockRootViewController]]); @@ -145,12 +144,9 @@ - (void)testFailToLoad { GAMRequest *gadRequest = OCMClassMock([GAMRequest class]); OCMStub([request asGAMRequest:[OCMArg any]]).andReturn(gadRequest); - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); FLTGAMInterstitialAd *ad = [[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId" request:request - rootViewController:mockRootViewController adId:@1]; ad.manager = mockManager; diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m index d5b50cae5..5cccc781f 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m @@ -252,7 +252,6 @@ - (void)testAdInstanceManagerOnRewardedAdUserEarnedReward { FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) adId:@1]; [_manager loadAd:ad]; @@ -279,7 +278,6 @@ - (void)testAdInstanceManagerOnRewardedInterstitialAdUserEarnedReward { FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) adId:@1]; [_manager loadAd:ad]; @@ -372,7 +370,6 @@ - (void)testFullScreenEventsRewardedAd { FLTRewardedAd *rewardedAd = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) adId:@1]; [_manager loadAd:rewardedAd]; @@ -402,7 +399,6 @@ - (void)testFullScreenEventsRewardedInterstitialAd { [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) adId:@1]; [_manager loadAd:rewardedInterstitialAd]; @@ -466,7 +462,6 @@ - (void)testAdClick { [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) adId:@1]; [_manager adDidRecordClick:rewardedInterstitialAd]; diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m index e850374a8..02819d7f3 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m @@ -40,7 +40,6 @@ - (void)testLoadShowInterstitialAd { FLTInterstitialAd *ad = [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" request:request - rootViewController:mockRootViewController adId:@1]; ad.manager = mockManager; @@ -107,7 +106,7 @@ - (void)testLoadShowInterstitialAd { }]]); // Show the ad - [ad show]; + [ad showFromRootViewController:mockRootViewController]; OCMVerify([interstitialClassMock presentFromRootViewController:[OCMArg isEqual:mockRootViewController]]); @@ -129,12 +128,9 @@ - (void)testFailedToLoad { GADRequest *gadRequest = OCMClassMock([GADRequest class]); OCMStub([request asGADRequest:[OCMArg any]]).andReturn(gadRequest); - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); FLTInterstitialAd *ad = [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" request:request - rootViewController:mockRootViewController adId:@1]; ad.manager = mockManager; diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m index b74965cf7..a64936b57 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m @@ -55,7 +55,6 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" request:request - rootViewController:mockRootViewController adId:@1]; ad.manager = mockManager; @@ -147,7 +146,7 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request setServerSideVerificationOptions:[OCMArg isEqual:gadOptions]]); // Show the ad and verify callbacks invoked - [ad show]; + [ad showFromRootViewController:mockRootViewController]; OCMVerify([rewardedClassMock presentFromRootViewController:[OCMArg isEqual:mockRootViewController] @@ -216,12 +215,9 @@ - (void)testFailedToLoadGAMRequest { // Helper for testing failed to load. - (void)testFailedToLoad:(FLTAdRequest *)request { - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" request:request - rootViewController:mockRootViewController adId:@1]; ad.manager = mockManager; diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m index 33d9384c5..261a9e049 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m @@ -55,7 +55,6 @@ - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" request:request - rootViewController:mockRootViewController adId:@1]; ad.manager = mockManager; @@ -152,7 +151,7 @@ - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request setServerSideVerificationOptions:[OCMArg isEqual:gadOptions]]); // Show the ad and verify callbacks are invoked - [ad show]; + [ad showFromRootViewController:mockRootViewController]; OCMVerify([rewardedInterstitialClassMock presentFromRootViewController:[OCMArg isEqual:mockRootViewController] @@ -202,12 +201,9 @@ - (void)testFailedToLoadGAMRequest { // Helper for testing failed to load. - (void)testFailedToLoad:(FLTAdRequest *)request { - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" request:request - rootViewController:mockRootViewController adId:@1]; ad.manager = mockManager; diff --git a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h index 1e8dd5549..1ddf4096e 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h +++ b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h @@ -32,7 +32,8 @@ - (NSNumber *_Nullable)adIdFor:(id _Nonnull)ad; - (void)loadAd:(id _Nonnull)ad; - (void)dispose:(NSNumber *_Nonnull)adId; -- (void)showAdWithID:(NSNumber *_Nonnull)adId; +- (void)showAdWithID:(NSNumber *_Nonnull)adId + rootViewController:(UIViewController *_Nonnull)rootViewController; - (void)onAdLoaded:(id _Nonnull)ad responseInfo:(GADResponseInfo *_Nonnull)responseInfo; - (void)onAdFailedToLoad:(id _Nonnull)ad error:(NSError *_Nonnull)error; diff --git a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m index 6f8e856cc..2ec069c95 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m @@ -67,7 +67,8 @@ - (void)disposeAllAds { [_ads removeAllObjects]; } -- (void)showAdWithID:(NSNumber *_Nonnull)adId { +- (void)showAdWithID:(NSNumber *_Nonnull)adId + rootViewController:(UIViewController *_Nonnull)rootViewController{ id ad = (id)[self adFor:adId]; if (!ad) { @@ -75,7 +76,7 @@ - (void)showAdWithID:(NSNumber *_Nonnull)adId { return; } - [ad show]; + [ad showFromRootViewController:rootViewController]; } - (void)onAdLoaded:(id _Nonnull)ad diff --git a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h index 92d0fc151..2f3264a56 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h +++ b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h @@ -164,7 +164,7 @@ @end @protocol FLTAdWithoutView -- (void)show; +- (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewController; @end @interface FLTBaseAd : NSObject @@ -214,8 +214,6 @@ @interface FLTInterstitialAd : FLTFullScreenAd - (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId request:(FLTAdRequest *_Nonnull)request - rootViewController: - (UIViewController *_Nonnull)rootViewController adId:(NSNumber *_Nonnull)adId; - (GADInterstitialAd *_Nullable)interstitial; - (NSString *_Nonnull)adUnitId; @@ -226,16 +224,12 @@ @interface FLTGAMInterstitialAd : FLTInterstitialAd - (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId request:(FLTGAMAdRequest *_Nonnull)request - rootViewController: - (UIViewController *_Nonnull)rootViewController adId:(NSNumber *_Nonnull)adId; @end @interface FLTRewardedAd : FLTFullScreenAd - (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId request:(FLTAdRequest *_Nonnull)request - rootViewController: - (UIViewController *_Nonnull)rootViewController adId:(NSNumber *_Nonnull)adId; - (GADRewardedAd *_Nullable)rewardedAd; - (void)setServerSideVerificationOptions: @@ -245,8 +239,6 @@ @interface FLTRewardedInterstitialAd : FLTFullScreenAd - (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId request:(FLTAdRequest *_Nonnull)request - rootViewController: - (UIViewController *_Nonnull)rootViewController adId:(NSNumber *_Nonnull)adId; - (GADRewardedInterstitialAd *_Nullable)rewardedInterstitialAd; - (void)setServerSideVerificationOptions: @@ -256,8 +248,6 @@ @interface FLTAppOpenAd : FLTFullScreenAd - (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId request:(FLTAdRequest *_Nonnull)request - rootViewController: - (UIViewController *_Nonnull)rootViewController adId:(NSNumber *_Nonnull)adId; - (GADAppOpenAd *_Nullable)appOpenAd; @end diff --git a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m index 0a82ba796..12ae3348a 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m @@ -619,7 +619,7 @@ - (void)load { format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; } -- (void)show { +- (void)showFromRootViewController:(UIViewController *)rootViewController { // Must be overridden by subclasses [NSException raise:NSInternalInconsistencyException @@ -674,20 +674,17 @@ - (void)adDidRecordClick:(nonnull id)ad { @implementation FLTInterstitialAd { GADInterstitialAd *_interstitialView; FLTAdRequest *_adRequest; - UIViewController *_rootViewController; NSString *_adUnitId; } - (instancetype)initWithAdUnitId:(NSString *_Nonnull)adUnitId request:(FLTAdRequest *_Nonnull)request - rootViewController:(UIViewController *_Nonnull)rootViewController adId:(NSNumber *_Nonnull)adId { self = [super init]; if (self) { self.adId = adId; _adRequest = request; _adUnitId = [adUnitId copy]; - _rootViewController = rootViewController; } return self; } @@ -729,9 +726,9 @@ - (void)load { }]; } -- (void)show { +- (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewController { if (self.interstitial) { - [self.interstitial presentFromRootViewController:_rootViewController]; + [self.interstitial presentFromRootViewController:rootViewController]; } else { NSLog(@"InterstitialAd failed to show because the ad was not ready."); } @@ -744,20 +741,17 @@ - (void)show { @implementation FLTGAMInterstitialAd { GAMInterstitialAd *_insterstitial; FLTGAMAdRequest *_adRequest; - UIViewController *_rootViewController; NSString *_adUnitId; } - (instancetype)initWithAdUnitId:(NSString *_Nonnull)adUnitId request:(FLTGAMAdRequest *_Nonnull)request - rootViewController:(UIViewController *_Nonnull)rootViewController adId:(NSNumber *_Nonnull)adId { self = [super init]; if (self) { self.adId = adId; _adRequest = request; _adUnitId = [adUnitId copy]; - _rootViewController = rootViewController; } return self; } @@ -795,9 +789,9 @@ - (void)load { }]; } -- (void)show { +- (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewController { if (self.interstitial) { - [self.interstitial presentFromRootViewController:_rootViewController]; + [self.interstitial presentFromRootViewController:rootViewController]; } else { NSLog(@"InterstitialAd failed to show because the ad was not ready."); } @@ -817,19 +811,16 @@ - (void)interstitialAd:(nonnull GADInterstitialAd *)interstitialAd @implementation FLTRewardedAd { GADRewardedAd *_rewardedView; FLTAdRequest *_adRequest; - UIViewController *_rootViewController; NSString *_adUnitId; } - (instancetype)initWithAdUnitId:(NSString *_Nonnull)adUnitId request:(FLTAdRequest *_Nonnull)request - rootViewController:(UIViewController *_Nonnull)rootViewController adId:(NSNumber *_Nonnull)adId { self = [super init]; if (self) { self.adId = adId; _adRequest = request; - _rootViewController = rootViewController; _adUnitId = [adUnitId copy]; } return self; @@ -878,10 +869,10 @@ - (void)load { }]; } -- (void)show { +- (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewController { if (self.rewardedAd) { [self.rewardedAd - presentFromRootViewController:_rootViewController + presentFromRootViewController:rootViewController userDidEarnRewardHandler:^{ GADAdReward *reward = self.rewardedAd.adReward; FLTRewardItem *fltReward = @@ -912,19 +903,16 @@ - (void)setServerSideVerificationOptions: @implementation FLTRewardedInterstitialAd { GADRewardedInterstitialAd *_rewardedInterstitialView; FLTAdRequest *_adRequest; - UIViewController *_rootViewController; NSString *_adUnitId; } - (instancetype)initWithAdUnitId:(NSString *_Nonnull)adUnitId request:(FLTAdRequest *_Nonnull)request - rootViewController:(UIViewController *_Nonnull)rootViewController adId:(NSNumber *_Nonnull)adId { self = [super init]; if (self) { self.adId = adId; _adRequest = request; - _rootViewController = rootViewController; _adUnitId = [adUnitId copy]; } return self; @@ -976,10 +964,10 @@ - (void)load { }]; } -- (void)show { +- (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewController { if (self.rewardedInterstitialAd) { [self.rewardedInterstitialAd - presentFromRootViewController:_rootViewController + presentFromRootViewController:rootViewController userDidEarnRewardHandler:^{ GADAdReward *reward = self.rewardedInterstitialAd.adReward; FLTRewardItem *fltReward = @@ -1012,20 +1000,16 @@ - (void)setServerSideVerificationOptions: @implementation FLTAppOpenAd { GADAppOpenAd *_appOpenAd; FLTAdRequest *_adRequest; - UIViewController *_rootViewController; NSString *_adUnitId; } - (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId request:(FLTAdRequest *_Nonnull)request - rootViewController: - (UIViewController *_Nonnull)rootViewController adId:(NSNumber *_Nonnull)adId { self = [super init]; if (self) { self.adId = adId; _adRequest = request; - _rootViewController = rootViewController; _adUnitId = [adUnitId copy]; } return self; @@ -1075,9 +1059,9 @@ - (void)load { }]; } -- (void)show { +- (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewController { if (self.appOpenAd) { - [self.appOpenAd presentFromRootViewController:_rootViewController]; + [self.appOpenAd presentFromRootViewController:rootViewController]; } else { NSLog(@"AppOpenAd failed to show because the ad was not ready."); } diff --git a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m index 1defb9db4..d76165594 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m +++ b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m @@ -213,27 +213,46 @@ + (BOOL)registerNativeAdFactory:(id)registry - (UIViewController *)rootController { UIViewController *root = - UIApplication.sharedApplication.delegate.window.rootViewController; + UIApplication.sharedApplication.delegate.window.rootViewController; if ([FLTAdUtil isNull:root]) { - // UIApplication.sharedApplication.delegate.window is not guaranteed to be - // set. Use the keyWindow in this case. -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" + // UIApplication.sharedApplication.delegate.window is not guaranteed to be + // set. Use the keyWindow in this case. + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdeprecated-declarations" root = UIApplication.sharedApplication.keyWindow.rootViewController; -#pragma clang diagnostic pop + #pragma clang diagnostic pop } - // Get the presented view controller. This fixes an issue in the add to app - // case: https://github.com/googleads/googleads-mobile-flutter/issues/700 UIViewController *presentedViewController = root; - while (presentedViewController.presentedViewController) { - presentedViewController = presentedViewController.presentedViewController; + while (presentedViewController.presentedViewController && ![presentedViewController.presentedViewController isBeingDismissed]) { + if ([presentedViewController isKindOfClass:[UITabBarController class]]) { + UITabBarController* tabBarController = (UITabBarController*)presentedViewController; + presentedViewController = tabBarController.selectedViewController; + } else if ([presentedViewController isKindOfClass:[UINavigationController class]]) { + UINavigationController* navigationController = (UINavigationController*)presentedViewController; + presentedViewController = navigationController.visibleViewController; + } else { + presentedViewController = presentedViewController.presentedViewController; + } } return presentedViewController; } +- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController { + if ([rootViewController isKindOfClass:[UITabBarController class]]) { + UITabBarController* tabBarController = (UITabBarController*)rootViewController; + return [self topViewControllerWithRootViewController:tabBarController.selectedViewController]; + } else if ([rootViewController isKindOfClass:[UINavigationController class]]) { + UINavigationController* navigationController = (UINavigationController*)rootViewController; + return [self topViewControllerWithRootViewController:navigationController.visibleViewController]; + } else { + return rootViewController; + } +} + - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { + NSLog(@"handleMethodCall %@", call.method); UIViewController *rootController = self.rootController; if ([call.method isEqualToString:@"MobileAds#initialize"]) { @@ -426,7 +445,6 @@ - (void)handleMethodCall:(FlutterMethodCall *)call FLTInterstitialAd *ad = [[FLTInterstitialAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] request:call.arguments[@"request"] - rootViewController:rootController adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); @@ -434,7 +452,6 @@ - (void)handleMethodCall:(FlutterMethodCall *)call FLTGAMInterstitialAd *ad = [[FLTGAMInterstitialAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] request:call.arguments[@"request"] - rootViewController:rootController adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); @@ -455,7 +472,6 @@ - (void)handleMethodCall:(FlutterMethodCall *)call FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] request:request - rootViewController:rootController adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); @@ -476,7 +492,6 @@ - (void)handleMethodCall:(FlutterMethodCall *)call FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] request:request - rootViewController:rootController adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); @@ -496,7 +511,6 @@ - (void)handleMethodCall:(FlutterMethodCall *)call FLTAppOpenAd *ad = [[FLTAppOpenAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] request:request - rootViewController:rootController adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); @@ -504,7 +518,8 @@ - (void)handleMethodCall:(FlutterMethodCall *)call [_manager dispose:call.arguments[@"adId"]]; result(nil); } else if ([call.method isEqualToString:@"showAdWithoutView"]) { - [_manager showAdWithID:call.arguments[@"adId"]]; + [_manager showAdWithID:call.arguments[@"adId"] + rootViewController:rootController]; result(nil); } else if ([call.method isEqualToString:@"AdSize#getAnchoredAdaptiveBannerAdSize"]) { From d05e62c7e1a438c25475d8619dea17e35179ffb2 Mon Sep 17 00:00:00 2001 From: Aldo Becerril Date: Fri, 9 Aug 2024 09:51:07 -0700 Subject: [PATCH 02/15] Format fix --- .../Classes/FLTAdInstanceManager_Internal.h | 19 +- .../Classes/FLTAdInstanceManager_Internal.m | 36 +- .../google_mobile_ads/ios/Classes/FLTAdUtil.h | 3 +- .../google_mobile_ads/ios/Classes/FLTAdUtil.m | 18 +- .../ios/Classes/FLTAd_Internal.h | 108 ++-- .../ios/Classes/FLTAd_Internal.m | 490 +++++++----------- .../ios/Classes/FLTAppStateNotifier.m | 34 +- .../FLTGoogleMobileAdsCollection_Internal.h | 5 +- .../FLTGoogleMobileAdsCollection_Internal.m | 3 +- .../ios/Classes/FLTGoogleMobileAdsPlugin.h | 24 +- .../ios/Classes/FLTGoogleMobileAdsPlugin.m | 357 ++++++------- .../FLTGoogleMobileAdsReaderWriter_Internal.h | 14 +- .../FLTGoogleMobileAdsReaderWriter_Internal.m | 478 ++++++++--------- .../FLTMediationNetworkExtrasProvider.h | 6 +- .../ios/Classes/FLTMobileAds_Internal.h | 3 +- .../ios/Classes/FLTMobileAds_Internal.m | 22 +- .../FLTNativeTemplateFontStyle.m | 22 +- .../NativeTemplates/FLTNativeTemplateStyle.h | 18 +- .../NativeTemplates/FLTNativeTemplateStyle.m | 64 +-- .../FLTNativeTemplateTextStyle.h | 9 +- .../FLTNativeTemplateTextStyle.m | 44 +- .../NativeTemplates/FLTNativeTemplateType.h | 2 +- .../NativeTemplates/FLTNativeTemplateType.m | 17 +- .../GADTTemplateView.h | 33 +- .../GADTTemplateView.m | 159 +++--- .../FLTUserMessagingPlatformManager.h | 5 +- .../FLTUserMessagingPlatformManager.m | 142 +++-- .../FLTUserMessagingPlatformReaderWriter.m | 62 ++- 28 files changed, 934 insertions(+), 1263 deletions(-) diff --git a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h index 1ddf4096e..2f3662c9e 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h +++ b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. +#import #import "FLTAd_Internal.h" #import "FLTGoogleMobileAdsCollection_Internal.h" #import "FLTGoogleMobileAdsReaderWriter_Internal.h" -#import @protocol FLTAd; @class FLTBannerAd; @@ -33,9 +33,8 @@ - (void)loadAd:(id _Nonnull)ad; - (void)dispose:(NSNumber *_Nonnull)adId; - (void)showAdWithID:(NSNumber *_Nonnull)adId - rootViewController:(UIViewController *_Nonnull)rootViewController; -- (void)onAdLoaded:(id _Nonnull)ad - responseInfo:(GADResponseInfo *_Nonnull)responseInfo; + rootViewController:(UIViewController *_Nonnull)rootViewController; +- (void)onAdLoaded:(id _Nonnull)ad responseInfo:(GADResponseInfo *_Nonnull)responseInfo; - (void)onAdFailedToLoad:(id _Nonnull)ad error:(NSError *_Nonnull)error; - (void)onAppEvent:(id _Nonnull)ad name:(NSString *_Nullable)name @@ -46,10 +45,8 @@ - (void)onNativeAdWillDismissScreen:(FLTNativeAd *_Nonnull)ad; - (void)onRewardedAdUserEarnedReward:(FLTRewardedAd *_Nonnull)ad reward:(FLTRewardItem *_Nonnull)reward; -- (void)onRewardedInterstitialAdUserEarnedReward: - (FLTRewardedInterstitialAd *_Nonnull)ad - reward: - (FLTRewardItem *_Nonnull)reward; +- (void)onRewardedInterstitialAdUserEarnedReward:(FLTRewardedInterstitialAd *_Nonnull)ad + reward:(FLTRewardItem *_Nonnull)reward; - (void)onPaidEvent:(id _Nonnull)ad value:(FLTAdValue *_Nonnull)value; - (void)onBannerImpression:(FLTBannerAd *_Nonnull)ad; - (void)onBannerWillDismissScreen:(FLTBannerAd *_Nonnull)ad; @@ -67,9 +64,7 @@ - (void)disposeAllAds; @end -@interface FLTNewGoogleMobileAdsViewFactory - : NSObject +@interface FLTNewGoogleMobileAdsViewFactory : NSObject @property(readonly) FLTAdInstanceManager *_Nonnull manager; -- (instancetype _Nonnull)initWithManager: - (FLTAdInstanceManager *_Nonnull)manager; +- (instancetype _Nonnull)initWithManager:(FLTAdInstanceManager *_Nonnull)manager; @end diff --git a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m index 2ec069c95..e384dc1dd 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m @@ -26,10 +26,9 @@ - (instancetype _Nonnull)initWithBinaryMessenger: _ads = [[FLTGoogleMobileAdsCollection alloc] init]; NSObject *methodCodec = [FlutterStandardMethodCodec codecWithReaderWriter:[[FLTGoogleMobileAdsReaderWriter alloc] init]]; - _channel = [[FlutterMethodChannel alloc] - initWithName:@"plugins.flutter.io/google_mobile_ads" - binaryMessenger:binaryMessenger - codec:methodCodec]; + _channel = [[FlutterMethodChannel alloc] initWithName:@"plugins.flutter.io/google_mobile_ads" + binaryMessenger:binaryMessenger + codec:methodCodec]; } return self; } @@ -68,7 +67,7 @@ - (void)disposeAllAds { } - (void)showAdWithID:(NSNumber *_Nonnull)adId - rootViewController:(UIViewController *_Nonnull)rootViewController{ + rootViewController:(UIViewController *_Nonnull)rootViewController { id ad = (id)[self adFor:adId]; if (!ad) { @@ -79,14 +78,12 @@ - (void)showAdWithID:(NSNumber *_Nonnull)adId [ad showFromRootViewController:rootViewController]; } -- (void)onAdLoaded:(id _Nonnull)ad - responseInfo:(GADResponseInfo *_Nonnull)responseInfo { +- (void)onAdLoaded:(id _Nonnull)ad responseInfo:(GADResponseInfo *_Nonnull)responseInfo { [_channel invokeMethod:@"onAdEvent" arguments:@{ @"adId" : ad.adId, @"eventName" : @"onAdLoaded", - @"responseInfo" : [[FLTGADResponseInfo alloc] - initWithResponseInfo:responseInfo] + @"responseInfo" : [[FLTGADResponseInfo alloc] initWithResponseInfo:responseInfo] }]; } @@ -99,9 +96,7 @@ - (void)onAdFailedToLoad:(id _Nonnull)ad error:(NSError *_Nonnull)error { }]; } -- (void)onAppEvent:(id _Nonnull)ad - name:(NSString *)name - data:(NSString *)data { +- (void)onAppEvent:(id _Nonnull)ad name:(NSString *)name data:(NSString *)data { [_channel invokeMethod:@"onAdEvent" arguments:@{ @"adId" : ad.adId, @@ -137,10 +132,8 @@ - (void)onRewardedAdUserEarnedReward:(FLTRewardedAd *_Nonnull)ad }]; } -- (void)onRewardedInterstitialAdUserEarnedReward: - (FLTRewardedInterstitialAd *_Nonnull)ad - reward: - (FLTRewardItem *_Nonnull)reward { +- (void)onRewardedInterstitialAdUserEarnedReward:(FLTRewardedInterstitialAd *_Nonnull)ad + reward:(FLTRewardItem *_Nonnull)reward { [_channel invokeMethod:@"onAdEvent" arguments:@{ @"adId" : ad.adId, @@ -239,17 +232,12 @@ - (instancetype)initWithManager:(FLTAdInstanceManager *_Nonnull)manager { viewIdentifier:(int64_t)viewId arguments:(id _Nullable)args { NSNumber *adId = args; - NSObject *view = - (NSObject *)[_manager adFor:adId]; + NSObject *view = (NSObject *)[_manager adFor:adId]; if (!view) { NSString *reason = [NSString - stringWithFormat: - @"Could not find an ad with id: %@. Was this ad already disposed?", - adId]; - @throw [NSException exceptionWithName:NSInvalidArgumentException - reason:reason - userInfo:nil]; + stringWithFormat:@"Could not find an ad with id: %@. Was this ad already disposed?", adId]; + @throw [NSException exceptionWithName:NSInvalidArgumentException reason:reason userInfo:nil]; } return view; } diff --git a/packages/google_mobile_ads/ios/Classes/FLTAdUtil.h b/packages/google_mobile_ads/ios/Classes/FLTAdUtil.h index 1a0c2f9ff..92bd01d96 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAdUtil.h +++ b/packages/google_mobile_ads/ios/Classes/FLTAdUtil.h @@ -23,8 +23,7 @@ + (BOOL)isNotNull:(_Nullable id)object; + (WKWebView *_Nullable)getWebView:(NSNumber *_Nonnull)webViewId - flutterPluginRegistry: - (id _Nonnull)flutterPluginRegistry; + flutterPluginRegistry:(id _Nonnull)flutterPluginRegistry; @property(readonly, class) NSString *_Nonnull requestAgent; diff --git a/packages/google_mobile_ads/ios/Classes/FLTAdUtil.m b/packages/google_mobile_ads/ios/Classes/FLTAdUtil.m index 8627b3415..87d4c2282 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAdUtil.m +++ b/packages/google_mobile_ads/ios/Classes/FLTAdUtil.m @@ -30,22 +30,20 @@ + (BOOL)isNotNull:(id)object { + (NSString *)requestAgent { NSString *newsTemplateString = @""; - id newsTemplateVersion = [NSBundle.mainBundle - objectForInfoDictionaryKey:@"FLTNewsTemplateVersion"]; + id newsTemplateVersion = + [NSBundle.mainBundle objectForInfoDictionaryKey:@"FLTNewsTemplateVersion"]; if ([newsTemplateVersion isKindOfClass:[NSString class]]) { - newsTemplateString = - [NSString stringWithFormat:@"_News-%@", newsTemplateVersion]; + newsTemplateString = [NSString stringWithFormat:@"_News-%@", newsTemplateVersion]; } NSString *gameTemplateString = @""; - id gameTemplateVersion = [NSBundle.mainBundle - objectForInfoDictionaryKey:@"FLTGameTemplateVersion"]; + id gameTemplateVersion = + [NSBundle.mainBundle objectForInfoDictionaryKey:@"FLTGameTemplateVersion"]; if ([gameTemplateVersion isKindOfClass:[NSString class]]) { - gameTemplateString = - [NSString stringWithFormat:@"_Game-%@", gameTemplateVersion]; + gameTemplateString = [NSString stringWithFormat:@"_Game-%@", gameTemplateVersion]; } - return [NSString stringWithFormat:@"%@%@%@", FLT_REQUEST_AGENT_VERSIONED, - newsTemplateString, gameTemplateString]; + return [NSString stringWithFormat:@"%@%@%@", FLT_REQUEST_AGENT_VERSIONED, newsTemplateString, + gameTemplateString]; } + (WKWebView *)getWebView:(NSNumber *)webViewId diff --git a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h index 2f3264a56..09e571ee3 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h +++ b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#import +#import #import "FLTAdInstanceManager_Internal.h" #import "FLTGoogleMobileAdsPlugin.h" #import "FLTMediationExtras.h" @@ -19,8 +21,6 @@ #import "FLTMobileAds_Internal.h" #import "FLTNativeTemplateStyle.h" #import "GADTTemplateView.h" -#import -#import @class FLTAdInstanceManager; @protocol FLTNativeAdFactory; @@ -29,8 +29,7 @@ @property(readonly) GADAdSize size; @property(readonly) NSNumber *_Nonnull width; @property(readonly) NSNumber *_Nonnull height; -- (instancetype _Nonnull)initWithWidth:(NSNumber *_Nonnull)width - height:(NSNumber *_Nonnull)height; +- (instancetype _Nonnull)initWithWidth:(NSNumber *_Nonnull)width height:(NSNumber *_Nonnull)height; - (instancetype _Nonnull)initWithAdSize:(GADAdSize)size; @end @@ -39,22 +38,14 @@ * Plugin. */ @interface FLTAdSizeFactory : NSObject -- (GADAdSize)portraitAnchoredAdaptiveBannerAdSizeWithWidth: - (NSNumber *_Nonnull)width; -- (GADAdSize)landscapeAnchoredAdaptiveBannerAdSizeWithWidth: - (NSNumber *_Nonnull)width; -- (GADAdSize)currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth: - (NSNumber *_Nonnull)width; -- (GADAdSize)currentOrientationInlineAdaptiveBannerSizeWithWidth: - (NSNumber *_Nonnull)width; -- (GADAdSize)portraitOrientationInlineAdaptiveBannerSizeWithWidth: - (NSNumber *_Nonnull)width; -- (GADAdSize)landscapeInlineAdaptiveBannerAdSizeWithWidth: - (NSNumber *_Nonnull)width; -- (GADAdSize) - inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:(NSNumber *_Nonnull)width - maxHeight: - (NSNumber *_Nonnull)maxHeight; +- (GADAdSize)portraitAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width; +- (GADAdSize)landscapeAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width; +- (GADAdSize)currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width; +- (GADAdSize)currentOrientationInlineAdaptiveBannerSizeWithWidth:(NSNumber *_Nonnull)width; +- (GADAdSize)portraitOrientationInlineAdaptiveBannerSizeWithWidth:(NSNumber *_Nonnull)width; +- (GADAdSize)landscapeInlineAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width; +- (GADAdSize)inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:(NSNumber *_Nonnull)width + maxHeight:(NSNumber *_Nonnull)maxHeight; @end @@ -87,10 +78,9 @@ @property NSString *_Nullable contentURL; @property BOOL nonPersonalizedAds; @property NSArray *_Nullable neighboringContentURLs; -@property NSString *_Nullable mediationExtrasIdentifier - DEPRECATED_MSG_ATTRIBUTE("Use mediationExtras instead."); -@property id< - FLTMediationNetworkExtrasProvider> _Nullable mediationNetworkExtrasProvider +@property NSString *_Nullable mediationExtrasIdentifier DEPRECATED_MSG_ATTRIBUTE( + "Use mediationExtras instead."); +@property id _Nullable mediationNetworkExtrasProvider DEPRECATED_MSG_ATTRIBUTE("Use mediationExtras instead."); @property NSDictionary *_Nullable adMobExtras; @property NSString *_Nonnull requestAgent; @@ -114,8 +104,7 @@ @property NSString *_Nullable adSourceName; @property NSString *_Nullable adSourceInstanceName; -- (instancetype _Nonnull)initWithResponseInfo: - (GADAdNetworkResponseInfo *_Nonnull)responseInfo; +- (instancetype _Nonnull)initWithResponseInfo:(GADAdNetworkResponseInfo *_Nonnull)responseInfo; @end /** @@ -128,8 +117,7 @@ @property FLTGADAdNetworkResponseInfo *_Nullable loadedAdNetworkResponseInfo; @property NSDictionary *_Nullable extrasDictionary; -- (instancetype _Nonnull)initWithResponseInfo: - (GADResponseInfo *_Nonnull)responseInfo; +- (instancetype _Nonnull)initWithResponseInfo:(GADResponseInfo *_Nonnull)responseInfo; @end /** @@ -150,8 +138,7 @@ */ @interface FLTGAMAdRequest : FLTAdRequest @property NSDictionary *_Nullable customTargeting; -@property NSDictionary *> - *_Nullable customTargetingLists; +@property NSDictionary *> *_Nullable customTargetingLists; @property NSString *_Nullable pubProvidedID; - (GAMRequest *_Nonnull)asGAMRequest:(NSString *_Nonnull)adUnitId; @@ -171,13 +158,11 @@ @property(readonly) NSNumber *_Nonnull adId; @end -@interface FLTBannerAd - : FLTBaseAd +@interface FLTBannerAd : FLTBaseAd - (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId size:(FLTAdSize *_Nonnull)size request:(FLTAdRequest *_Nonnull)request - rootViewController: - (UIViewController *_Nonnull)rootViewController + rootViewController:(UIViewController *_Nonnull)rootViewController adId:(NSNumber *_Nonnull)adId; - (FLTAdSize *_Nullable)getAdSize; - (GADBannerView *_Nonnull)bannerView; @@ -190,8 +175,7 @@ - (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId sizes:(NSArray *_Nonnull)sizes request:(FLTGAMAdRequest *_Nonnull)request - rootViewController: - (UIViewController *_Nonnull)rootViewController + rootViewController:(UIViewController *_Nonnull)rootViewController adId:(NSNumber *_Nonnull)adId; @end @@ -202,13 +186,11 @@ @interface FLTFluidGAMBannerAd : FLTGAMBannerAd - (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId request:(FLTGAMAdRequest *_Nonnull)request - rootViewController: - (UIViewController *_Nonnull)rootViewController + rootViewController:(UIViewController *_Nonnull)rootViewController adId:(NSNumber *_Nonnull)adId; @end -@interface FLTFullScreenAd - : FLTBaseAd +@interface FLTFullScreenAd : FLTBaseAd @end @interface FLTInterstitialAd : FLTFullScreenAd @@ -256,10 +238,9 @@ @property(readonly) NSNumber *_Nullable clickToExpandRequested; @property(readonly) NSNumber *_Nullable customControlsRequested; @property(readonly) NSNumber *_Nullable startMuted; -- (instancetype _Nonnull) - initWithClickToExpandRequested:(NSNumber *_Nullable)clickToExpandRequested - customControlsRequested:(NSNumber *_Nullable)customControlsRequested - startMuted:(NSNumber *_Nullable)startMuted; +- (instancetype _Nonnull)initWithClickToExpandRequested:(NSNumber *_Nullable)clickToExpandRequested + customControlsRequested:(NSNumber *_Nullable)customControlsRequested + startMuted:(NSNumber *_Nullable)startMuted; - (GADVideoOptions *_Nonnull)asGADVideoOptions; @end @@ -272,39 +253,34 @@ @property(readonly) NSNumber *_Nullable shouldRequestMultipleImages; @property(readonly) NSNumber *_Nullable shouldReturnUrlsForImageAssets; -- (instancetype _Nonnull) - initWithAdChoicesPlacement:(NSNumber *_Nullable)adChoicesPlacement - mediaAspectRatio:(NSNumber *_Nullable)mediaAspectRatio - videoOptions:(FLTVideoOptions *_Nullable)videoOptions - requestCustomMuteThisAd:(NSNumber *_Nullable)requestCustomMuteThisAd - shouldRequestMultipleImages: - (NSNumber *_Nullable)shouldRequestMultipleImages - shouldReturnUrlsForImageAssets: - (NSNumber *_Nullable)shouldReturnUrlsForImageAssets; +- (instancetype _Nonnull)initWithAdChoicesPlacement:(NSNumber *_Nullable)adChoicesPlacement + mediaAspectRatio:(NSNumber *_Nullable)mediaAspectRatio + videoOptions:(FLTVideoOptions *_Nullable)videoOptions + requestCustomMuteThisAd:(NSNumber *_Nullable)requestCustomMuteThisAd + shouldRequestMultipleImages:(NSNumber *_Nullable)shouldRequestMultipleImages + shouldReturnUrlsForImageAssets: + (NSNumber *_Nullable)shouldReturnUrlsForImageAssets; - (NSArray *_Nonnull)asGADAdLoaderOptions; @end @interface FLTNativeAd - : FLTBaseAd -- (instancetype _Nonnull) - initWithAdUnitId:(NSString *_Nonnull)adUnitId - request:(FLTAdRequest *_Nonnull)request - nativeAdFactory:(NSObject *_Nonnull)nativeAdFactory - customOptions:(NSDictionary *_Nullable)customOptions - rootViewController:(UIViewController *_Nonnull)rootViewController - adId:(NSNumber *_Nonnull)adId - nativeAdOptions:(FLTNativeAdOptions *_Nullable)nativeAdOptions - nativeTemplateStyle:(FLTNativeTemplateStyle *_Nullable)nativeTemplateStyle; + : FLTBaseAd +- (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId + request:(FLTAdRequest *_Nonnull)request + nativeAdFactory:(NSObject *_Nonnull)nativeAdFactory + customOptions:(NSDictionary *_Nullable)customOptions + rootViewController:(UIViewController *_Nonnull)rootViewController + adId:(NSNumber *_Nonnull)adId + nativeAdOptions:(FLTNativeAdOptions *_Nullable)nativeAdOptions + nativeTemplateStyle:(FLTNativeTemplateStyle *_Nullable)nativeTemplateStyle; - (GADAdLoader *_Nonnull)adLoader; @end @interface FLTRewardItem : NSObject @property(readonly) NSNumber *_Nonnull amount; @property(readonly) NSString *_Nonnull type; -- (instancetype _Nonnull)initWithAmount:(NSNumber *_Nonnull)amount - type:(NSString *_Nonnull)type; +- (instancetype _Nonnull)initWithAmount:(NSNumber *_Nonnull)amount type:(NSString *_Nonnull)type; @end @interface FLTAdValue : NSObject diff --git a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m index 12ae3348a..a2c2d36ea 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m @@ -17,10 +17,9 @@ #import "FLTNativeTemplateStyle.h" @implementation FLTAdSize -- (instancetype _Nonnull)initWithWidth:(NSNumber *_Nonnull)width - height:(NSNumber *_Nonnull)height { - return [self initWithAdSize:GADAdSizeFromCGSize(CGSizeMake( - width.doubleValue, height.doubleValue))]; +- (instancetype _Nonnull)initWithWidth:(NSNumber *_Nonnull)width height:(NSNumber *_Nonnull)height { + return + [self initWithAdSize:GADAdSizeFromCGSize(CGSizeMake(width.doubleValue, height.doubleValue))]; } - (instancetype _Nonnull)initWithAdSize:(GADAdSize)size { @@ -35,42 +34,31 @@ - (instancetype _Nonnull)initWithAdSize:(GADAdSize)size { @end @implementation FLTAdSizeFactory -- (GADAdSize)portraitAnchoredAdaptiveBannerAdSizeWithWidth: - (NSNumber *_Nonnull)width { +- (GADAdSize)portraitAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width { return GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth(width.doubleValue); } -- (GADAdSize)landscapeAnchoredAdaptiveBannerAdSizeWithWidth: - (NSNumber *_Nonnull)width { +- (GADAdSize)landscapeAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width { return GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth(width.doubleValue); } -- (GADAdSize)currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth: - (NSNumber *_Nonnull)width { - return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth( - width.doubleValue); +- (GADAdSize)currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width { + return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(width.doubleValue); } -- (GADAdSize)currentOrientationInlineAdaptiveBannerSizeWithWidth: - (NSNumber *_Nonnull)width { - return GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth( - width.floatValue); +- (GADAdSize)currentOrientationInlineAdaptiveBannerSizeWithWidth:(NSNumber *_Nonnull)width { + return GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(width.floatValue); } -- (GADAdSize)portraitOrientationInlineAdaptiveBannerSizeWithWidth: - (NSNumber *_Nonnull)width { +- (GADAdSize)portraitOrientationInlineAdaptiveBannerSizeWithWidth:(NSNumber *_Nonnull)width { return GADPortraitInlineAdaptiveBannerAdSizeWithWidth(width.floatValue); } -- (GADAdSize)landscapeInlineAdaptiveBannerAdSizeWithWidth: - (NSNumber *_Nonnull)width { +- (GADAdSize)landscapeInlineAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width { return GADLandscapeInlineAdaptiveBannerAdSizeWithWidth(width.floatValue); } -- (GADAdSize) - inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:(NSNumber *_Nonnull)width - maxHeight: - (NSNumber *_Nonnull)maxHeight { - return GADInlineAdaptiveBannerAdSizeWithWidthAndMaxHeight( - width.floatValue, maxHeight.floatValue); +- (GADAdSize)inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:(NSNumber *_Nonnull)width + maxHeight:(NSNumber *_Nonnull)maxHeight { + return GADInlineAdaptiveBannerAdSizeWithWidthAndMaxHeight(width.floatValue, maxHeight.floatValue); } @end @@ -81,8 +69,7 @@ - (instancetype _Nonnull)initWithFactory:(FLTAdSizeFactory *_Nonnull)factory width:(NSNumber *_Nonnull)width { GADAdSize size; if ([FLTAdUtil isNull:orientation]) { - size = - [factory currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:width]; + size = [factory currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:width]; } else if ([orientation isEqualToString:@"portrait"]) { size = [factory portraitAnchoredAdaptiveBannerAdSizeWithWidth:width]; } else if ([orientation isEqualToString:@"landscape"]) { @@ -107,18 +94,13 @@ - (instancetype _Nonnull)initWithFactory:(FLTAdSizeFactory *_Nonnull)factory orientation:(NSNumber *_Nullable)orientation { GADAdSize gadAdSize; if ([FLTAdUtil isNotNull:orientation]) { - gadAdSize = - orientation.intValue == 0 - ? [factory - portraitOrientationInlineAdaptiveBannerSizeWithWidth:width] - : [factory landscapeInlineAdaptiveBannerAdSizeWithWidth:width]; + gadAdSize = orientation.intValue == 0 + ? [factory portraitOrientationInlineAdaptiveBannerSizeWithWidth:width] + : [factory landscapeInlineAdaptiveBannerAdSizeWithWidth:width]; } else if ([FLTAdUtil isNotNull:maxHeight]) { - gadAdSize = - [factory inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:width - maxHeight:maxHeight]; + gadAdSize = [factory inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:width maxHeight:maxHeight]; } else { - gadAdSize = - [factory currentOrientationInlineAdaptiveBannerSizeWithWidth:width]; + gadAdSize = [factory currentOrientationInlineAdaptiveBannerSizeWithWidth:width]; } self = [self initWithAdSize:gadAdSize]; if (self) { @@ -140,8 +122,7 @@ - (instancetype _Nonnull)initWithOrientation:(NSString *_Nonnull)orientation { size = kGADAdSizeSmartBannerLandscape; #pragma clang diagnostic pop } else { - NSLog(@"SmartBanner orientation should be 'portrait' or 'landscape': %@", - orientation); + NSLog(@"SmartBanner orientation should be 'portrait' or 'landscape': %@", orientation); return nil; } @@ -169,21 +150,18 @@ - (void)addNetworkExtrasToGADRequest:(GADRequest *_Nonnull)request @implementation FLTAdRequest -- (void)addNetworkExtrasToGADRequest:(GADRequest *)request - adUnitId:(NSString *_Nonnull)adUnitId { +- (void)addNetworkExtrasToGADRequest:(GADRequest *)request adUnitId:(NSString *_Nonnull)adUnitId { NSArray> *extras; if (_mediationExtras != NULL) { - NSMutableArray> *flutterExtras = - [NSMutableArray array]; + NSMutableArray> *flutterExtras = [NSMutableArray array]; for (id extra in _mediationExtras) { [flutterExtras addObject:[extra getMediationExtras]]; } extras = [NSArray arrayWithArray:flutterExtras]; } else { - extras = [_mediationNetworkExtrasProvider - getMediationExtras:adUnitId - mediationExtrasIdentifier:_mediationExtrasIdentifier]; + extras = [_mediationNetworkExtrasProvider getMediationExtras:adUnitId + mediationExtrasIdentifier:_mediationExtrasIdentifier]; } BOOL addedNpaToGADExtras = false; @@ -192,8 +170,8 @@ - (void)addNetworkExtrasToGADRequest:(GADRequest *)request // If GADExtras are present and npa is true, add npa = 1 to the GADExtras if ([extra isKindOfClass:[GADExtras class]] && _nonPersonalizedAds) { GADExtras *gadExtras = (GADExtras *)extra; - NSMutableDictionary *newParams = [[NSMutableDictionary alloc] - initWithDictionary:gadExtras.additionalParameters]; + NSMutableDictionary *newParams = + [[NSMutableDictionary alloc] initWithDictionary:gadExtras.additionalParameters]; newParams[@"npa"] = @"1"; gadExtras.additionalParameters = newParams; [request registerAdNetworkExtras:gadExtras]; @@ -240,25 +218,20 @@ - (GADRequest *_Nonnull)asGADRequest:(NSString *_Nonnull)adUnitId { @implementation FLTGADResponseInfo -- (instancetype _Nonnull)initWithResponseInfo: - (GADResponseInfo *_Nonnull)responseInfo { +- (instancetype _Nonnull)initWithResponseInfo:(GADResponseInfo *_Nonnull)responseInfo { self = [super init]; if (self) { _responseIdentifier = responseInfo.responseIdentifier; - _adNetworkClassName = - responseInfo.loadedAdNetworkResponseInfo.adNetworkClassName; - NSMutableArray *infoArray = - [[NSMutableArray alloc] init]; - for (GADAdNetworkResponseInfo *adNetworkInfo in responseInfo - .adNetworkInfoArray) { - [infoArray addObject:[[FLTGADAdNetworkResponseInfo alloc] - initWithResponseInfo:adNetworkInfo]]; + _adNetworkClassName = responseInfo.loadedAdNetworkResponseInfo.adNetworkClassName; + NSMutableArray *infoArray = [[NSMutableArray alloc] init]; + for (GADAdNetworkResponseInfo *adNetworkInfo in responseInfo.adNetworkInfoArray) { + [infoArray + addObject:[[FLTGADAdNetworkResponseInfo alloc] initWithResponseInfo:adNetworkInfo]]; } _adNetworkInfoArray = infoArray; _loadedAdNetworkResponseInfo = [[FLTGADAdNetworkResponseInfo alloc] initWithResponseInfo:responseInfo.loadedAdNetworkResponseInfo]; - _extrasDictionary = - responseInfo.extrasDictionary ? responseInfo.extrasDictionary : @{}; + _extrasDictionary = responseInfo.extrasDictionary ? responseInfo.extrasDictionary : @{}; } return self; } @@ -266,13 +239,11 @@ - (instancetype _Nonnull)initWithResponseInfo: @implementation FLTGADAdNetworkResponseInfo -- (instancetype _Nonnull)initWithResponseInfo: - (GADAdNetworkResponseInfo *_Nonnull)responseInfo { +- (instancetype _Nonnull)initWithResponseInfo:(GADAdNetworkResponseInfo *_Nonnull)responseInfo { self = [super init]; if (self) { _adNetworkClassName = responseInfo.adNetworkClassName; - NSNumber *timeInMillis = - [[NSNumber alloc] initWithDouble:responseInfo.latency * 1000]; + NSNumber *timeInMillis = [[NSNumber alloc] initWithDouble:responseInfo.latency * 1000]; _latency = @(timeInMillis.longValue); _dictionaryDescription = responseInfo.dictionaryRepresentation.description; _adUnitMapping = [[NSMutableDictionary alloc] init]; @@ -303,11 +274,9 @@ - (instancetype _Nonnull)initWithError:(NSError *_Nonnull)error { _code = error.code; _domain = error.domain; _message = error.localizedDescription; - GADResponseInfo *responseInfo = - error.userInfo[GADErrorUserInfoKeyResponseInfo]; + GADResponseInfo *responseInfo = error.userInfo[GADErrorUserInfoKeyResponseInfo]; if (responseInfo) { - _responseInfo = - [[FLTGADResponseInfo alloc] initWithResponseInfo:responseInfo]; + _responseInfo = [[FLTGADResponseInfo alloc] initWithResponseInfo:responseInfo]; } } return self; @@ -328,8 +297,7 @@ - (GADRequest *_Nonnull)asGAMRequest:(NSString *_Nonnull)adUnitId { NSMutableDictionary *targetingDictionary = [NSMutableDictionary dictionaryWithDictionary:self.customTargeting]; for (NSString *key in self.customTargetingLists) { - targetingDictionary[key] = - [self.customTargetingLists[key] componentsJoinedByString:@","]; + targetingDictionary[key] = [self.customTargetingLists[key] componentsJoinedByString:@","]; } request.customTargeting = targetingDictionary; [self addNetworkExtrasToGADRequest:request adUnitId:adUnitId]; @@ -374,10 +342,9 @@ - (instancetype)initWithAdUnitId:(NSString *_Nonnull)adUnitId return; } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] - initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; } return self; @@ -405,8 +372,7 @@ - (void)bannerViewDidReceiveAd:(GADBannerView *)bannerView { [manager onAdLoaded:self responseInfo:bannerView.responseInfo]; } -- (void)bannerView:(GADBannerView *)bannerView - didFailToReceiveAdWithError:(NSError *)error { +- (void)bannerView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(NSError *)error { [manager onAdFailedToLoad:self error:error]; } @@ -462,8 +428,7 @@ - (instancetype)initWithAdUnitId:(NSString *_Nonnull)adUnitId _bannerView.appEventDelegate = self; _bannerView.delegate = self; - NSMutableArray *validAdSizes = - [NSMutableArray arrayWithCapacity:sizes.count]; + NSMutableArray *validAdSizes = [NSMutableArray arrayWithCapacity:sizes.count]; for (FLTAdSize *size in sizes) { [validAdSizes addObject:NSValueFromGADAdSize(size.size)]; } @@ -475,10 +440,9 @@ - (instancetype)initWithAdUnitId:(NSString *_Nonnull)adUnitId return; } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] - initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; } return self; @@ -540,10 +504,9 @@ - (instancetype)initWithAdUnitId:(NSString *_Nonnull)adUnitId return; } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] - initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; } return self; @@ -570,27 +533,23 @@ - (nonnull UIView *)view { [scrollView addSubview:_bannerView]; _bannerView.translatesAutoresizingMaskIntoConstraints = false; - NSLayoutConstraint *width = - [NSLayoutConstraint constraintWithItem:_bannerView - attribute:NSLayoutAttributeWidth - relatedBy:0 - toItem:scrollView - attribute:NSLayoutAttributeWidth - multiplier:1.0 - constant:0]; + NSLayoutConstraint *width = [NSLayoutConstraint constraintWithItem:_bannerView + attribute:NSLayoutAttributeWidth + relatedBy:0 + toItem:scrollView + attribute:NSLayoutAttributeWidth + multiplier:1.0 + constant:0]; [scrollView addConstraint:width]; _containerView = scrollView; - [_bannerView.widthAnchor constraintEqualToAnchor:scrollView.widthAnchor] - .active = YES; - [_bannerView.topAnchor constraintEqualToAnchor:scrollView.topAnchor].active = - YES; + [_bannerView.widthAnchor constraintEqualToAnchor:scrollView.widthAnchor].active = YES; + [_bannerView.topAnchor constraintEqualToAnchor:scrollView.topAnchor].active = YES; return scrollView; } #pragma mark - GADAdSizeDelegate -- (void)adView:(GADBannerView *)bannerView - willChangeAdSizeTo:(GADAdSize)adSize { +- (void)adView:(GADBannerView *)bannerView willChangeAdSizeTo:(GADAdSize)adSize { CGFloat height = adSize.size.height; [self.manager onFluidAdHeightChanged:self height:height]; } @@ -614,16 +573,14 @@ @implementation FLTFullScreenAd { - (void)load { // Must be overridden by subclasses - [NSException - raise:NSInternalInconsistencyException - format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; + [NSException raise:NSInternalInconsistencyException + format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; } - (void)showFromRootViewController:(UIViewController *)rootViewController { // Must be overridden by subclasses - [NSException - raise:NSInternalInconsistencyException - format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; + [NSException raise:NSInternalInconsistencyException + format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; } - (void)ad:(nonnull id)ad @@ -631,30 +588,25 @@ - (void)ad:(nonnull id)ad [manager didFailToPresentFullScreenContentWithError:self error:error]; } -- (void)adWillPresentFullScreenContent: - (nonnull id)ad { +- (void)adWillPresentFullScreenContent:(nonnull id)ad { // Manually hide the status bar. This is a fix for // https://github.com/googleads/googleads-mobile-flutter/issues/191 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - _statusBarVisibilityBeforeAdShow = - UIApplication.sharedApplication.statusBarHidden; + _statusBarVisibilityBeforeAdShow = UIApplication.sharedApplication.statusBarHidden; [UIApplication.sharedApplication setStatusBarHidden:YES]; #pragma clang diagnostic pop [manager adWillPresentFullScreenContent:self]; } -- (void)adDidDismissFullScreenContent: - (nonnull id)ad { +- (void)adDidDismissFullScreenContent:(nonnull id)ad { [manager adDidDismissFullScreenContent:self]; } -- (void)adWillDismissFullScreenContent: - (nonnull id)ad { +- (void)adWillDismissFullScreenContent:(nonnull id)ad { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - [UIApplication.sharedApplication - setStatusBarHidden:_statusBarVisibilityBeforeAdShow]; + [UIApplication.sharedApplication setStatusBarHidden:_statusBarVisibilityBeforeAdShow]; #pragma clang diagnostic pop [manager adWillDismissFullScreenContent:self]; } @@ -698,32 +650,30 @@ - (NSString *_Nonnull)adUnitId { } - (void)load { - [GADInterstitialAd - loadWithAdUnitID:_adUnitId - request:[_adRequest asGADRequest:_adUnitId] - completionHandler:^(GADInterstitialAd *ad, NSError *error) { - if (error) { - [self.manager onAdFailedToLoad:self error:error]; - return; - } - - ad.fullScreenContentDelegate = self; - self->_interstitialView = ad; - __weak FLTInterstitialAd *weakSelf = self; - ad.paidEventHandler = ^(GADAdValue *_Nonnull value) { - if (weakSelf.manager == nil) { - return; - } - [weakSelf.manager - onPaidEvent:weakSelf - value:[[FLTAdValue alloc] - initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; - }; - - [self.manager onAdLoaded:self responseInfo:ad.responseInfo]; - }]; + [GADInterstitialAd loadWithAdUnitID:_adUnitId + request:[_adRequest asGADRequest:_adUnitId] + completionHandler:^(GADInterstitialAd *ad, NSError *error) { + if (error) { + [self.manager onAdFailedToLoad:self error:error]; + return; + } + + ad.fullScreenContentDelegate = self; + self->_interstitialView = ad; + __weak FLTInterstitialAd *weakSelf = self; + ad.paidEventHandler = ^(GADAdValue *_Nonnull value) { + if (weakSelf.manager == nil) { + return; + } + [weakSelf.manager + onPaidEvent:weakSelf + value:[[FLTAdValue alloc] initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; + }; + + [self.manager onAdLoaded:self responseInfo:ad.responseInfo]; + }]; } - (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewController { @@ -779,10 +729,9 @@ - (void)load { } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] - initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; self->_insterstitial = ad; @@ -844,8 +793,7 @@ - (void)load { [GADRewardedAd loadWithAdUnitID:_adUnitId request:request - completionHandler:^(GADRewardedAd *_Nullable rewardedAd, - NSError *_Nullable error) { + completionHandler:^(GADRewardedAd *_Nullable rewardedAd, NSError *_Nullable error) { if (error) { [self.manager onAdFailedToLoad:self error:error]; return; @@ -857,30 +805,26 @@ - (void)load { } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] - initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; rewardedAd.fullScreenContentDelegate = self; self->_rewardedView = rewardedAd; - [self.manager onAdLoaded:self - responseInfo:rewardedAd.responseInfo]; + [self.manager onAdLoaded:self responseInfo:rewardedAd.responseInfo]; }]; } - (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewController { if (self.rewardedAd) { - [self.rewardedAd - presentFromRootViewController:rootViewController - userDidEarnRewardHandler:^{ - GADAdReward *reward = self.rewardedAd.adReward; - FLTRewardItem *fltReward = - [[FLTRewardItem alloc] initWithAmount:reward.amount - type:reward.type]; - [self.manager onRewardedAdUserEarnedReward:self - reward:fltReward]; - }]; + [self.rewardedAd presentFromRootViewController:rootViewController + userDidEarnRewardHandler:^{ + GADAdReward *reward = self.rewardedAd.adReward; + FLTRewardItem *fltReward = + [[FLTRewardItem alloc] initWithAmount:reward.amount + type:reward.type]; + [self.manager onRewardedAdUserEarnedReward:self reward:fltReward]; + }]; } else { NSLog(@"RewardedAd failed to show because the ad was not ready."); } @@ -937,30 +881,25 @@ - (void)load { [GADRewardedInterstitialAd loadWithAdUnitID:_adUnitId request:request - completionHandler:^( - GADRewardedInterstitialAd *_Nullable rewardedInterstitialAd, - NSError *_Nullable error) { + completionHandler:^(GADRewardedInterstitialAd *_Nullable rewardedInterstitialAd, + NSError *_Nullable error) { if (error) { [self.manager onAdFailedToLoad:self error:error]; return; } __weak FLTRewardedInterstitialAd *weakSelf = self; - rewardedInterstitialAd.paidEventHandler = - ^(GADAdValue *_Nonnull value) { - if (weakSelf.manager == nil) { - return; - } - [weakSelf.manager - onPaidEvent:weakSelf - value:[[FLTAdValue alloc] - initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; - }; + rewardedInterstitialAd.paidEventHandler = ^(GADAdValue *_Nonnull value) { + if (weakSelf.manager == nil) { + return; + } + [weakSelf.manager onPaidEvent:weakSelf + value:[[FLTAdValue alloc] initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; + }; rewardedInterstitialAd.fullScreenContentDelegate = self; self->_rewardedInterstitialView = rewardedInterstitialAd; - [self.manager onAdLoaded:self - responseInfo:rewardedInterstitialAd.responseInfo]; + [self.manager onAdLoaded:self responseInfo:rewardedInterstitialAd.responseInfo]; }]; } @@ -970,16 +909,12 @@ - (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewControlle presentFromRootViewController:rootViewController userDidEarnRewardHandler:^{ GADAdReward *reward = self.rewardedInterstitialAd.adReward; - FLTRewardItem *fltReward = - [[FLTRewardItem alloc] initWithAmount:reward.amount - type:reward.type]; - [self.manager - onRewardedInterstitialAdUserEarnedReward:self - reward:fltReward]; + FLTRewardItem *fltReward = [[FLTRewardItem alloc] initWithAmount:reward.amount + type:reward.type]; + [self.manager onRewardedInterstitialAdUserEarnedReward:self reward:fltReward]; }]; } else { - NSLog( - @"RewardedInterstitialAd failed to show because the ad was not ready."); + NSLog(@"RewardedInterstitialAd failed to show because the ad was not ready."); } } @@ -1033,8 +968,7 @@ - (void)load { [GADAppOpenAd loadWithAdUnitID:_adUnitId request:request - completionHandler:^(GADAppOpenAd *_Nullable appOpenAd, - NSError *_Nullable error) { + completionHandler:^(GADAppOpenAd *_Nullable appOpenAd, NSError *_Nullable error) { if (error) { [self.manager onAdFailedToLoad:self error:error]; return; @@ -1046,16 +980,14 @@ - (void)load { } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] - initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; appOpenAd.fullScreenContentDelegate = self; self->_appOpenAd = appOpenAd; - [self.manager onAdLoaded:self - responseInfo:appOpenAd.responseInfo]; + [self.manager onAdLoaded:self responseInfo:appOpenAd.responseInfo]; }]; } @@ -1082,15 +1014,14 @@ @implementation FLTNativeAd { FLTNativeTemplateStyle *_nativeTemplateStyle; } -- (instancetype _Nonnull) - initWithAdUnitId:(NSString *_Nonnull)adUnitId - request:(FLTAdRequest *_Nonnull)request - nativeAdFactory:(NSObject *_Nonnull)nativeAdFactory - customOptions:(NSDictionary *_Nullable)customOptions - rootViewController:(UIViewController *_Nonnull)rootViewController - adId:(NSNumber *_Nonnull)adId - nativeAdOptions:(FLTNativeAdOptions *_Nullable)nativeAdOptions - nativeTemplateStyle:(FLTNativeTemplateStyle *_Nullable)nativeTemplateStyle { +- (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId + request:(FLTAdRequest *_Nonnull)request + nativeAdFactory:(NSObject *_Nonnull)nativeAdFactory + customOptions:(NSDictionary *_Nullable)customOptions + rootViewController:(UIViewController *_Nonnull)rootViewController + adId:(NSNumber *_Nonnull)adId + nativeAdOptions:(FLTNativeAdOptions *_Nullable)nativeAdOptions + nativeTemplateStyle:(FLTNativeTemplateStyle *_Nullable)nativeTemplateStyle { self = [super init]; if (self) { self.adId = adId; @@ -1103,11 +1034,10 @@ @implementation FLTNativeAd { ? @[] : nativeAdOptions.asGADAdLoaderOptions; - _adLoader = - [[GADAdLoader alloc] initWithAdUnitID:_adUnitId - rootViewController:rootViewController - adTypes:@[ GADAdLoaderAdTypeNative ] - options:adLoaderOptions]; + _adLoader = [[GADAdLoader alloc] initWithAdUnitID:_adUnitId + rootViewController:rootViewController + adTypes:@[ GADAdLoaderAdTypeNative ] + options:adLoaderOptions]; _nativeAdOptions = nativeAdOptions; _nativeTemplateStyle = nativeTemplateStyle; self.adLoader.delegate = self; @@ -1133,16 +1063,14 @@ - (void)load { #pragma mark - GADNativeAdLoaderDelegate -- (void)adLoader:(GADAdLoader *)adLoader - didReceiveNativeAd:(GADNativeAd *)nativeAd { +- (void)adLoader:(GADAdLoader *)adLoader didReceiveNativeAd:(GADNativeAd *)nativeAd { // Use Nil instead of Null to fix crash with Swift integrations. NSDictionary *customOptions = [[NSNull null] isEqual:_customOptions] ? nil : _customOptions; if ([FLTAdUtil isNotNull:_nativeTemplateStyle]) { _view = [_nativeTemplateStyle getDisplayedView:nativeAd]; } else if ([FLTAdUtil isNotNull:_nativeAdFactory]) { - _view = [_nativeAdFactory createNativeAd:nativeAd - customOptions:customOptions]; + _view = [_nativeAdFactory createNativeAd:nativeAd customOptions:customOptions]; } nativeAd.delegate = self; @@ -1152,17 +1080,15 @@ - (void)adLoader:(GADAdLoader *)adLoader if (weakSelf.manager == nil) { return; } - [weakSelf.manager - onPaidEvent:weakSelf - value:[[FLTAdValue alloc] initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + [weakSelf.manager onPaidEvent:weakSelf + value:[[FLTAdValue alloc] initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; [manager onAdLoaded:self responseInfo:nativeAd.responseInfo]; } -- (void)adLoader:(GADAdLoader *)adLoader - didFailToReceiveAdWithError:(NSError *)error { +- (void)adLoader:(GADAdLoader *)adLoader didFailToReceiveAdWithError:(NSError *)error { [manager onAdFailedToLoad:self error:error]; } @@ -1198,8 +1124,7 @@ - (UIView *)view { @end @implementation FLTRewardItem -- (instancetype _Nonnull)initWithAmount:(NSNumber *_Nonnull)amount - type:(NSString *_Nonnull)type { +- (instancetype _Nonnull)initWithAmount:(NSNumber *_Nonnull)amount type:(NSString *_Nonnull)type { self = [super init]; if (self) { _amount = amount; @@ -1231,8 +1156,7 @@ - (instancetype _Nonnull)initWithValue:(NSDecimalNumber *_Nonnull)value self = [super init]; if (self) { _valueMicros = - [value decimalNumberByMultiplyingBy:[[NSDecimalNumber alloc] - initWithInteger:1000000]]; + [value decimalNumberByMultiplyingBy:[[NSDecimalNumber alloc] initWithInteger:1000000]]; _precision = precision; _currencyCode = currencyCode; } @@ -1241,10 +1165,9 @@ - (instancetype _Nonnull)initWithValue:(NSDecimalNumber *_Nonnull)value @end @implementation FLTVideoOptions -- (instancetype _Nonnull) - initWithClickToExpandRequested:(NSNumber *_Nullable)clickToExpandRequested - customControlsRequested:(NSNumber *_Nullable)customControlsRequested - startMuted:(NSNumber *_Nullable)startMuted { +- (instancetype _Nonnull)initWithClickToExpandRequested:(NSNumber *_Nullable)clickToExpandRequested + customControlsRequested:(NSNumber *_Nullable)customControlsRequested + startMuted:(NSNumber *_Nullable)startMuted { self = [super init]; if (self) { _clickToExpandRequested = clickToExpandRequested; @@ -1271,15 +1194,13 @@ - (GADVideoOptions *_Nonnull)asGADVideoOptions { @end @implementation FLTNativeAdOptions -- (instancetype _Nonnull) - initWithAdChoicesPlacement:(NSNumber *_Nullable)adChoicesPlacement - mediaAspectRatio:(NSNumber *_Nullable)mediaAspectRatio - videoOptions:(FLTVideoOptions *_Nullable)videoOptions - requestCustomMuteThisAd:(NSNumber *_Nullable)requestCustomMuteThisAd - shouldRequestMultipleImages: - (NSNumber *_Nullable)shouldRequestMultipleImages - shouldReturnUrlsForImageAssets: - (NSNumber *_Nullable)shouldReturnUrlsForImageAssets { +- (instancetype _Nonnull)initWithAdChoicesPlacement:(NSNumber *_Nullable)adChoicesPlacement + mediaAspectRatio:(NSNumber *_Nullable)mediaAspectRatio + videoOptions:(FLTVideoOptions *_Nullable)videoOptions + requestCustomMuteThisAd:(NSNumber *_Nullable)requestCustomMuteThisAd + shouldRequestMultipleImages:(NSNumber *_Nullable)shouldRequestMultipleImages + shouldReturnUrlsForImageAssets: + (NSNumber *_Nullable)shouldReturnUrlsForImageAssets { self = [super init]; if (self) { _adChoicesPlacement = adChoicesPlacement; @@ -1295,69 +1216,60 @@ @implementation FLTNativeAdOptions - (NSArray *_Nonnull)asGADAdLoaderOptions { NSMutableArray *options = [NSMutableArray array]; - GADNativeAdImageAdLoaderOptions *imageOptions = - [[GADNativeAdImageAdLoaderOptions alloc] init]; + GADNativeAdImageAdLoaderOptions *imageOptions = [[GADNativeAdImageAdLoaderOptions alloc] init]; if ([FLTAdUtil isNotNull:_shouldReturnUrlsForImageAssets]) { - imageOptions.disableImageLoading = - _shouldReturnUrlsForImageAssets.boolValue; + imageOptions.disableImageLoading = _shouldReturnUrlsForImageAssets.boolValue; } if ([FLTAdUtil isNotNull:_shouldRequestMultipleImages]) { - imageOptions.shouldRequestMultipleImages = - _shouldRequestMultipleImages.boolValue; + imageOptions.shouldRequestMultipleImages = _shouldRequestMultipleImages.boolValue; } [options addObject:imageOptions]; if ([FLTAdUtil isNotNull:_adChoicesPlacement]) { - GADNativeAdViewAdOptions *adViewOptions = - [[GADNativeAdViewAdOptions alloc] init]; + GADNativeAdViewAdOptions *adViewOptions = [[GADNativeAdViewAdOptions alloc] init]; switch (_adChoicesPlacement.intValue) { - case 0: - adViewOptions.preferredAdChoicesPosition = - GADAdChoicesPositionTopRightCorner; - break; - case 1: - adViewOptions.preferredAdChoicesPosition = - GADAdChoicesPositionTopLeftCorner; - break; - case 2: - adViewOptions.preferredAdChoicesPosition = - GADAdChoicesPositionBottomRightCorner; - break; - case 3: - adViewOptions.preferredAdChoicesPosition = - GADAdChoicesPositionBottomLeftCorner; - break; - default: - NSLog(@"AdChoicesPlacement should be an int in the range [0, 3]: %d", - _adChoicesPlacement.intValue); - break; + case 0: + adViewOptions.preferredAdChoicesPosition = GADAdChoicesPositionTopRightCorner; + break; + case 1: + adViewOptions.preferredAdChoicesPosition = GADAdChoicesPositionTopLeftCorner; + break; + case 2: + adViewOptions.preferredAdChoicesPosition = GADAdChoicesPositionBottomRightCorner; + break; + case 3: + adViewOptions.preferredAdChoicesPosition = GADAdChoicesPositionBottomLeftCorner; + break; + default: + NSLog(@"AdChoicesPlacement should be an int in the range [0, 3]: %d", + _adChoicesPlacement.intValue); + break; } [options addObject:adViewOptions]; } if ([FLTAdUtil isNotNull:_mediaAspectRatio]) { - GADNativeAdMediaAdLoaderOptions *mediaOptions = - [[GADNativeAdMediaAdLoaderOptions alloc] init]; + GADNativeAdMediaAdLoaderOptions *mediaOptions = [[GADNativeAdMediaAdLoaderOptions alloc] init]; switch (_mediaAspectRatio.intValue) { - case 0: - mediaOptions.mediaAspectRatio = GADMediaAspectRatioUnknown; - break; - case 1: - mediaOptions.mediaAspectRatio = GADMediaAspectRatioAny; - break; - case 2: - mediaOptions.mediaAspectRatio = GADMediaAspectRatioLandscape; - break; - case 3: - mediaOptions.mediaAspectRatio = GADMediaAspectRatioPortrait; - break; - case 4: - mediaOptions.mediaAspectRatio = GADMediaAspectRatioSquare; - break; - default: - NSLog(@"MediaAspectRatio should be an int in the range [0, 4]: %d", - _mediaAspectRatio.intValue); - break; + case 0: + mediaOptions.mediaAspectRatio = GADMediaAspectRatioUnknown; + break; + case 1: + mediaOptions.mediaAspectRatio = GADMediaAspectRatioAny; + break; + case 2: + mediaOptions.mediaAspectRatio = GADMediaAspectRatioLandscape; + break; + case 3: + mediaOptions.mediaAspectRatio = GADMediaAspectRatioPortrait; + break; + case 4: + mediaOptions.mediaAspectRatio = GADMediaAspectRatioSquare; + break; + default: + NSLog(@"MediaAspectRatio should be an int in the range [0, 4]: %d", + _mediaAspectRatio.intValue); + break; } [options addObject:mediaOptions]; } diff --git a/packages/google_mobile_ads/ios/Classes/FLTAppStateNotifier.m b/packages/google_mobile_ads/ios/Classes/FLTAppStateNotifier.m index d4ef51ad8..08a5adf36 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAppStateNotifier.m +++ b/packages/google_mobile_ads/ios/Classes/FLTAppStateNotifier.m @@ -29,24 +29,21 @@ - (instancetype _Nonnull)initWithBinaryMessenger: FLTAppStateNotifier *__weak weakSelf = self; _observers = [[NSMutableArray alloc] init]; _eventChannel = [FlutterEventChannel - eventChannelWithName: - @"plugins.flutter.io/google_mobile_ads/app_state_event" + eventChannelWithName:@"plugins.flutter.io/google_mobile_ads/app_state_event" binaryMessenger:messenger]; _methodChannel = [FlutterMethodChannel - methodChannelWithName: - @"plugins.flutter.io/google_mobile_ads/app_state_method" + methodChannelWithName:@"plugins.flutter.io/google_mobile_ads/app_state_method" binaryMessenger:messenger]; [_eventChannel setStreamHandler:self]; - [_methodChannel setMethodCallHandler:^(FlutterMethodCall *_Nonnull call, - FlutterResult _Nonnull result) { - [weakSelf handleMethodCall:call result:result]; - }]; + [_methodChannel + setMethodCallHandler:^(FlutterMethodCall *_Nonnull call, FlutterResult _Nonnull result) { + [weakSelf handleMethodCall:call result:result]; + }]; } return self; } -- (void)handleMethodCall:(FlutterMethodCall *_Nonnull)call - result:(FlutterResult _Nonnull)result { +- (void)handleMethodCall:(FlutterMethodCall *_Nonnull)call result:(FlutterResult _Nonnull)result { if ([call.method isEqualToString:@"start"]) { [self addAppStateObservers]; result(nil); @@ -93,13 +90,13 @@ - (void)addAppStateObservers { }]; [_observers addObject:foregroundSceneObserver]; - id backgroundSceneObserver = [NSNotificationCenter.defaultCenter - addObserverForName:UISceneDidEnterBackgroundNotification - object:nil - queue:nil - usingBlock:^(NSNotification *_Nonnull note) { - [self handleDidEnterBackground]; - }]; + id backgroundSceneObserver = + [NSNotificationCenter.defaultCenter addObserverForName:UISceneDidEnterBackgroundNotification + object:nil + queue:nil + usingBlock:^(NSNotification *_Nonnull note) { + [self handleDidEnterBackground]; + }]; [_observers addObject:backgroundSceneObserver]; } } @@ -133,8 +130,7 @@ - (FlutterError *_Nullable)onCancelWithArguments:(id _Nullable)arguments { } - (FlutterError *_Nullable)onListenWithArguments:(id _Nullable)arguments - eventSink: - (nonnull FlutterEventSink)events { + eventSink:(nonnull FlutterEventSink)events { _events = events; return nil; } diff --git a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsCollection_Internal.h b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsCollection_Internal.h index 5034d4672..f063e569d 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsCollection_Internal.h +++ b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsCollection_Internal.h @@ -12,16 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. +#import #import "FLTAd_Internal.h" #import "FLTGoogleMobileAdsPlugin.h" -#import @protocol FLTAd; // Thread-safe wrapper of NSMutableDictionary. @interface FLTGoogleMobileAdsCollection : NSObject -- (void)setObject:(ObjectType _Nonnull)object - forKey:(KeyType _Nonnull)key; +- (void)setObject:(ObjectType _Nonnull)object forKey:(KeyType _Nonnull)key; - (void)removeObjectForKey:(KeyType _Nonnull)key; - (id _Nullable)objectForKey:(KeyType _Nonnull)key; - (NSArray *_Nonnull)allKeysForObject:(ObjectType _Nonnull)object; diff --git a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsCollection_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsCollection_Internal.m index 6efb188e6..c99ec97b8 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsCollection_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsCollection_Internal.m @@ -23,8 +23,7 @@ - (instancetype _Nonnull)init { self = [super init]; if (self) { _dictionary = [[NSMutableDictionary alloc] init]; - _lockQueue = dispatch_queue_create("FLTGoogleMobileAdsCollection", - DISPATCH_QUEUE_SERIAL); + _lockQueue = dispatch_queue_create("FLTGoogleMobileAdsCollection", DISPATCH_QUEUE_SERIAL); } return self; } diff --git a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.h b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.h index f01782088..470654ffa 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.h +++ b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.h @@ -21,7 +21,7 @@ #import "FLTMediationNetworkExtrasProvider.h" #import "FLTMobileAds_Internal.h" -#define FLTLogWarning(format, ...) \ +#define FLTLogWarning(format, ...) \ NSLog((@"GoogleMobileAdsPlugin " format), ##__VA_ARGS__) /** @@ -42,8 +42,7 @@ * @return a `GADNativeAdView` that is overlaid on top of the FlutterView. */ - (GADNativeAdView *_Nullable)createNativeAd:(GADNativeAd *_Nonnull)nativeAd - customOptions: - (NSDictionary *_Nullable)customOptions; + customOptions:(NSDictionary *_Nullable)customOptions; @end /** @@ -63,19 +62,15 @@ * a FLTGoogleMobileAdsPlugin in the registry. */ + (BOOL)registerMediationNetworkExtrasProvider: - (id _Nonnull) - mediationNetworkExtrasProvider - registry: - (id _Nonnull) - registry + (id _Nonnull)mediationNetworkExtrasProvider + registry:(id _Nonnull)registry __deprecated_msg("Use MediationExtras instead"); /* * Unregisters any FLTMediationNetworkExtrasProvider that was associated with * the FLTGoogleMobileAdsPlugin in registry. */ -+ (void)unregisterMediationNetworkExtrasProvider: - (id _Nonnull)registry ++ (void)unregisterMediationNetworkExtrasProvider:(id _Nonnull)registry __deprecated_msg("Use MediationExtras instead"); /** @@ -92,8 +87,7 @@ */ + (BOOL)registerNativeAdFactory:(id _Nonnull)registry factoryId:(NSString *_Nonnull)factoryId - nativeAdFactory: - (id _Nonnull)nativeAdFactory; + nativeAdFactory:(id _Nonnull)nativeAdFactory; /** * Unregisters a `FLTNativeAdFactory` used to create `GADNativeAdView`s from a @@ -105,7 +99,7 @@ * @return the previous `FLTNativeAdFactory` associated with this factoryId, or * null if there was none for this factoryId. */ -+ (id _Nullable) - unregisterNativeAdFactory:(id _Nonnull)registry - factoryId:(NSString *_Nonnull)factoryId; ++ (id _Nullable)unregisterNativeAdFactory: + (id _Nonnull)registry + factoryId:(NSString *_Nonnull)factoryId; @end diff --git a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m index d76165594..b872d164c 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m +++ b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m @@ -22,8 +22,7 @@ @interface FLTGoogleMobileAdsPlugin () @property(nonatomic, retain) FlutterMethodChannel *channel; -@property NSMutableDictionary> - *nativeAdFactories; +@property NSMutableDictionary> *nativeAdFactories; @end /// Initialization handler for GMASDK. Invokes result at most once. @@ -75,29 +74,26 @@ @implementation FLTGoogleMobileAdsPlugin { } + (void)registerWithRegistrar:(NSObject *)registrar { - FLTGoogleMobileAdsPlugin *instance = [[FLTGoogleMobileAdsPlugin alloc] - initWithBinaryMessenger:registrar.messenger]; + FLTGoogleMobileAdsPlugin *instance = + [[FLTGoogleMobileAdsPlugin alloc] initWithBinaryMessenger:registrar.messenger]; [registrar publish:instance]; - FLTGoogleMobileAdsReaderWriter *readerWriter = - [[FLTGoogleMobileAdsReaderWriter alloc] init]; + FLTGoogleMobileAdsReaderWriter *readerWriter = [[FLTGoogleMobileAdsReaderWriter alloc] init]; instance->_readerWriter = readerWriter; NSObject *codec = [FlutterStandardMethodCodec codecWithReaderWriter:readerWriter]; - FlutterMethodChannel *channel = [FlutterMethodChannel - methodChannelWithName:@"plugins.flutter.io/google_mobile_ads" - binaryMessenger:[registrar messenger] - codec:codec]; + FlutterMethodChannel *channel = + [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/google_mobile_ads" + binaryMessenger:[registrar messenger] + codec:codec]; [registrar addMethodCallDelegate:instance channel:channel]; FLTNewGoogleMobileAdsViewFactory *viewFactory = - [[FLTNewGoogleMobileAdsViewFactory alloc] - initWithManager:instance->_manager]; - [registrar - registerViewFactory:viewFactory - withId:@"plugins.flutter.io/google_mobile_ads/ad_widget"]; + [[FLTNewGoogleMobileAdsViewFactory alloc] initWithManager:instance->_manager]; + [registrar registerViewFactory:viewFactory + withId:@"plugins.flutter.io/google_mobile_ads/ad_widget"]; [registrar addApplicationDelegate:instance]; } @@ -112,32 +108,25 @@ - (BOOL)application:(UIApplication *)application return YES; } -- (instancetype)initWithBinaryMessenger: - (id)binaryMessenger { +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger { self = [self init]; if (self) { _nativeAdFactories = [NSMutableDictionary dictionary]; - _manager = - [[FLTAdInstanceManager alloc] initWithBinaryMessenger:binaryMessenger]; - _appStateNotifier = - [[FLTAppStateNotifier alloc] initWithBinaryMessenger:binaryMessenger]; - _userMessagingPlatformManager = [[FLTUserMessagingPlatformManager alloc] - initWithBinaryMessenger:binaryMessenger]; + _manager = [[FLTAdInstanceManager alloc] initWithBinaryMessenger:binaryMessenger]; + _appStateNotifier = [[FLTAppStateNotifier alloc] initWithBinaryMessenger:binaryMessenger]; + _userMessagingPlatformManager = + [[FLTUserMessagingPlatformManager alloc] initWithBinaryMessenger:binaryMessenger]; } return self; } + (BOOL)registerMediationNetworkExtrasProvider: - (id _Nonnull) - mediationNetworkExtrasProvider - registry: - (id _Nonnull) - registry { - NSString *pluginClassName = - NSStringFromClass([FLTGoogleMobileAdsPlugin class]); - FLTGoogleMobileAdsPlugin *adMobPlugin = (FLTGoogleMobileAdsPlugin *)[registry - valuePublishedByPlugin:pluginClassName]; + (id _Nonnull)mediationNetworkExtrasProvider + registry:(id _Nonnull)registry { + NSString *pluginClassName = NSStringFromClass([FLTGoogleMobileAdsPlugin class]); + FLTGoogleMobileAdsPlugin *adMobPlugin = + (FLTGoogleMobileAdsPlugin *)[registry valuePublishedByPlugin:pluginClassName]; if (!adMobPlugin) { NSLog(@"Could not find a %@ instance registering mediation extras " @"provider. The plugin may " @@ -147,18 +136,15 @@ + (BOOL)registerMediationNetworkExtrasProvider: } adMobPlugin->_mediationNetworkExtrasProvider = mediationNetworkExtrasProvider; - adMobPlugin->_readerWriter.mediationNetworkExtrasProvider = - mediationNetworkExtrasProvider; + adMobPlugin->_readerWriter.mediationNetworkExtrasProvider = mediationNetworkExtrasProvider; return YES; } -+ (void)unregisterMediationNetworkExtrasProvider: - (id _Nonnull)registry { - NSString *pluginClassName = - NSStringFromClass([FLTGoogleMobileAdsPlugin class]); - FLTGoogleMobileAdsPlugin *adMobPlugin = (FLTGoogleMobileAdsPlugin *)[registry - valuePublishedByPlugin:pluginClassName]; ++ (void)unregisterMediationNetworkExtrasProvider:(id _Nonnull)registry { + NSString *pluginClassName = NSStringFromClass([FLTGoogleMobileAdsPlugin class]); + FLTGoogleMobileAdsPlugin *adMobPlugin = + (FLTGoogleMobileAdsPlugin *)[registry valuePublishedByPlugin:pluginClassName]; if (!adMobPlugin) { NSLog(@"Could not find a %@ instance deregistering mediation extras " @"provider. The plugin may " @@ -174,23 +160,18 @@ + (void)unregisterMediationNetworkExtrasProvider: + (BOOL)registerNativeAdFactory:(id)registry factoryId:(NSString *)factoryId nativeAdFactory:(id)nativeAdFactory { - NSString *pluginClassName = - NSStringFromClass([FLTGoogleMobileAdsPlugin class]); - FLTGoogleMobileAdsPlugin *adMobPlugin = (FLTGoogleMobileAdsPlugin *)[registry - valuePublishedByPlugin:pluginClassName]; + NSString *pluginClassName = NSStringFromClass([FLTGoogleMobileAdsPlugin class]); + FLTGoogleMobileAdsPlugin *adMobPlugin = + (FLTGoogleMobileAdsPlugin *)[registry valuePublishedByPlugin:pluginClassName]; if (!adMobPlugin) { - NSString *reason = - [NSString stringWithFormat:@"Could not find a %@ instance. The plugin " - @"may have not been registered.", - pluginClassName]; - [NSException exceptionWithName:NSInvalidArgumentException - reason:reason - userInfo:nil]; + NSString *reason = [NSString stringWithFormat:@"Could not find a %@ instance. The plugin " + @"may have not been registered.", + pluginClassName]; + [NSException exceptionWithName:NSInvalidArgumentException reason:reason userInfo:nil]; } if (adMobPlugin.nativeAdFactories[factoryId]) { - NSLog(@"A NativeAdFactory with the following factoryId already exists: %@", - factoryId); + NSLog(@"A NativeAdFactory with the following factoryId already exists: %@", factoryId); return NO; } @@ -198,38 +179,36 @@ + (BOOL)registerNativeAdFactory:(id)registry return YES; } -+ (id)unregisterNativeAdFactory: - (id)registry ++ (id)unregisterNativeAdFactory:(id)registry factoryId:(NSString *)factoryId { FLTGoogleMobileAdsPlugin *adMobPlugin = (FLTGoogleMobileAdsPlugin *)[registry - valuePublishedByPlugin:NSStringFromClass( - [FLTGoogleMobileAdsPlugin class])]; + valuePublishedByPlugin:NSStringFromClass([FLTGoogleMobileAdsPlugin class])]; id factory = adMobPlugin.nativeAdFactories[factoryId]; - if (factory) - [adMobPlugin.nativeAdFactories removeObjectForKey:factoryId]; + if (factory) [adMobPlugin.nativeAdFactories removeObjectForKey:factoryId]; return factory; } - (UIViewController *)rootController { - UIViewController *root = - UIApplication.sharedApplication.delegate.window.rootViewController; + UIViewController *root = UIApplication.sharedApplication.delegate.window.rootViewController; if ([FLTAdUtil isNull:root]) { - // UIApplication.sharedApplication.delegate.window is not guaranteed to be - // set. Use the keyWindow in this case. - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wdeprecated-declarations" +// UIApplication.sharedApplication.delegate.window is not guaranteed to be +// set. Use the keyWindow in this case. +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" root = UIApplication.sharedApplication.keyWindow.rootViewController; - #pragma clang diagnostic pop +#pragma clang diagnostic pop } UIViewController *presentedViewController = root; - while (presentedViewController.presentedViewController && ![presentedViewController.presentedViewController isBeingDismissed]) { + while (presentedViewController.presentedViewController && + ![presentedViewController.presentedViewController isBeingDismissed]) { if ([presentedViewController isKindOfClass:[UITabBarController class]]) { - UITabBarController* tabBarController = (UITabBarController*)presentedViewController; + UITabBarController *tabBarController = (UITabBarController *)presentedViewController; presentedViewController = tabBarController.selectedViewController; } else if ([presentedViewController isKindOfClass:[UINavigationController class]]) { - UINavigationController* navigationController = (UINavigationController*)presentedViewController; + UINavigationController *navigationController = + (UINavigationController *)presentedViewController; presentedViewController = navigationController.visibleViewController; } else { presentedViewController = presentedViewController.presentedViewController; @@ -238,26 +217,26 @@ - (UIViewController *)rootController { return presentedViewController; } -- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController { +- (UIViewController *)topViewControllerWithRootViewController: + (UIViewController *)rootViewController { if ([rootViewController isKindOfClass:[UITabBarController class]]) { - UITabBarController* tabBarController = (UITabBarController*)rootViewController; + UITabBarController *tabBarController = (UITabBarController *)rootViewController; return [self topViewControllerWithRootViewController:tabBarController.selectedViewController]; } else if ([rootViewController isKindOfClass:[UINavigationController class]]) { - UINavigationController* navigationController = (UINavigationController*)rootViewController; - return [self topViewControllerWithRootViewController:navigationController.visibleViewController]; + UINavigationController *navigationController = (UINavigationController *)rootViewController; + return + [self topViewControllerWithRootViewController:navigationController.visibleViewController]; } else { return rootViewController; } } -- (void)handleMethodCall:(FlutterMethodCall *)call - result:(FlutterResult)result { +- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { NSLog(@"handleMethodCall %@", call.method); UIViewController *rootController = self.rootController; if ([call.method isEqualToString:@"MobileAds#initialize"]) { - FLTInitializationHandler *handler = - [[FLTInitializationHandler alloc] initWithResult:result]; + FLTInitializationHandler *handler = [[FLTInitializationHandler alloc] initWithResult:result]; [[GADMobileAds sharedInstance] startWithCompletionHandler:^(GADInitializationStatus *_Nonnull status) { [handler handleInitializationComplete:status]; @@ -266,35 +245,27 @@ - (void)handleMethodCall:(FlutterMethodCall *)call [_manager disposeAllAds]; result(nil); } else if ([call.method isEqualToString:@"MobileAds#setSameAppKeyEnabled"]) { - GADRequestConfiguration *requestConfig = - GADMobileAds.sharedInstance.requestConfiguration; + GADRequestConfiguration *requestConfig = GADMobileAds.sharedInstance.requestConfiguration; NSNumber *isEnabled = call.arguments[@"isEnabled"]; [requestConfig setPublisherFirstPartyIDEnabled:isEnabled.boolValue]; result(nil); } else if ([call.method isEqualToString:@"MobileAds#setAppMuted"]) { - GADMobileAds.sharedInstance.applicationMuted = - [call.arguments[@"muted"] boolValue]; + GADMobileAds.sharedInstance.applicationMuted = [call.arguments[@"muted"] boolValue]; result(nil); } else if ([call.method isEqualToString:@"MobileAds#setAppVolume"]) { - GADMobileAds.sharedInstance.applicationVolume = - [call.arguments[@"volume"] floatValue]; + GADMobileAds.sharedInstance.applicationVolume = [call.arguments[@"volume"] floatValue]; result(nil); - } else if ([call.method - isEqualToString:@"MobileAds#disableSDKCrashReporting"]) { + } else if ([call.method isEqualToString:@"MobileAds#disableSDKCrashReporting"]) { [GADMobileAds.sharedInstance disableSDKCrashReporting]; result(nil); - } else if ([call.method - isEqualToString:@"MobileAds#disableMediationInitialization"]) { + } else if ([call.method isEqualToString:@"MobileAds#disableMediationInitialization"]) { [GADMobileAds.sharedInstance disableMediationInitialization]; result(nil); } else if ([call.method isEqualToString:@"MobileAds#openDebugMenu"]) { NSString *adUnitId = call.arguments[@"adUnitId"]; GADDebugOptionsViewController *debugOptionsViewController = - [GADDebugOptionsViewController - debugOptionsViewControllerWithAdUnitID:adUnitId]; - [rootController presentViewController:debugOptionsViewController - animated:YES - completion:nil]; + [GADDebugOptionsViewController debugOptionsViewControllerWithAdUnitID:adUnitId]; + [rootController presentViewController:debugOptionsViewController animated:YES completion:nil]; result(nil); } else if ([call.method isEqualToString:@"MobileAds#openAdInspector"]) { [GADMobileAds.sharedInstance @@ -302,8 +273,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call completionHandler:^(NSError *error) { if (error) { result([FlutterError - errorWithCode:[[NSString alloc] - initWithInt:error.code] + errorWithCode:[[NSString alloc] initWithInt:error.code] message:error.localizedDescription details:error.domain]); } else { @@ -311,28 +281,22 @@ - (void)handleMethodCall:(FlutterMethodCall *)call } }]; } else if ([call.method isEqualToString:@"MobileAds#getVersionString"]) { - result(GADGetStringFromVersionNumber( - GADMobileAds.sharedInstance.versionNumber)); - } else if ([call.method - isEqualToString:@"MobileAds#getRequestConfiguration"]) { + result(GADGetStringFromVersionNumber(GADMobileAds.sharedInstance.versionNumber)); + } else if ([call.method isEqualToString:@"MobileAds#getRequestConfiguration"]) { result(GADMobileAds.sharedInstance.requestConfiguration); } else if ([call.method isEqualToString:@"MobileAds#registerWebView"]) { if (!_appDelegate) { NSLog(@"App delegate is null in MobileAds#registerWebView, skipping"); } else { NSNumber *webViewId = call.arguments[@"webViewId"]; - WKWebView *webView = [FLTAdUtil getWebView:webViewId - flutterPluginRegistry:_appDelegate]; + WKWebView *webView = [FLTAdUtil getWebView:webViewId flutterPluginRegistry:_appDelegate]; [GADMobileAds.sharedInstance registerWebView:webView]; } result(nil); - } else if ([call.method - isEqualToString:@"MobileAds#updateRequestConfiguration"]) { + } else if ([call.method isEqualToString:@"MobileAds#updateRequestConfiguration"]) { NSString *maxAdContentRating = call.arguments[@"maxAdContentRating"]; - NSNumber *tagForChildDirectedTreatment = - call.arguments[@"tagForChildDirectedTreatment"]; - NSNumber *tagForUnderAgeOfConsent = - call.arguments[@"tagForUnderAgeOfConsent"]; + NSNumber *tagForChildDirectedTreatment = call.arguments[@"tagForChildDirectedTreatment"]; + NSNumber *tagForUnderAgeOfConsent = call.arguments[@"tagForUnderAgeOfConsent"]; NSArray *testDeviceIds = call.arguments[@"testDeviceIds"]; if (maxAdContentRating != NULL && maxAdContentRating != (id)[NSNull null]) { @@ -350,76 +314,63 @@ - (void)handleMethodCall:(FlutterMethodCall *)call GADMaxAdContentRatingMatureAudience; } } - if (tagForChildDirectedTreatment != NULL && - tagForChildDirectedTreatment != (id)[NSNull null]) { + if (tagForChildDirectedTreatment != NULL && tagForChildDirectedTreatment != (id)[NSNull null]) { switch ([tagForChildDirectedTreatment intValue]) { - case 0: - GADMobileAds.sharedInstance.requestConfiguration - .tagForChildDirectedTreatment = @NO; - break; - case 1: - GADMobileAds.sharedInstance.requestConfiguration - .tagForChildDirectedTreatment = @YES; - break; + case 0: + GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment = @NO; + break; + case 1: + GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment = @YES; + break; } } - if (tagForUnderAgeOfConsent != NULL && - tagForUnderAgeOfConsent != (id)[NSNull null]) { + if (tagForUnderAgeOfConsent != NULL && tagForUnderAgeOfConsent != (id)[NSNull null]) { switch ([tagForUnderAgeOfConsent intValue]) { - case 0: - GADMobileAds.sharedInstance.requestConfiguration - .tagForUnderAgeOfConsent = @NO; - break; - case 1: - GADMobileAds.sharedInstance.requestConfiguration - .tagForUnderAgeOfConsent = @YES; - break; + case 0: + GADMobileAds.sharedInstance.requestConfiguration.tagForUnderAgeOfConsent = @NO; + break; + case 1: + GADMobileAds.sharedInstance.requestConfiguration.tagForUnderAgeOfConsent = @YES; + break; } } if (testDeviceIds != NULL && testDeviceIds != (id)[NSNull null]) { - GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = - testDeviceIds; + GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = testDeviceIds; } result(nil); } else if ([call.method isEqualToString:@"loadBannerAd"]) { - FLTBannerAd *ad = - [[FLTBannerAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - size:call.arguments[@"size"] - request:call.arguments[@"request"] - rootViewController:rootController - adId:call.arguments[@"adId"]]; + FLTBannerAd *ad = [[FLTBannerAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + size:call.arguments[@"size"] + request:call.arguments[@"request"] + rootViewController:rootController + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadAdManagerBannerAd"]) { - FLTGAMBannerAd *ad = - [[FLTGAMBannerAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - sizes:call.arguments[@"sizes"] - request:call.arguments[@"request"] - rootViewController:rootController - adId:call.arguments[@"adId"]]; + FLTGAMBannerAd *ad = [[FLTGAMBannerAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + sizes:call.arguments[@"sizes"] + request:call.arguments[@"request"] + rootViewController:rootController + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadFluidAd"]) { - FLTFluidGAMBannerAd *ad = [[FLTFluidGAMBannerAd alloc] - initWithAdUnitId:call.arguments[@"adUnitId"] - request:call.arguments[@"request"] - rootViewController:rootController - adId:call.arguments[@"adId"]]; + FLTFluidGAMBannerAd *ad = + [[FLTFluidGAMBannerAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + request:call.arguments[@"request"] + rootViewController:rootController + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadNativeAd"]) { NSString *factoryId = call.arguments[@"factoryId"]; id factory = _nativeAdFactories[factoryId]; - FLTNativeTemplateStyle *templateStyle = - call.arguments[@"nativeTemplateStyle"]; + FLTNativeTemplateStyle *templateStyle = call.arguments[@"nativeTemplateStyle"]; if ([FLTAdUtil isNull:factory] && [FLTAdUtil isNull:templateStyle]) { - NSString *message = - [NSString stringWithFormat:@"Can't find NativeAdFactory with id: %@ " - @"and nativeTemplateStyle is null", - factoryId]; - result([FlutterError errorWithCode:@"NativeAdError" - message:message - details:nil]); + NSString *message = [NSString stringWithFormat:@"Can't find NativeAdFactory with id: %@ " + @"and nativeTemplateStyle is null", + factoryId]; + result([FlutterError errorWithCode:@"NativeAdError" message:message details:nil]); return; } @@ -430,29 +381,27 @@ - (void)handleMethodCall:(FlutterMethodCall *)call request = call.arguments[@"adManagerRequest"]; } - FLTNativeAd *ad = [[FLTNativeAd alloc] - initWithAdUnitId:call.arguments[@"adUnitId"] - request:request - nativeAdFactory:(id)factory - customOptions:call.arguments[@"customOptions"] - rootViewController:rootController - adId:call.arguments[@"adId"] - nativeAdOptions:call.arguments[@"nativeAdOptions"] - nativeTemplateStyle:call.arguments[@"nativeTemplateStyle"]]; + FLTNativeAd *ad = [[FLTNativeAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + request:request + nativeAdFactory:(id)factory + customOptions:call.arguments[@"customOptions"] + rootViewController:rootController + adId:call.arguments[@"adId"] + nativeAdOptions:call.arguments[@"nativeAdOptions"] + nativeTemplateStyle:call.arguments[@"nativeTemplateStyle"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadInterstitialAd"]) { - FLTInterstitialAd *ad = - [[FLTInterstitialAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - request:call.arguments[@"request"] - adId:call.arguments[@"adId"]]; + FLTInterstitialAd *ad = [[FLTInterstitialAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + request:call.arguments[@"request"] + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadAdManagerInterstitialAd"]) { - FLTGAMInterstitialAd *ad = [[FLTGAMInterstitialAd alloc] - initWithAdUnitId:call.arguments[@"adUnitId"] - request:call.arguments[@"request"] - adId:call.arguments[@"adId"]]; + FLTGAMInterstitialAd *ad = + [[FLTGAMInterstitialAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + request:call.arguments[@"request"] + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadRewardedAd"]) { @@ -462,17 +411,15 @@ - (void)handleMethodCall:(FlutterMethodCall *)call } else if ([FLTAdUtil isNotNull:call.arguments[@"adManagerRequest"]]) { request = call.arguments[@"adManagerRequest"]; } else { - result([FlutterError - errorWithCode:@"InvalidRequest" - message:@"A null or invalid ad request was provided." - details:nil]); + result([FlutterError errorWithCode:@"InvalidRequest" + message:@"A null or invalid ad request was provided." + details:nil]); return; } - FLTRewardedAd *ad = - [[FLTRewardedAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - request:request - adId:call.arguments[@"adId"]]; + FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + request:request + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadRewardedInterstitialAd"]) { @@ -482,17 +429,16 @@ - (void)handleMethodCall:(FlutterMethodCall *)call } else if ([FLTAdUtil isNotNull:call.arguments[@"adManagerRequest"]]) { request = call.arguments[@"adManagerRequest"]; } else { - result([FlutterError - errorWithCode:@"InvalidRequest" - message:@"A null or invalid ad request was provided." - details:nil]); + result([FlutterError errorWithCode:@"InvalidRequest" + message:@"A null or invalid ad request was provided." + details:nil]); return; } - FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] - initWithAdUnitId:call.arguments[@"adUnitId"] - request:request - adId:call.arguments[@"adId"]]; + FLTRewardedInterstitialAd *ad = + [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + request:request + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadAppOpenAd"]) { @@ -502,31 +448,27 @@ - (void)handleMethodCall:(FlutterMethodCall *)call } else if ([FLTAdUtil isNotNull:call.arguments[@"adManagerRequest"]]) { request = call.arguments[@"adManagerRequest"]; } else { - result([FlutterError - errorWithCode:@"InvalidRequest" - message:@"A null or invalid ad request was provided." - details:nil]); + result([FlutterError errorWithCode:@"InvalidRequest" + message:@"A null or invalid ad request was provided." + details:nil]); return; } - FLTAppOpenAd *ad = - [[FLTAppOpenAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - request:request - adId:call.arguments[@"adId"]]; + FLTAppOpenAd *ad = [[FLTAppOpenAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + request:request + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"disposeAd"]) { [_manager dispose:call.arguments[@"adId"]]; result(nil); } else if ([call.method isEqualToString:@"showAdWithoutView"]) { - [_manager showAdWithID:call.arguments[@"adId"] - rootViewController:rootController]; + [_manager showAdWithID:call.arguments[@"adId"] rootViewController:rootController]; result(nil); - } else if ([call.method - isEqualToString:@"AdSize#getAnchoredAdaptiveBannerAdSize"]) { - FLTAnchoredAdaptiveBannerSize *size = [[FLTAnchoredAdaptiveBannerSize alloc] - initWithFactory:[[FLTAdSizeFactory alloc] init] - orientation:call.arguments[@"orientation"] - width:call.arguments[@"width"]]; + } else if ([call.method isEqualToString:@"AdSize#getAnchoredAdaptiveBannerAdSize"]) { + FLTAnchoredAdaptiveBannerSize *size = + [[FLTAnchoredAdaptiveBannerSize alloc] initWithFactory:[[FLTAdSizeFactory alloc] init] + orientation:call.arguments[@"orientation"] + width:call.arguments[@"width"]]; if (IsGADAdSizeValid(size.size)) { result(size.height); } else { @@ -544,17 +486,14 @@ - (void)handleMethodCall:(FlutterMethodCall *)call } else { result(FlutterMethodNotImplemented); } - } else if ([call.method - isEqualToString:@"setServerSideVerificationOptions"]) { + } else if ([call.method isEqualToString:@"setServerSideVerificationOptions"]) { id ad = [_manager adFor:call.arguments[@"adId"]]; - FLTServerSideVerificationOptions *options = - call.arguments[@"serverSideVerificationOptions"]; + FLTServerSideVerificationOptions *options = call.arguments[@"serverSideVerificationOptions"]; if ([ad isKindOfClass:[FLTRewardedAd class]]) { FLTRewardedAd *rewardedAd = (FLTRewardedAd *)ad; [rewardedAd setServerSideVerificationOptions:options]; } else if ([ad isKindOfClass:[FLTRewardedInterstitialAd class]]) { - FLTRewardedInterstitialAd *rewardedInterstitialAd = - (FLTRewardedInterstitialAd *)ad; + FLTRewardedInterstitialAd *rewardedInterstitialAd = (FLTRewardedInterstitialAd *)ad; [rewardedInterstitialAd setServerSideVerificationOptions:options]; } else { NSLog(@"Error - setServerSideVerificationOptions called on missing or " diff --git a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsReaderWriter_Internal.h b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsReaderWriter_Internal.h index 5d8092afa..bb4ce9544 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsReaderWriter_Internal.h +++ b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsReaderWriter_Internal.h @@ -12,27 +12,23 @@ // See the License for the specific language governing permissions and // limitations under the License. +#import #import "FLTAd_Internal.h" #import "FLTMediationNetworkExtrasProvider.h" -#import @class FLTAdSizeFactory; @interface FLTGoogleMobileAdsReaderWriter : FlutterStandardReaderWriter @property(readonly) FLTAdSizeFactory *_Nonnull adSizeFactory; -@property id< - FLTMediationNetworkExtrasProvider> _Nullable mediationNetworkExtrasProvider; +@property id _Nullable mediationNetworkExtrasProvider; -- (instancetype _Nonnull)initWithFactory: - (FLTAdSizeFactory *_Nonnull)adSizeFactory; +- (instancetype _Nonnull)initWithFactory:(FLTAdSizeFactory *_Nonnull)adSizeFactory; @end @interface FLTGoogleMobileAdsReader : FlutterStandardReader @property(readonly) FLTAdSizeFactory *_Nonnull adSizeFactory; -@property id< - FLTMediationNetworkExtrasProvider> _Nullable mediationNetworkExtrasProvider; +@property id _Nullable mediationNetworkExtrasProvider; -- (instancetype _Nonnull)initWithFactory: - (FLTAdSizeFactory *_Nonnull)adSizeFactory +- (instancetype _Nonnull)initWithFactory:(FLTAdSizeFactory *_Nonnull)adSizeFactory data:(NSData *_Nonnull)data; @end diff --git a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsReaderWriter_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsReaderWriter_Internal.m index 24572e60f..34a1a7435 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsReaderWriter_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsReaderWriter_Internal.m @@ -59,8 +59,7 @@ - (instancetype)init { return [self initWithFactory:[[FLTAdSizeFactory alloc] init]]; } -- (instancetype _Nonnull)initWithFactory: - (FLTAdSizeFactory *_Nonnull)adSizeFactory { +- (instancetype _Nonnull)initWithFactory:(FLTAdSizeFactory *_Nonnull)adSizeFactory { self = [super init]; if (self) { _adSizeFactory = adSizeFactory; @@ -70,14 +69,12 @@ - (instancetype _Nonnull)initWithFactory: - (FlutterStandardReader *_Nonnull)readerWithData:(NSData *_Nonnull)data { FLTGoogleMobileAdsReader *reader = - [[FLTGoogleMobileAdsReader alloc] initWithFactory:_adSizeFactory - data:data]; + [[FLTGoogleMobileAdsReader alloc] initWithFactory:_adSizeFactory data:data]; reader.mediationNetworkExtrasProvider = _mediationNetworkExtrasProvider; return reader; } -- (FlutterStandardWriter *_Nonnull)writerWithData: - (NSMutableData *_Nonnull)data { +- (FlutterStandardWriter *_Nonnull)writerWithData:(NSMutableData *_Nonnull)data { return [[FLTGoogleMobileAdsWriter alloc] initWithData:data]; } @end @@ -85,8 +82,7 @@ - (FlutterStandardWriter *_Nonnull)writerWithData: @implementation FLTGoogleMobileAdsReader { NSString *_requestAgent; } -- (instancetype _Nonnull)initWithFactory: - (FLTAdSizeFactory *_Nonnull)adSizeFactory +- (instancetype _Nonnull)initWithFactory:(FLTAdSizeFactory *_Nonnull)adSizeFactory data:(NSData *_Nonnull)data { self = [super initWithData:data]; if (self) { @@ -99,248 +95,228 @@ - (instancetype _Nonnull)initWithFactory: - (id _Nullable)readValueOfType:(UInt8)type { FLTAdMobField field = (FLTAdMobField)type; switch (field) { - case FLTAdMobFieldAdSize: - return [[FLTAdSize alloc] - initWithWidth:[self readValueOfType:[self readByte]] - height:[self readValueOfType:[self readByte]]]; - case FLTAdMobFieldFluidAdSize: - return [[FLTFluidSize alloc] init]; - case FLTAdMobFieldAdRequest: { - FLTAdRequest *request = [[FLTAdRequest alloc] init]; + case FLTAdMobFieldAdSize: + return [[FLTAdSize alloc] initWithWidth:[self readValueOfType:[self readByte]] + height:[self readValueOfType:[self readByte]]]; + case FLTAdMobFieldFluidAdSize: + return [[FLTFluidSize alloc] init]; + case FLTAdMobFieldAdRequest: { + FLTAdRequest *request = [[FLTAdRequest alloc] init]; - request.keywords = [self readValueOfType:[self readByte]]; - request.contentURL = [self readValueOfType:[self readByte]]; + request.keywords = [self readValueOfType:[self readByte]]; + request.contentURL = [self readValueOfType:[self readByte]]; - NSNumber *nonPersonalizedAds = [self readValueOfType:[self readByte]]; - request.nonPersonalizedAds = nonPersonalizedAds.boolValue; - request.neighboringContentURLs = [self readValueOfType:[self readByte]]; - request.mediationExtrasIdentifier = [self readValueOfType:[self readByte]]; - request.mediationNetworkExtrasProvider = _mediationNetworkExtrasProvider; - request.adMobExtras = [self readValueOfType:[self readByte]]; - request.requestAgent = _requestAgent; - request.mediationExtras = [self readValueOfType:[self readByte]]; - return request; - } - case FLTAdmobFieldMediationExtras: { - id flutterMediationExtras = - [[NSClassFromString([self readValueOfType:[self readByte]]) alloc] - init]; - NSMutableDictionary *flutterExtras = [self readValueOfType:[self readByte]]; - flutterMediationExtras.extras = flutterExtras; - return flutterMediationExtras; - } - case FLTAdMobFieldRewardItem: { - return [[FLTRewardItem alloc] - initWithAmount:[self readValueOfType:[self readByte]] - type:[self readValueOfType:[self readByte]]]; - } - case FLTAdmobFieldGadResponseInfo: { - NSString *responseIdentifier = [self readValueOfType:[self readByte]]; - NSString *adNetworkClassName = [self readValueOfType:[self readByte]]; - NSArray *adNetworkInfoArray = - [self readValueOfType:[self readByte]]; - FLTGADAdNetworkResponseInfo *loadedResponseInfo = - [self readValueOfType:[self readByte]]; - NSDictionary *extrasDictionary = - [self readValueOfType:[self readByte]]; - FLTGADResponseInfo *gadResponseInfo = [[FLTGADResponseInfo alloc] init]; - gadResponseInfo.adNetworkClassName = adNetworkClassName; - gadResponseInfo.responseIdentifier = responseIdentifier; - gadResponseInfo.adNetworkInfoArray = adNetworkInfoArray; - gadResponseInfo.loadedAdNetworkResponseInfo = loadedResponseInfo; - gadResponseInfo.extrasDictionary = extrasDictionary; - return gadResponseInfo; - } - case FLTAdmobFieldGADAdNetworkResponseInfo: { - NSString *adNetworkClassName = [self readValueOfType:[self readByte]]; - NSNumber *latency = [self readValueOfType:[self readByte]]; - NSString *dictionaryDescription = [self readValueOfType:[self readByte]]; - NSDictionary *adUnitMapping = - [self readValueOfType:[self readByte]]; - NSError *error = [self readValueOfType:[self readByte]]; - NSString *adSourceName = [self readValueOfType:[self readByte]]; - NSString *adSourceID = [self readValueOfType:[self readByte]]; - NSString *adSourceInstanceName = [self readValueOfType:[self readByte]]; - NSString *adSourceInstanceID = [self readValueOfType:[self readByte]]; - FLTGADAdNetworkResponseInfo *adNetworkResponseInfo = - [[FLTGADAdNetworkResponseInfo alloc] init]; - adNetworkResponseInfo.adNetworkClassName = adNetworkClassName; - adNetworkResponseInfo.latency = latency; - adNetworkResponseInfo.dictionaryDescription = dictionaryDescription; - adNetworkResponseInfo.adUnitMapping = adUnitMapping; - adNetworkResponseInfo.error = error; - adNetworkResponseInfo.adSourceName = adSourceName; - adNetworkResponseInfo.adSourceID = adSourceID; - adNetworkResponseInfo.adSourceInstanceName = adSourceInstanceName; - adNetworkResponseInfo.adSourceInstanceID = adSourceInstanceID; + NSNumber *nonPersonalizedAds = [self readValueOfType:[self readByte]]; + request.nonPersonalizedAds = nonPersonalizedAds.boolValue; + request.neighboringContentURLs = [self readValueOfType:[self readByte]]; + request.mediationExtrasIdentifier = [self readValueOfType:[self readByte]]; + request.mediationNetworkExtrasProvider = _mediationNetworkExtrasProvider; + request.adMobExtras = [self readValueOfType:[self readByte]]; + request.requestAgent = _requestAgent; + request.mediationExtras = [self readValueOfType:[self readByte]]; + return request; + } + case FLTAdmobFieldMediationExtras: { + id flutterMediationExtras = + [[NSClassFromString([self readValueOfType:[self readByte]]) alloc] init]; + NSMutableDictionary *flutterExtras = [self readValueOfType:[self readByte]]; + flutterMediationExtras.extras = flutterExtras; + return flutterMediationExtras; + } + case FLTAdMobFieldRewardItem: { + return [[FLTRewardItem alloc] initWithAmount:[self readValueOfType:[self readByte]] + type:[self readValueOfType:[self readByte]]]; + } + case FLTAdmobFieldGadResponseInfo: { + NSString *responseIdentifier = [self readValueOfType:[self readByte]]; + NSString *adNetworkClassName = [self readValueOfType:[self readByte]]; + NSArray *adNetworkInfoArray = + [self readValueOfType:[self readByte]]; + FLTGADAdNetworkResponseInfo *loadedResponseInfo = [self readValueOfType:[self readByte]]; + NSDictionary *extrasDictionary = [self readValueOfType:[self readByte]]; + FLTGADResponseInfo *gadResponseInfo = [[FLTGADResponseInfo alloc] init]; + gadResponseInfo.adNetworkClassName = adNetworkClassName; + gadResponseInfo.responseIdentifier = responseIdentifier; + gadResponseInfo.adNetworkInfoArray = adNetworkInfoArray; + gadResponseInfo.loadedAdNetworkResponseInfo = loadedResponseInfo; + gadResponseInfo.extrasDictionary = extrasDictionary; + return gadResponseInfo; + } + case FLTAdmobFieldGADAdNetworkResponseInfo: { + NSString *adNetworkClassName = [self readValueOfType:[self readByte]]; + NSNumber *latency = [self readValueOfType:[self readByte]]; + NSString *dictionaryDescription = [self readValueOfType:[self readByte]]; + NSDictionary *adUnitMapping = [self readValueOfType:[self readByte]]; + NSError *error = [self readValueOfType:[self readByte]]; + NSString *adSourceName = [self readValueOfType:[self readByte]]; + NSString *adSourceID = [self readValueOfType:[self readByte]]; + NSString *adSourceInstanceName = [self readValueOfType:[self readByte]]; + NSString *adSourceInstanceID = [self readValueOfType:[self readByte]]; + FLTGADAdNetworkResponseInfo *adNetworkResponseInfo = + [[FLTGADAdNetworkResponseInfo alloc] init]; + adNetworkResponseInfo.adNetworkClassName = adNetworkClassName; + adNetworkResponseInfo.latency = latency; + adNetworkResponseInfo.dictionaryDescription = dictionaryDescription; + adNetworkResponseInfo.adUnitMapping = adUnitMapping; + adNetworkResponseInfo.error = error; + adNetworkResponseInfo.adSourceName = adSourceName; + adNetworkResponseInfo.adSourceID = adSourceID; + adNetworkResponseInfo.adSourceInstanceName = adSourceInstanceName; + adNetworkResponseInfo.adSourceInstanceID = adSourceInstanceID; - return adNetworkResponseInfo; - } - case FLTAdMobFieldLoadError: { - NSNumber *code = [self readValueOfType:[self readByte]]; - NSString *domain = [self readValueOfType:[self readByte]]; - NSString *message = [self readValueOfType:[self readByte]]; - FLTGADResponseInfo *responseInfo = [self readValueOfType:[self readByte]]; - FLTLoadAdError *loadAdError = [[FLTLoadAdError alloc] init]; - loadAdError.code = code.longValue; - loadAdError.domain = domain; - loadAdError.message = message; - loadAdError.responseInfo = responseInfo; - return loadAdError; - } - case FLTAdmobFieldAdError: { - NSNumber *code = [self readValueOfType:[self readByte]]; - NSString *domain = [self readValueOfType:[self readByte]]; - NSString *message = [self readValueOfType:[self readByte]]; - return [NSError errorWithDomain:domain - code:code.longValue - userInfo:@{NSLocalizedDescriptionKey : message}]; - } - case FLTAdMobFieldAdManagerAdRequest: { - FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init]; - request.keywords = [self readValueOfType:[self readByte]]; - request.contentURL = [self readValueOfType:[self readByte]]; - request.customTargeting = [self readValueOfType:[self readByte]]; - request.customTargetingLists = [self readValueOfType:[self readByte]]; - NSNumber *nonPersonalizedAds = [self readValueOfType:[self readByte]]; - request.nonPersonalizedAds = nonPersonalizedAds.boolValue; - request.neighboringContentURLs = [self readValueOfType:[self readByte]]; - request.pubProvidedID = [self readValueOfType:[self readByte]]; - request.mediationExtrasIdentifier = [self readValueOfType:[self readByte]]; - request.mediationNetworkExtrasProvider = _mediationNetworkExtrasProvider; - request.adMobExtras = [self readValueOfType:[self readByte]]; - request.requestAgent = _requestAgent; - request.mediationExtras = [self readValueOfType:[self readByte]]; - return request; - } - case FLTAdMobFieldAdapterInitializationState: { - NSString *state = [self readValueOfType:[self readByte]]; - if (!state) { + return adNetworkResponseInfo; + } + case FLTAdMobFieldLoadError: { + NSNumber *code = [self readValueOfType:[self readByte]]; + NSString *domain = [self readValueOfType:[self readByte]]; + NSString *message = [self readValueOfType:[self readByte]]; + FLTGADResponseInfo *responseInfo = [self readValueOfType:[self readByte]]; + FLTLoadAdError *loadAdError = [[FLTLoadAdError alloc] init]; + loadAdError.code = code.longValue; + loadAdError.domain = domain; + loadAdError.message = message; + loadAdError.responseInfo = responseInfo; + return loadAdError; + } + case FLTAdmobFieldAdError: { + NSNumber *code = [self readValueOfType:[self readByte]]; + NSString *domain = [self readValueOfType:[self readByte]]; + NSString *message = [self readValueOfType:[self readByte]]; + return [NSError errorWithDomain:domain + code:code.longValue + userInfo:@{NSLocalizedDescriptionKey : message}]; + } + case FLTAdMobFieldAdManagerAdRequest: { + FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init]; + request.keywords = [self readValueOfType:[self readByte]]; + request.contentURL = [self readValueOfType:[self readByte]]; + request.customTargeting = [self readValueOfType:[self readByte]]; + request.customTargetingLists = [self readValueOfType:[self readByte]]; + NSNumber *nonPersonalizedAds = [self readValueOfType:[self readByte]]; + request.nonPersonalizedAds = nonPersonalizedAds.boolValue; + request.neighboringContentURLs = [self readValueOfType:[self readByte]]; + request.pubProvidedID = [self readValueOfType:[self readByte]]; + request.mediationExtrasIdentifier = [self readValueOfType:[self readByte]]; + request.mediationNetworkExtrasProvider = _mediationNetworkExtrasProvider; + request.adMobExtras = [self readValueOfType:[self readByte]]; + request.requestAgent = _requestAgent; + request.mediationExtras = [self readValueOfType:[self readByte]]; + return request; + } + case FLTAdMobFieldAdapterInitializationState: { + NSString *state = [self readValueOfType:[self readByte]]; + if (!state) { + return nil; + } else if ([@"notReady" isEqualToString:state]) { + return @(FLTAdapterInitializationStateNotReady); + } else if ([@"ready" isEqualToString:state]) { + return @(FLTAdapterInitializationStateReady); + } + NSLog(@"Failed to interpret AdapterInitializationState of: %@", state); return nil; - } else if ([@"notReady" isEqualToString:state]) { - return @(FLTAdapterInitializationStateNotReady); - } else if ([@"ready" isEqualToString:state]) { - return @(FLTAdapterInitializationStateReady); } - NSLog(@"Failed to interpret AdapterInitializationState of: %@", state); - return nil; - } - case FLTAdMobFieldAdapterStatus: { - FLTAdapterStatus *status = [[FLTAdapterStatus alloc] init]; - status.state = [self readValueOfType:[self readByte]]; - status.statusDescription = [self readValueOfType:[self readByte]]; - status.latency = [self readValueOfType:[self readByte]]; - return status; - } - case FLTAdMobFieldInitializationStatus: { - FLTInitializationStatus *status = [[FLTInitializationStatus alloc] init]; - status.adapterStatuses = [self readValueOfType:[self readByte]]; - return status; - } - case FLTAdmobFieldServerSideVerificationOptions: { - FLTServerSideVerificationOptions *options = - [[FLTServerSideVerificationOptions alloc] init]; - options.userIdentifier = [self readValueOfType:[self readByte]]; - options.customRewardString = [self readValueOfType:[self readByte]]; - return options; - } - case FLTAdmobFieldAnchoredAdaptiveBannerAdSize: { - NSString *orientation = [self readValueOfType:[self readByte]]; - NSNumber *width = [self readValueOfType:[self readByte]]; - return [[FLTAnchoredAdaptiveBannerSize alloc] initWithFactory:_adSizeFactory - orientation:orientation - width:width]; - } - case FLTAdmobFieldSmartBannerAdSize: - return [[FLTSmartBannerSize alloc] - initWithOrientation:[self readValueOfType:[self readByte]]]; - case FLTAdmobFieldNativeAdOptions: { - return [[FLTNativeAdOptions alloc] - initWithAdChoicesPlacement:[self readValueOfType:[self readByte]] - mediaAspectRatio:[self readValueOfType:[self readByte]] - videoOptions:[self readValueOfType:[self readByte]] - requestCustomMuteThisAd:[self readValueOfType:[self readByte]] - shouldRequestMultipleImages:[self readValueOfType:[self readByte]] - shouldReturnUrlsForImageAssets:[self readValueOfType:[self readByte]]]; - } - case FLTAdmobFieldVideoOptions: { - return [[FLTVideoOptions alloc] - initWithClickToExpandRequested:[self readValueOfType:[self readByte]] - customControlsRequested:[self readValueOfType:[self readByte]] - startMuted:[self readValueOfType:[self readByte]]]; - } - case FLTAdmobRequestConfigurationParams: { - GADMobileAds.sharedInstance.requestConfiguration.maxAdContentRating = - [self readValueOfType:[self readByte]]; - GADMobileAds.sharedInstance.requestConfiguration - .tagForChildDirectedTreatment = [self readValueOfType:[self readByte]]; - GADMobileAds.sharedInstance.requestConfiguration.tagForUnderAgeOfConsent = - [self readValueOfType:[self readByte]]; - GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = - [self readValueOfType:[self readByte]]; - return GADMobileAds.sharedInstance.requestConfiguration; - } - case FLTAdmobFieldInlineAdaptiveAdSize: { - return [[FLTInlineAdaptiveBannerSize alloc] - initWithFactory:_adSizeFactory - width:[self readValueOfType:[self readByte]] - maxHeight:[self readValueOfType:[self readByte]] - orientation:[self readValueOfType:[self readByte]]]; - } - case FLTAdmobFieldNativeTemplateStyle: { - FLTNativeTemplateType *templateType = - [self readValueOfType:[self readByte]]; - FLTNativeTemplateColor *mainBackgroundColor = - [self readValueOfType:[self readByte]]; - FLTNativeTemplateTextStyle *callToActionStyle = - [self readValueOfType:[self readByte]]; - FLTNativeTemplateTextStyle *primaryTextStyle = - [self readValueOfType:[self readByte]]; - FLTNativeTemplateTextStyle *secondaryTextStyle = - [self readValueOfType:[self readByte]]; - FLTNativeTemplateTextStyle *tertiaryTextStyle = - [self readValueOfType:[self readByte]]; - NSNumber *cornerRadius = [self readValueOfType:[self readByte]]; - return - [[FLTNativeTemplateStyle alloc] initWithTemplateType:templateType - mainBackgroundColor:mainBackgroundColor - callToActionStyle:callToActionStyle - primaryTextStyle:primaryTextStyle - secondaryTextStyle:secondaryTextStyle - tertiaryTextStyle:tertiaryTextStyle - cornerRadius:cornerRadius]; - } - case FLTAdmobFieldNativeTemplateTextStyle: { - FLTNativeTemplateColor *textColor = [self readValueOfType:[self readByte]]; - FLTNativeTemplateColor *backgroundColor = - [self readValueOfType:[self readByte]]; - FLTNativeTemplateFontStyleWrapper *fontStyle = - [self readValueOfType:[self readByte]]; - NSNumber *size = [self readValueOfType:[self readByte]]; - return [[FLTNativeTemplateTextStyle alloc] initWithTextColor:textColor - backgroundColor:backgroundColor - fontStyle:fontStyle - size:size]; - } - case FLTAdmobFieldNativeTemplateFontStyle: { - NSNumber *fontStyleIndex = [self readValueOfType:[self readByte]]; - return [[FLTNativeTemplateFontStyleWrapper alloc] - initWithInt:fontStyleIndex.intValue]; - } - case FLTAdmobFieldNativeTemplateType: { - NSNumber *templateIndex = [self readValueOfType:[self readByte]]; - return [[FLTNativeTemplateType alloc] initWithInt:templateIndex.intValue]; - } - case FLTAdmobFieldNativeTemplateColor: { - NSNumber *alpha = [self readValueOfType:[self readByte]]; - NSNumber *red = [self readValueOfType:[self readByte]]; - NSNumber *green = [self readValueOfType:[self readByte]]; - NSNumber *blue = [self readValueOfType:[self readByte]]; - return [[FLTNativeTemplateColor alloc] initWithAlpha:alpha - red:red - green:green - blue:blue]; - } + case FLTAdMobFieldAdapterStatus: { + FLTAdapterStatus *status = [[FLTAdapterStatus alloc] init]; + status.state = [self readValueOfType:[self readByte]]; + status.statusDescription = [self readValueOfType:[self readByte]]; + status.latency = [self readValueOfType:[self readByte]]; + return status; + } + case FLTAdMobFieldInitializationStatus: { + FLTInitializationStatus *status = [[FLTInitializationStatus alloc] init]; + status.adapterStatuses = [self readValueOfType:[self readByte]]; + return status; + } + case FLTAdmobFieldServerSideVerificationOptions: { + FLTServerSideVerificationOptions *options = [[FLTServerSideVerificationOptions alloc] init]; + options.userIdentifier = [self readValueOfType:[self readByte]]; + options.customRewardString = [self readValueOfType:[self readByte]]; + return options; + } + case FLTAdmobFieldAnchoredAdaptiveBannerAdSize: { + NSString *orientation = [self readValueOfType:[self readByte]]; + NSNumber *width = [self readValueOfType:[self readByte]]; + return [[FLTAnchoredAdaptiveBannerSize alloc] initWithFactory:_adSizeFactory + orientation:orientation + width:width]; + } + case FLTAdmobFieldSmartBannerAdSize: + return + [[FLTSmartBannerSize alloc] initWithOrientation:[self readValueOfType:[self readByte]]]; + case FLTAdmobFieldNativeAdOptions: { + return [[FLTNativeAdOptions alloc] + initWithAdChoicesPlacement:[self readValueOfType:[self readByte]] + mediaAspectRatio:[self readValueOfType:[self readByte]] + videoOptions:[self readValueOfType:[self readByte]] + requestCustomMuteThisAd:[self readValueOfType:[self readByte]] + shouldRequestMultipleImages:[self readValueOfType:[self readByte]] + shouldReturnUrlsForImageAssets:[self readValueOfType:[self readByte]]]; + } + case FLTAdmobFieldVideoOptions: { + return [[FLTVideoOptions alloc] + initWithClickToExpandRequested:[self readValueOfType:[self readByte]] + customControlsRequested:[self readValueOfType:[self readByte]] + startMuted:[self readValueOfType:[self readByte]]]; + } + case FLTAdmobRequestConfigurationParams: { + GADMobileAds.sharedInstance.requestConfiguration.maxAdContentRating = + [self readValueOfType:[self readByte]]; + GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment = + [self readValueOfType:[self readByte]]; + GADMobileAds.sharedInstance.requestConfiguration.tagForUnderAgeOfConsent = + [self readValueOfType:[self readByte]]; + GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = + [self readValueOfType:[self readByte]]; + return GADMobileAds.sharedInstance.requestConfiguration; + } + case FLTAdmobFieldInlineAdaptiveAdSize: { + return [[FLTInlineAdaptiveBannerSize alloc] + initWithFactory:_adSizeFactory + width:[self readValueOfType:[self readByte]] + maxHeight:[self readValueOfType:[self readByte]] + orientation:[self readValueOfType:[self readByte]]]; + } + case FLTAdmobFieldNativeTemplateStyle: { + FLTNativeTemplateType *templateType = [self readValueOfType:[self readByte]]; + FLTNativeTemplateColor *mainBackgroundColor = [self readValueOfType:[self readByte]]; + FLTNativeTemplateTextStyle *callToActionStyle = [self readValueOfType:[self readByte]]; + FLTNativeTemplateTextStyle *primaryTextStyle = [self readValueOfType:[self readByte]]; + FLTNativeTemplateTextStyle *secondaryTextStyle = [self readValueOfType:[self readByte]]; + FLTNativeTemplateTextStyle *tertiaryTextStyle = [self readValueOfType:[self readByte]]; + NSNumber *cornerRadius = [self readValueOfType:[self readByte]]; + return [[FLTNativeTemplateStyle alloc] initWithTemplateType:templateType + mainBackgroundColor:mainBackgroundColor + callToActionStyle:callToActionStyle + primaryTextStyle:primaryTextStyle + secondaryTextStyle:secondaryTextStyle + tertiaryTextStyle:tertiaryTextStyle + cornerRadius:cornerRadius]; + } + case FLTAdmobFieldNativeTemplateTextStyle: { + FLTNativeTemplateColor *textColor = [self readValueOfType:[self readByte]]; + FLTNativeTemplateColor *backgroundColor = [self readValueOfType:[self readByte]]; + FLTNativeTemplateFontStyleWrapper *fontStyle = [self readValueOfType:[self readByte]]; + NSNumber *size = [self readValueOfType:[self readByte]]; + return [[FLTNativeTemplateTextStyle alloc] initWithTextColor:textColor + backgroundColor:backgroundColor + fontStyle:fontStyle + size:size]; + } + case FLTAdmobFieldNativeTemplateFontStyle: { + NSNumber *fontStyleIndex = [self readValueOfType:[self readByte]]; + return [[FLTNativeTemplateFontStyleWrapper alloc] initWithInt:fontStyleIndex.intValue]; + } + case FLTAdmobFieldNativeTemplateType: { + NSNumber *templateIndex = [self readValueOfType:[self readByte]]; + return [[FLTNativeTemplateType alloc] initWithInt:templateIndex.intValue]; + } + case FLTAdmobFieldNativeTemplateColor: { + NSNumber *alpha = [self readValueOfType:[self readByte]]; + NSNumber *red = [self readValueOfType:[self readByte]]; + NSNumber *green = [self readValueOfType:[self readByte]]; + NSNumber *blue = [self readValueOfType:[self readByte]]; + return [[FLTNativeTemplateColor alloc] initWithAlpha:alpha red:red green:green blue:blue]; + } } return [super readValueOfType:type]; } @@ -356,8 +332,7 @@ - (void)writeAdSize:(FLTAdSize *_Nonnull)value { [self writeValue:size.orientation]; } else if ([value isKindOfClass:[FLTAnchoredAdaptiveBannerSize class]]) { [self writeByte:FLTAdmobFieldAnchoredAdaptiveBannerAdSize]; - FLTAnchoredAdaptiveBannerSize *size = - (FLTAnchoredAdaptiveBannerSize *)value; + FLTAnchoredAdaptiveBannerSize *size = (FLTAnchoredAdaptiveBannerSize *)value; [self writeValue:size.orientation]; [self writeValue:size.width]; } else if ([value isKindOfClass:[FLTSmartBannerSize class]]) { @@ -448,15 +423,12 @@ - (void)writeValue:(id)value { [self writeByte:FLTAdMobFieldAdapterInitializationState]; if (!status.state) { [self writeValue:[NSNull null]]; - } else if (status.state.unsignedLongValue == - FLTAdapterInitializationStateNotReady) { + } else if (status.state.unsignedLongValue == FLTAdapterInitializationStateNotReady) { [self writeValue:@"notReady"]; - } else if (status.state.unsignedLongValue == - FLTAdapterInitializationStateReady) { + } else if (status.state.unsignedLongValue == FLTAdapterInitializationStateReady) { [self writeValue:@"ready"]; } else { - NSLog(@"Failed to interpret AdapterInitializationState of: %@", - status.state); + NSLog(@"Failed to interpret AdapterInitializationState of: %@", status.state); [self writeValue:[NSNull null]]; } [self writeValue:status.statusDescription]; diff --git a/packages/google_mobile_ads/ios/Classes/FLTMediationNetworkExtrasProvider.h b/packages/google_mobile_ads/ios/Classes/FLTMediationNetworkExtrasProvider.h index 3f2c9281e..d91e01ee2 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTMediationNetworkExtrasProvider.h +++ b/packages/google_mobile_ads/ios/Classes/FLTMediationNetworkExtrasProvider.h @@ -35,8 +35,8 @@ __attribute__((deprecated)) * which extras to include for an ad request, beyond just the ad unit. * @return an array of GADAdNetworkExtras to include in the ad request. */ -- (NSArray> *_Nullable) - getMediationExtras:(NSString *_Nonnull)adUnitId - mediationExtrasIdentifier:(NSString *_Nullable)mediationExtrasIdentifier; +- (NSArray> *_Nullable)getMediationExtras:(NSString *_Nonnull)adUnitId + mediationExtrasIdentifier: + (NSString *_Nullable)mediationExtrasIdentifier; @end diff --git a/packages/google_mobile_ads/ios/Classes/FLTMobileAds_Internal.h b/packages/google_mobile_ads/ios/Classes/FLTMobileAds_Internal.h index 06414f4d3..5d46def90 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTMobileAds_Internal.h +++ b/packages/google_mobile_ads/ios/Classes/FLTMobileAds_Internal.h @@ -51,7 +51,6 @@ typedef NS_ENUM(NSUInteger, FLTAdapterInitializationState) { @interface FLTServerSideVerificationOptions : NSObject @property(nonatomic, copy, nullable) NSString *userIdentifier; @property(nonatomic, copy, nullable) NSString *customRewardString; -- (GADServerSideVerificationOptions *_Nonnull) - asGADServerSideVerificationOptions; +- (GADServerSideVerificationOptions *_Nonnull)asGADServerSideVerificationOptions; @end NS_ASSUME_NONNULL_END diff --git a/packages/google_mobile_ads/ios/Classes/FLTMobileAds_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTMobileAds_Internal.m index cb3a3fba2..9dd6d66be 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTMobileAds_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTMobileAds_Internal.m @@ -19,12 +19,12 @@ - (instancetype)initWithStatus:(GADAdapterStatus *)status { self = [self init]; if (self) { switch (status.state) { - case GADAdapterInitializationStateNotReady: - _state = @(FLTAdapterInitializationStateNotReady); - break; - case GADAdapterInitializationStateReady: - _state = @(FLTAdapterInitializationStateReady); - break; + case GADAdapterInitializationStateNotReady: + _state = @(FLTAdapterInitializationStateNotReady); + break; + case GADAdapterInitializationStateReady: + _state = @(FLTAdapterInitializationStateReady); + break; } _statusDescription = status.description; _latency = @(status.latency); @@ -39,8 +39,8 @@ - (instancetype)initWithStatus:(GADInitializationStatus *)status { if (self) { NSMutableDictionary *newDictionary = [NSMutableDictionary dictionary]; for (NSString *name in status.adapterStatusesByClassName.allKeys) { - FLTAdapterStatus *adapterStatus = [[FLTAdapterStatus alloc] - initWithStatus:status.adapterStatusesByClassName[name]]; + FLTAdapterStatus *adapterStatus = + [[FLTAdapterStatus alloc] initWithStatus:status.adapterStatusesByClassName[name]]; [newDictionary setValue:adapterStatus forKey:name]; } _adapterStatuses = newDictionary; @@ -50,10 +50,8 @@ - (instancetype)initWithStatus:(GADInitializationStatus *)status { @end @implementation FLTServerSideVerificationOptions -- (GADServerSideVerificationOptions *_Nonnull) - asGADServerSideVerificationOptions { - GADServerSideVerificationOptions *options = - [[GADServerSideVerificationOptions alloc] init]; +- (GADServerSideVerificationOptions *_Nonnull)asGADServerSideVerificationOptions { + GADServerSideVerificationOptions *options = [[GADServerSideVerificationOptions alloc] init]; options.userIdentifier = _userIdentifier; options.customRewardString = _customRewardString; return options; diff --git a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateFontStyle.m b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateFontStyle.m index 1d1fdbed1..f61fa6c2d 100644 --- a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateFontStyle.m +++ b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateFontStyle.m @@ -28,17 +28,17 @@ - (instancetype _Nonnull)initWithInt:(int)intValue { - (FLTNativeTemplateFontStyle)fontStyle { switch (_intValue) { - case 0: - return FLTNativeTemplateFontNormal; - case 1: - return FLTNativeTemplateFontBold; - case 2: - return FLTNativeTemplateFontItalic; - case 3: - return FLTNativeTemplateFontMonospace; - default: - NSLog(@"Unknown FLTNativeTemplateFontStyle value: %d", _intValue); - return FLTNativeTemplateFontNormal; + case 0: + return FLTNativeTemplateFontNormal; + case 1: + return FLTNativeTemplateFontBold; + case 2: + return FLTNativeTemplateFontItalic; + case 3: + return FLTNativeTemplateFontMonospace; + default: + NSLog(@"Unknown FLTNativeTemplateFontStyle value: %d", _intValue); + return FLTNativeTemplateFontNormal; } } diff --git a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateStyle.h b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateStyle.h index 58ecc30d6..627485d35 100644 --- a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateStyle.h +++ b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateStyle.h @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +#import +#import +#import #import "FLTNativeTemplateColor.h" #import "FLTNativeTemplateTextStyle.h" #import "FLTNativeTemplateType.h" #import "GADTTemplateView.h" -#import -#import -#import /** * Wraps a GADTTemplateView for being displayed as a platform view. @@ -35,13 +35,10 @@ - (instancetype _Nonnull) initWithTemplateType:(FLTNativeTemplateType *_Nonnull)templateType mainBackgroundColor:(FLTNativeTemplateColor *_Nullable)mainBackgroundColor - callToActionStyle: - (FLTNativeTemplateTextStyle *_Nullable)callToActionStyle + callToActionStyle:(FLTNativeTemplateTextStyle *_Nullable)callToActionStyle primaryTextStyle:(FLTNativeTemplateTextStyle *_Nullable)primaryTextStyle - secondaryTextStyle: - (FLTNativeTemplateTextStyle *_Nullable)secondaryTextStyle - tertiaryTextStyle: - (FLTNativeTemplateTextStyle *_Nullable)tertiaryTextStyle + secondaryTextStyle:(FLTNativeTemplateTextStyle *_Nullable)secondaryTextStyle + tertiaryTextStyle:(FLTNativeTemplateTextStyle *_Nullable)tertiaryTextStyle cornerRadius:(NSNumber *_Nullable)cornerRadius; @property(readonly) FLTNativeTemplateType *_Nonnull templateType; @property(readonly) FLTNativeTemplateColor *_Nullable mainBackgroundColor; @@ -52,7 +49,6 @@ @property(readonly) NSNumber *_Nullable cornerRadius; /** The actual view to be displayed. */ -- (FLTNativeTemplateViewWrapper *_Nonnull)getDisplayedView: - (GADNativeAd *_Nonnull)gadNativeAd; +- (FLTNativeTemplateViewWrapper *_Nonnull)getDisplayedView:(GADNativeAd *_Nonnull)gadNativeAd; @end diff --git a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateStyle.m b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateStyle.m index 1de7bb509..49de53e18 100644 --- a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateStyle.m +++ b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateStyle.m @@ -22,13 +22,10 @@ @implementation FLTNativeTemplateStyle - (instancetype _Nonnull) initWithTemplateType:(FLTNativeTemplateType *_Nonnull)templateType mainBackgroundColor:(FLTNativeTemplateColor *_Nullable)mainBackgroundColor - callToActionStyle: - (FLTNativeTemplateTextStyle *_Nullable)callToActionStyle + callToActionStyle:(FLTNativeTemplateTextStyle *_Nullable)callToActionStyle primaryTextStyle:(FLTNativeTemplateTextStyle *_Nullable)primaryTextStyle - secondaryTextStyle: - (FLTNativeTemplateTextStyle *_Nullable)secondaryTextStyle - tertiaryTextStyle: - (FLTNativeTemplateTextStyle *_Nullable)tertiaryTextStyle + secondaryTextStyle:(FLTNativeTemplateTextStyle *_Nullable)secondaryTextStyle + tertiaryTextStyle:(FLTNativeTemplateTextStyle *_Nullable)tertiaryTextStyle cornerRadius:(NSNumber *_Nullable)cornerRadius { self = [super init]; if (self) { @@ -43,15 +40,13 @@ @implementation FLTNativeTemplateStyle return self; } -- (FLTNativeTemplateViewWrapper *_Nonnull)getDisplayedView: - (GADNativeAd *_Nonnull)gadNativeAd { +- (FLTNativeTemplateViewWrapper *_Nonnull)getDisplayedView:(GADNativeAd *_Nonnull)gadNativeAd { GADTTemplateView *templateView = _templateType.templateView; templateView.nativeAd = gadNativeAd; NSMutableDictionary *styles = [[NSMutableDictionary alloc] init]; if ([FLTAdUtil isNotNull:_mainBackgroundColor]) { - styles[GADTNativeTemplateStyleKeyMainBackgroundColor] = - _mainBackgroundColor.uiColor; + styles[GADTNativeTemplateStyleKeyMainBackgroundColor] = _mainBackgroundColor.uiColor; } if ([FLTAdUtil isNotNull:_cornerRadius]) { styles[GADTNativeTemplateStyleKeyCornerRadius] = _cornerRadius; @@ -62,8 +57,7 @@ - (FLTNativeTemplateViewWrapper *_Nonnull)getDisplayedView: _callToActionStyle.backgroundColor.uiColor; } if ([FLTAdUtil isNotNull:_callToActionStyle.uiFont]) { - styles[GADTNativeTemplateStyleKeyCallToActionFont] = - _callToActionStyle.uiFont; + styles[GADTNativeTemplateStyleKeyCallToActionFont] = _callToActionStyle.uiFont; } if ([FLTAdUtil isNotNull:_callToActionStyle.textColor]) { styles[GADTNativeTemplateStyleKeyCallToActionFontColor] = @@ -79,8 +73,7 @@ - (FLTNativeTemplateViewWrapper *_Nonnull)getDisplayedView: styles[GADTNativeTemplateStyleKeyPrimaryFont] = _primaryTextStyle.uiFont; } if ([FLTAdUtil isNotNull:_primaryTextStyle.textColor]) { - styles[GADTNativeTemplateStyleKeyPrimaryFontColor] = - _primaryTextStyle.textColor.uiColor; + styles[GADTNativeTemplateStyleKeyPrimaryFontColor] = _primaryTextStyle.textColor.uiColor; } } if ([FLTAdUtil isNotNull:_secondaryTextStyle]) { @@ -89,12 +82,10 @@ - (FLTNativeTemplateViewWrapper *_Nonnull)getDisplayedView: _secondaryTextStyle.backgroundColor.uiColor; } if ([FLTAdUtil isNotNull:_secondaryTextStyle.uiFont]) { - styles[GADTNativeTemplateStyleKeySecondaryFont] = - _secondaryTextStyle.uiFont; + styles[GADTNativeTemplateStyleKeySecondaryFont] = _secondaryTextStyle.uiFont; } if ([FLTAdUtil isNotNull:_secondaryTextStyle.textColor]) { - styles[GADTNativeTemplateStyleKeySecondaryFontColor] = - _secondaryTextStyle.textColor.uiColor; + styles[GADTNativeTemplateStyleKeySecondaryFontColor] = _secondaryTextStyle.textColor.uiColor; } } if ([FLTAdUtil isNotNull:_tertiaryTextStyle]) { @@ -103,12 +94,10 @@ - (FLTNativeTemplateViewWrapper *_Nonnull)getDisplayedView: _tertiaryTextStyle.backgroundColor.uiColor; } if ([FLTAdUtil isNotNull:_tertiaryTextStyle.uiFont]) { - styles[GADTNativeTemplateStyleKeyTertiaryFont] = - _tertiaryTextStyle.uiFont; + styles[GADTNativeTemplateStyleKeyTertiaryFont] = _tertiaryTextStyle.uiFont; } if ([FLTAdUtil isNotNull:_tertiaryTextStyle.textColor]) { - styles[GADTNativeTemplateStyleKeyTertiaryFontColor] = - _tertiaryTextStyle.textColor.uiColor; + styles[GADTNativeTemplateStyleKeyTertiaryFontColor] = _tertiaryTextStyle.textColor.uiColor; } } templateView.styles = styles; @@ -131,24 +120,21 @@ - (void)layoutSubviews { // aligns the template view if (_templateView.superview) { [_templateView.superview - addConstraint:[NSLayoutConstraint - constraintWithItem:_templateView.superview - attribute:NSLayoutAttributeTop - relatedBy:NSLayoutRelationEqual - toItem:_templateView - attribute:NSLayoutAttributeTop - multiplier:1 - constant:0]]; + addConstraint:[NSLayoutConstraint constraintWithItem:_templateView.superview + attribute:NSLayoutAttributeTop + relatedBy:NSLayoutRelationEqual + toItem:_templateView + attribute:NSLayoutAttributeTop + multiplier:1 + constant:0]]; [_templateView.superview - addConstraint: - [NSLayoutConstraint - constraintWithItem:_templateView.superview - attribute:NSLayoutAttributeBottom - relatedBy:NSLayoutRelationGreaterThanOrEqual - toItem:_templateView - attribute:NSLayoutAttributeBottom - multiplier:1 - constant:0]]; + addConstraint:[NSLayoutConstraint constraintWithItem:_templateView.superview + attribute:NSLayoutAttributeBottom + relatedBy:NSLayoutRelationGreaterThanOrEqual + toItem:_templateView + attribute:NSLayoutAttributeBottom + multiplier:1 + constant:0]]; } [_templateView addHorizontalConstraintsToSuperviewWidth]; } diff --git a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateTextStyle.h b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateTextStyle.h index d4068a786..921e14140 100644 --- a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateTextStyle.h +++ b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateTextStyle.h @@ -20,11 +20,10 @@ */ @interface FLTNativeTemplateTextStyle : NSObject -- (instancetype _Nonnull) - initWithTextColor:(FLTNativeTemplateColor *_Nullable)textColor - backgroundColor:(FLTNativeTemplateColor *_Nullable)backgroundColor - fontStyle:(FLTNativeTemplateFontStyleWrapper *_Nullable)fontStyle - size:(NSNumber *_Nullable)size; +- (instancetype _Nonnull)initWithTextColor:(FLTNativeTemplateColor *_Nullable)textColor + backgroundColor:(FLTNativeTemplateColor *_Nullable)backgroundColor + fontStyle:(FLTNativeTemplateFontStyleWrapper *_Nullable)fontStyle + size:(NSNumber *_Nullable)size; @property(readonly) FLTNativeTemplateColor *_Nullable textColor; @property(readonly) FLTNativeTemplateColor *_Nullable backgroundColor; diff --git a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateTextStyle.m b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateTextStyle.m index 82716ba18..ec8c97a0c 100644 --- a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateTextStyle.m +++ b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateTextStyle.m @@ -17,11 +17,10 @@ @implementation FLTNativeTemplateTextStyle -- (instancetype _Nonnull) - initWithTextColor:(FLTNativeTemplateColor *_Nullable)textColor - backgroundColor:(FLTNativeTemplateColor *_Nullable)backgroundColor - fontStyle:(FLTNativeTemplateFontStyleWrapper *_Nullable)fontStyle - size:(NSNumber *_Nullable)size { +- (instancetype _Nonnull)initWithTextColor:(FLTNativeTemplateColor *_Nullable)textColor + backgroundColor:(FLTNativeTemplateColor *_Nullable)backgroundColor + fontStyle:(FLTNativeTemplateFontStyleWrapper *_Nullable)fontStyle + size:(NSNumber *_Nullable)size { self = [super init]; if (self) { _textColor = textColor; @@ -37,29 +36,26 @@ - (UIFont *_Nullable)uiFont { return nil; } - CGFloat size = - [FLTAdUtil isNull:_size] ? UIFont.systemFontSize : _size.floatValue; + CGFloat size = [FLTAdUtil isNull:_size] ? UIFont.systemFontSize : _size.floatValue; if ([FLTAdUtil isNull:_fontStyle]) { return [UIFont systemFontOfSize:size]; } else { switch (_fontStyle.fontStyle) { - case FLTNativeTemplateFontNormal: - return [UIFont systemFontOfSize:size]; - case FLTNativeTemplateFontBold: - return [UIFont boldSystemFontOfSize:size]; - case FLTNativeTemplateFontItalic: - return [UIFont italicSystemFontOfSize:size]; - case FLTNativeTemplateFontMonospace: - if (@available(iOS 13.0, *)) { - return [UIFont monospacedSystemFontOfSize:size - weight:UIFontWeightRegular]; - } else { - return [UIFont monospacedDigitSystemFontOfSize:size - weight:UIFontWeightRegular]; - } - default: - NSLog(@"Unknown fontStyle case: %ld", _fontStyle.fontStyle); - return [UIFont systemFontOfSize:size]; + case FLTNativeTemplateFontNormal: + return [UIFont systemFontOfSize:size]; + case FLTNativeTemplateFontBold: + return [UIFont boldSystemFontOfSize:size]; + case FLTNativeTemplateFontItalic: + return [UIFont italicSystemFontOfSize:size]; + case FLTNativeTemplateFontMonospace: + if (@available(iOS 13.0, *)) { + return [UIFont monospacedSystemFontOfSize:size weight:UIFontWeightRegular]; + } else { + return [UIFont monospacedDigitSystemFontOfSize:size weight:UIFontWeightRegular]; + } + default: + NSLog(@"Unknown fontStyle case: %ld", _fontStyle.fontStyle); + return [UIFont systemFontOfSize:size]; } } } diff --git a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateType.h b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateType.h index 65bda99b7..dda7b3a01 100644 --- a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateType.h +++ b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateType.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "GADTTemplateView.h" #import +#import "GADTTemplateView.h" /** Maps int values to template layout types. */ @interface FLTNativeTemplateType : NSObject diff --git a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateType.m b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateType.m index 6a8b4579b..126bb09a8 100644 --- a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateType.m +++ b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateType.m @@ -28,20 +28,19 @@ - (instancetype _Nonnull)initWithInt:(int)intValue { - (NSString *_Nonnull)xibName { switch (_intValue) { - case 0: - return @"GADTSmallTemplateView"; - case 1: - return @"GADTMediumTemplateView"; - default: - NSLog(@"Unknown template type value: %d", _intValue); - return @"GADTMediumTemplateView"; + case 0: + return @"GADTSmallTemplateView"; + case 1: + return @"GADTMediumTemplateView"; + default: + NSLog(@"Unknown template type value: %d", _intValue); + return @"GADTMediumTemplateView"; } } - (GADTTemplateView *_Nonnull)templateView { // Bundle file name is declared in podspec - id bundleURL = [NSBundle.mainBundle URLForResource:@"google_mobile_ads" - withExtension:@"bundle"]; + id bundleURL = [NSBundle.mainBundle URLForResource:@"google_mobile_ads" withExtension:@"bundle"]; NSBundle *bundle = [NSBundle bundleWithURL:bundleURL]; GADTTemplateView *templateView = [bundle loadNibNamed:self.xibName owner:nil options:nil].firstObject; diff --git a/packages/google_mobile_ads/ios/Classes/NativeTemplates/GoogleAdsMobileIosNativeTemplates/GADTTemplateView.h b/packages/google_mobile_ads/ios/Classes/NativeTemplates/GoogleAdsMobileIosNativeTemplates/GADTTemplateView.h index 82a27630a..358c5f13c 100644 --- a/packages/google_mobile_ads/ios/Classes/NativeTemplates/GoogleAdsMobileIosNativeTemplates/GADTTemplateView.h +++ b/packages/google_mobile_ads/ios/Classes/NativeTemplates/GoogleAdsMobileIosNativeTemplates/GADTTemplateView.h @@ -22,16 +22,13 @@ typedef NSString *GADTNativeTemplateStyleKey NS_STRING_ENUM; #pragma mark - Call To Action /// Call to action font. Expects a UIFont. -extern GADTNativeTemplateStyleKey const - GADTNativeTemplateStyleKeyCallToActionFont; +extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyCallToActionFont; /// Call to action font color. Expects a UIColor. -extern GADTNativeTemplateStyleKey const - GADTNativeTemplateStyleKeyCallToActionFontColor; +extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyCallToActionFontColor; /// Call to action background color. Expects a UIColor. -extern GADTNativeTemplateStyleKey const - GADTNativeTemplateStyleKeyCallToActionBackgroundColor; +extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyCallToActionBackgroundColor; /// The font, font color and background color for the first row of text in the /// template. All templates have a primary text area which is populated by the @@ -42,12 +39,10 @@ extern GADTNativeTemplateStyleKey const extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyPrimaryFont; /// Primary text font color. Expects a UIColor. -extern GADTNativeTemplateStyleKey const - GADTNativeTemplateStyleKeyPrimaryFontColor; +extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyPrimaryFontColor; /// Primary text background color. Expects a UIColor. -extern GADTNativeTemplateStyleKey const - GADTNativeTemplateStyleKeyPrimaryBackgroundColor; +extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyPrimaryBackgroundColor; /// The font, font color and background color for the second row of text in the /// template. All templates have a secondary text area which is populated either @@ -58,12 +53,10 @@ extern GADTNativeTemplateStyleKey const extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeySecondaryFont; /// Secondary text font color. Expects a UIColor. -extern GADTNativeTemplateStyleKey const - GADTNativeTemplateStyleKeySecondaryFontColor; +extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeySecondaryFontColor; /// Secondary text background color. Expects a UIColor. -extern GADTNativeTemplateStyleKey const - GADTNativeTemplateStyleKeySecondaryBackgroundColor; +extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeySecondaryBackgroundColor; /// The font, font color and background color for the third row of text in the /// template. The third row is used to display store name or the default @@ -74,18 +67,15 @@ extern GADTNativeTemplateStyleKey const extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyTertiaryFont; /// Tertiary text font color. Expects a UIColor. -extern GADTNativeTemplateStyleKey const - GADTNativeTemplateStyleKeyTertiaryFontColor; +extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyTertiaryFontColor; /// Tertiary text background color. Expects a UIColor. -extern GADTNativeTemplateStyleKey const - GADTNativeTemplateStyleKeyTertiaryBackgroundColor; +extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyTertiaryBackgroundColor; #pragma mark - Additional Style Options /// The background color for the bulk of the ad. Expects a UIColor. -extern GADTNativeTemplateStyleKey const - GADTNativeTemplateStyleKeyMainBackgroundColor; +extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyMainBackgroundColor; /// The corner rounding radius for the icon view and call to action. Expects an /// NSNumber. @@ -94,8 +84,7 @@ extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyCornerRadius; /// The super class for every template object. /// This class has the majority of all layout and styling logic. @interface GADTTemplateView : GADNativeAdView -@property(nonatomic, copy) - NSDictionary *styles; +@property(nonatomic, copy) NSDictionary *styles; @property(weak) IBOutlet UILabel *adBadge; @property(weak) UIView *rootView; diff --git a/packages/google_mobile_ads/ios/Classes/NativeTemplates/GoogleAdsMobileIosNativeTemplates/GADTTemplateView.m b/packages/google_mobile_ads/ios/Classes/NativeTemplates/GoogleAdsMobileIosNativeTemplates/GADTTemplateView.m index 2c8f34134..bfd085865 100644 --- a/packages/google_mobile_ads/ios/Classes/NativeTemplates/GoogleAdsMobileIosNativeTemplates/GADTTemplateView.m +++ b/packages/google_mobile_ads/ios/Classes/NativeTemplates/GoogleAdsMobileIosNativeTemplates/GADTTemplateView.m @@ -18,49 +18,39 @@ GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyCallToActionFont = @"call_to_action_font"; -GADTNativeTemplateStyleKey const - GADTNativeTemplateStyleKeyCallToActionFontColor = - @"call_to_action_font_color"; +GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyCallToActionFontColor = + @"call_to_action_font_color"; -GADTNativeTemplateStyleKey const - GADTNativeTemplateStyleKeyCallToActionBackgroundColor = - @"call_to_action_background_color"; +GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyCallToActionBackgroundColor = + @"call_to_action_background_color"; -GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeySecondaryFont = - @"secondary_font"; +GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeySecondaryFont = @"secondary_font"; GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeySecondaryFontColor = @"secondary_font_color"; -GADTNativeTemplateStyleKey const - GADTNativeTemplateStyleKeySecondaryBackgroundColor = - @"secondary_background_color"; +GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeySecondaryBackgroundColor = + @"secondary_background_color"; -GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyPrimaryFont = - @"primary_font"; +GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyPrimaryFont = @"primary_font"; -GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyPrimaryFontColor = - @"primary_font_color"; +GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyPrimaryFontColor = @"primary_font_color"; -GADTNativeTemplateStyleKey const - GADTNativeTemplateStyleKeyPrimaryBackgroundColor = - @"primary_background_color"; +GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyPrimaryBackgroundColor = + @"primary_background_color"; -GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyTertiaryFont = - @"tertiary_font"; +GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyTertiaryFont = @"tertiary_font"; GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyTertiaryFontColor = @"tertiary_font_color"; -GADTNativeTemplateStyleKey const - GADTNativeTemplateStyleKeyTertiaryBackgroundColor = - @"tertiary_background_color"; +GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyTertiaryBackgroundColor = + @"tertiary_background_color"; GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyMainBackgroundColor = @"main_background_color"; -GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyCornerRadius = - @"corner_radius"; +GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyCornerRadius = @"corner_radius"; static NSString *const GADTBlue = @"#5C84F0"; @@ -70,28 +60,25 @@ @implementation GADTTemplateView { - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { - _rootView = - [NSBundle.mainBundle loadNibNamed:NSStringFromClass([self class]) - owner:self - options:nil] - .firstObject; + _rootView = [NSBundle.mainBundle loadNibNamed:NSStringFromClass([self class]) + owner:self + options:nil] + .firstObject; [self addSubview:_rootView]; - [self addConstraints: - [NSLayoutConstraint - constraintsWithVisualFormat:@"H:|[_rootView]|" - options:0 - metrics:nil - views:NSDictionaryOfVariableBindings( - _rootView)]]; - [self addConstraints: - [NSLayoutConstraint - constraintsWithVisualFormat:@"V:|[_rootView]|" - options:0 - metrics:nil - views:NSDictionaryOfVariableBindings( - _rootView)]]; + [self + addConstraints:[NSLayoutConstraint + constraintsWithVisualFormat:@"H:|[_rootView]|" + options:0 + metrics:nil + views:NSDictionaryOfVariableBindings(_rootView)]]; + [self + addConstraints:[NSLayoutConstraint + constraintsWithVisualFormat:@"V:|[_rootView]|" + options:0 + metrics:nil + views:NSDictionaryOfVariableBindings(_rootView)]]; [self applyStyles]; [self styleAdBadge]; } @@ -111,20 +98,17 @@ - (id)styleForKey:(GADTNativeTemplateStyleKey)key { // Goes through all recognized style keys and updates the views accordingly, // overwriting the defaults. - (void)applyStyles { - self.layer.borderColor = - [GADTTemplateView colorFromHexString:@"E0E0E0"].CGColor; + self.layer.borderColor = [GADTTemplateView colorFromHexString:@"E0E0E0"].CGColor; self.layer.borderWidth = 1.0f; [self.mediaView sizeToFit]; if ([self styleForKey:GADTNativeTemplateStyleKeyCornerRadius]) { float roundedCornerRadius = - ((NSNumber *)[self styleForKey:GADTNativeTemplateStyleKeyCornerRadius]) - .floatValue; + ((NSNumber *)[self styleForKey:GADTNativeTemplateStyleKeyCornerRadius]).floatValue; // Rounded corners self.iconView.layer.cornerRadius = roundedCornerRadius; self.iconView.clipsToBounds = YES; - ((UIButton *)self.callToActionView).layer.cornerRadius = - roundedCornerRadius; + ((UIButton *)self.callToActionView).layer.cornerRadius = roundedCornerRadius; ((UIButton *)self.callToActionView).clipsToBounds = YES; } @@ -151,52 +135,49 @@ - (void)applyStyles { // Font colors if ([self styleForKey:GADTNativeTemplateStyleKeyPrimaryFontColor]) - ((UILabel *)self.headlineView).textColor = (UIColor *)[self - styleForKey:GADTNativeTemplateStyleKeyPrimaryFontColor]; + ((UILabel *)self.headlineView).textColor = + (UIColor *)[self styleForKey:GADTNativeTemplateStyleKeyPrimaryFontColor]; if ([self styleForKey:GADTNativeTemplateStyleKeySecondaryFontColor]) { - ((UILabel *)self.bodyView).textColor = (UIColor *)[self - styleForKey:GADTNativeTemplateStyleKeySecondaryFontColor]; + ((UILabel *)self.bodyView).textColor = + (UIColor *)[self styleForKey:GADTNativeTemplateStyleKeySecondaryFontColor]; } if ([self styleForKey:GADTNativeTemplateStyleKeyTertiaryFontColor]) { - ((UILabel *)self.advertiserView).textColor = (UIColor *)[self - styleForKey:GADTNativeTemplateStyleKeyTertiaryFontColor]; + ((UILabel *)self.advertiserView).textColor = + (UIColor *)[self styleForKey:GADTNativeTemplateStyleKeyTertiaryFontColor]; } if ([self styleForKey:GADTNativeTemplateStyleKeyCallToActionFontColor]) { [((UIButton *)self.callToActionView) - setTitleColor: - (UIColor *)[self - styleForKey:GADTNativeTemplateStyleKeyCallToActionFontColor] + setTitleColor:(UIColor *)[self styleForKey:GADTNativeTemplateStyleKeyCallToActionFontColor] forState:UIControlStateNormal]; } // Background colors if ([self styleForKey:GADTNativeTemplateStyleKeyPrimaryBackgroundColor]) { - ((UILabel *)self.headlineView).backgroundColor = (UIColor *)[self - styleForKey:GADTNativeTemplateStyleKeyPrimaryBackgroundColor]; + ((UILabel *)self.headlineView).backgroundColor = + (UIColor *)[self styleForKey:GADTNativeTemplateStyleKeyPrimaryBackgroundColor]; } if ([self styleForKey:GADTNativeTemplateStyleKeySecondaryBackgroundColor]) { - ((UILabel *)self.bodyView).backgroundColor = (UIColor *)[self - styleForKey:GADTNativeTemplateStyleKeySecondaryBackgroundColor]; + ((UILabel *)self.bodyView).backgroundColor = + (UIColor *)[self styleForKey:GADTNativeTemplateStyleKeySecondaryBackgroundColor]; } if ([self styleForKey:GADTNativeTemplateStyleKeyTertiaryBackgroundColor]) { - ((UILabel *)self.advertiserView).backgroundColor = (UIColor *)[self - styleForKey:GADTNativeTemplateStyleKeyTertiaryBackgroundColor]; + ((UILabel *)self.advertiserView).backgroundColor = + (UIColor *)[self styleForKey:GADTNativeTemplateStyleKeyTertiaryBackgroundColor]; } - if ([self - styleForKey:GADTNativeTemplateStyleKeyCallToActionBackgroundColor]) { - ((UIButton *)self.callToActionView).backgroundColor = (UIColor *)[self - styleForKey:GADTNativeTemplateStyleKeyCallToActionBackgroundColor]; + if ([self styleForKey:GADTNativeTemplateStyleKeyCallToActionBackgroundColor]) { + ((UIButton *)self.callToActionView).backgroundColor = + (UIColor *)[self styleForKey:GADTNativeTemplateStyleKeyCallToActionBackgroundColor]; } if ([self styleForKey:GADTNativeTemplateStyleKeyMainBackgroundColor]) { - self.backgroundColor = (UIColor *)[self - styleForKey:GADTNativeTemplateStyleKeyMainBackgroundColor]; + self.backgroundColor = + (UIColor *)[self styleForKey:GADTNativeTemplateStyleKeyMainBackgroundColor]; } [self styleAdBadge]; } @@ -209,8 +190,7 @@ - (void)styleAdBadge { adBadge.layer.masksToBounds = YES; } -- (void)setStyles: - (NSDictionary *)styles { +- (void)setStyles:(NSDictionary *)styles { _styles = [styles copy]; [self applyStyles]; } @@ -278,28 +258,24 @@ - (void)addHorizontalConstraintsToSuperviewWidth { if (self.superview) { UIView *child = self; [self.superview - addConstraints: - [NSLayoutConstraint - constraintsWithVisualFormat:@"H:|[child]|" - options:0 - metrics:nil - views:NSDictionaryOfVariableBindings( - child)]]; + addConstraints:[NSLayoutConstraint + constraintsWithVisualFormat:@"H:|[child]|" + options:0 + metrics:nil + views:NSDictionaryOfVariableBindings(child)]]; } } - (void)addVerticalCenterConstraintToSuperview { if (self.superview) { UIView *child = self; - [self.superview - addConstraint:[NSLayoutConstraint - constraintWithItem:self.superview - attribute:NSLayoutAttributeCenterY - relatedBy:NSLayoutRelationEqual - toItem:child - attribute:NSLayoutAttributeCenterY - multiplier:1 - constant:0]]; + [self.superview addConstraint:[NSLayoutConstraint constraintWithItem:self.superview + attribute:NSLayoutAttributeCenterY + relatedBy:NSLayoutRelationEqual + toItem:child + attribute:NSLayoutAttributeCenterY + multiplier:1 + constant:0]]; } } @@ -308,14 +284,13 @@ + (UIColor *)colorFromHexString:(NSString *)hexString { if (hexString == nil) { return nil; } - NSRange range = [hexString rangeOfString:@"^#[0-9a-fA-F]{6}$" - options:NSRegularExpressionSearch]; + NSRange range = [hexString rangeOfString:@"^#[0-9a-fA-F]{6}$" options:NSRegularExpressionSearch]; if (range.location == NSNotFound) { return nil; } unsigned rgbValue = 0; NSScanner *scanner = [NSScanner scannerWithString:hexString]; - [scanner setScanLocation:1]; // Bypass '#' character. + [scanner setScanLocation:1]; // Bypass '#' character. [scanner scanHexInt:&rgbValue]; return [UIColor colorWithRed:((rgbValue & 0xff0000) >> 16) / 255.0f diff --git a/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformManager.h b/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformManager.h index 9bfd93cf7..e9e8a8211 100644 --- a/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformManager.h +++ b/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformManager.h @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "FLTUserMessagingPlatformReaderWriter.h" #import #import +#include "FLTUserMessagingPlatformReaderWriter.h" @interface FLTUserMessagingPlatformManager : NSObject @@ -23,7 +23,6 @@ - (instancetype _Nonnull)initWithBinaryMessenger: (NSObject *_Nonnull)binaryMessenger; -- (void)handleMethodCall:(FlutterMethodCall *_Nonnull)call - result:(FlutterResult _Nonnull)result; +- (void)handleMethodCall:(FlutterMethodCall *_Nonnull)call result:(FlutterResult _Nonnull)result; @end diff --git a/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformManager.m b/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformManager.m index 4201b34d9..71e81eb93 100644 --- a/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformManager.m +++ b/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformManager.m @@ -13,10 +13,10 @@ // limitations under the License. #import "FLTUserMessagingPlatformManager.h" +#include #import "../FLTAdUtil.h" #import "../FLTNSString.h" #import "FLTUserMessagingPlatformReaderWriter.h" -#include @implementation FLTUserMessagingPlatformManager { FlutterMethodChannel *_methodChannel; @@ -29,16 +29,16 @@ - (instancetype _Nonnull)initWithBinaryMessenger: self.readerWriter = [[FLTUserMessagingPlatformReaderWriter alloc] init]; NSObject *methodCodec = [FlutterStandardMethodCodec codecWithReaderWriter:_readerWriter]; - _methodChannel = [[FlutterMethodChannel alloc] - initWithName:@"plugins.flutter.io/google_mobile_ads/ump" - binaryMessenger:binaryMessenger - codec:methodCodec]; + _methodChannel = + [[FlutterMethodChannel alloc] initWithName:@"plugins.flutter.io/google_mobile_ads/ump" + binaryMessenger:binaryMessenger + codec:methodCodec]; FLTUserMessagingPlatformManager *__weak weakSelf = self; - [_methodChannel setMethodCallHandler:^(FlutterMethodCall *_Nonnull call, - FlutterResult _Nonnull result) { - [weakSelf handleMethodCall:call result:result]; - }]; + [_methodChannel + setMethodCallHandler:^(FlutterMethodCall *_Nonnull call, FlutterResult _Nonnull result) { + [weakSelf handleMethodCall:call result:result]; + }]; } return self; } @@ -47,37 +47,31 @@ - (UIViewController *)rootController { return UIApplication.sharedApplication.delegate.window.rootViewController; } -- (void)handleMethodCall:(FlutterMethodCall *_Nonnull)call - result:(FlutterResult _Nonnull)result { +- (void)handleMethodCall:(FlutterMethodCall *_Nonnull)call result:(FlutterResult _Nonnull)result { if ([call.method isEqualToString:@"ConsentInformation#reset"]) { [UMPConsentInformation.sharedInstance reset]; result(nil); - } else if ([call.method - isEqualToString:@"ConsentInformation#getConsentStatus"]) { - UMPConsentStatus status = - UMPConsentInformation.sharedInstance.consentStatus; + } else if ([call.method isEqualToString:@"ConsentInformation#getConsentStatus"]) { + UMPConsentStatus status = UMPConsentInformation.sharedInstance.consentStatus; result([[NSNumber alloc] initWithInteger:status]); - } else if ([call.method - isEqualToString:@"ConsentInformation#canRequestAds"]) { + } else if ([call.method isEqualToString:@"ConsentInformation#canRequestAds"]) { result(@([UMPConsentInformation.sharedInstance canRequestAds])); - } else if ([call.method - isEqualToString:@"ConsentInformation#" - @"getPrivacyOptionsRequirementStatus"]) { + } else if ([call.method isEqualToString:@"ConsentInformation#" + @"getPrivacyOptionsRequirementStatus"]) { UMPPrivacyOptionsRequirementStatus status = UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus; switch (status) { - case UMPPrivacyOptionsRequirementStatusNotRequired: - result([[NSNumber alloc] initWithInt:0]); - break; - case UMPPrivacyOptionsRequirementStatusRequired: - result([[NSNumber alloc] initWithInt:1]); - break; - default: - result([[NSNumber alloc] initWithInt:2]); - break; + case UMPPrivacyOptionsRequirementStatusNotRequired: + result([[NSNumber alloc] initWithInt:0]); + break; + case UMPPrivacyOptionsRequirementStatusRequired: + result([[NSNumber alloc] initWithInt:1]); + break; + default: + result([[NSNumber alloc] initWithInt:2]); + break; } - } else if ([call.method isEqualToString: - @"ConsentInformation#requestConsentInfoUpdate"]) { + } else if ([call.method isEqualToString:@"ConsentInformation#requestConsentInfoUpdate"]) { UMPRequestParameters *parameters = call.arguments[@"params"]; [UMPConsentInformation.sharedInstance requestConsentInfoUpdateWithParameters:parameters @@ -86,15 +80,13 @@ - (void)handleMethodCall:(FlutterMethodCall *_Nonnull)call result(nil); } else { result([FlutterError - errorWithCode:[[NSString alloc] - initWithInt:error.code] + errorWithCode:[[NSString alloc] initWithInt:error.code] message:error.localizedDescription details:error.domain]); } }]; - } else if ([call.method - isEqualToString:@"UserMessagingPlatform#" - @"loadAndShowConsentFormIfRequired"]) { + } else if ([call.method isEqualToString:@"UserMessagingPlatform#" + @"loadAndShowConsentFormIfRequired"]) { [UMPConsentForm loadAndPresentIfRequiredFromViewController:self.rootController completionHandler:^(NSError *_Nullable error) { @@ -102,52 +94,37 @@ - (void)handleMethodCall:(FlutterMethodCall *_Nonnull)call result(nil); } else { result([FlutterError - errorWithCode: - [[NSString alloc] - initWithInt:error.code] - message:error - .localizedDescription + errorWithCode:[[NSString alloc] initWithInt:error.code] + message:error.localizedDescription details:error.domain]); } }]; - } else if ([call.method - isEqualToString:@"UserMessagingPlatform#loadConsentForm"]) { - [UMPConsentForm - loadWithCompletionHandler:^(UMPConsentForm *form, NSError *loadError) { - if ([FLTAdUtil isNull:loadError]) { - [self.readerWriter trackConsentForm:form]; - result(form); - } else { - result([FlutterError - errorWithCode:[[NSString alloc] initWithInt:loadError.code] - message:loadError.localizedDescription - details:loadError.domain]); - } - }]; - } else if ([call.method - isEqualToString: - @"UserMessagingPlatform#showPrivacyOptionsForm"]) { - [UMPConsentForm - presentPrivacyOptionsFormFromViewController:self.rootController - completionHandler:^( - NSError *_Nullable formError) { - if ([FLTAdUtil isNull:formError]) { - result(nil); - } else { - result([FlutterError - errorWithCode: - [[NSString alloc] - initWithInt:formError.code] - message: - formError - .localizedDescription - details:formError.domain]); - } - }]; - } else if ([call.method isEqualToString: - @"ConsentInformation#isConsentFormAvailable"]) { - BOOL isAvailable = UMPConsentInformation.sharedInstance.formStatus == - UMPFormStatusAvailable; + } else if ([call.method isEqualToString:@"UserMessagingPlatform#loadConsentForm"]) { + [UMPConsentForm loadWithCompletionHandler:^(UMPConsentForm *form, NSError *loadError) { + if ([FLTAdUtil isNull:loadError]) { + [self.readerWriter trackConsentForm:form]; + result(form); + } else { + result([FlutterError errorWithCode:[[NSString alloc] initWithInt:loadError.code] + message:loadError.localizedDescription + details:loadError.domain]); + } + }]; + } else if ([call.method isEqualToString:@"UserMessagingPlatform#showPrivacyOptionsForm"]) { + [UMPConsentForm presentPrivacyOptionsFormFromViewController:self.rootController + completionHandler:^(NSError *_Nullable formError) { + if ([FLTAdUtil isNull:formError]) { + result(nil); + } else { + result([FlutterError + errorWithCode:[[NSString alloc] + initWithInt:formError.code] + message:formError.localizedDescription + details:formError.domain]); + } + }]; + } else if ([call.method isEqualToString:@"ConsentInformation#isConsentFormAvailable"]) { + BOOL isAvailable = UMPConsentInformation.sharedInstance.formStatus == UMPFormStatusAvailable; result([[NSNumber alloc] initWithBool:isAvailable]); } else if ([call.method isEqualToString:@"ConsentForm#show"]) { UMPConsentForm *consentForm = call.arguments[@"consentForm"]; @@ -157,10 +134,9 @@ - (void)handleMethodCall:(FlutterMethodCall *_Nonnull)call if ([FLTAdUtil isNull:error]) { result(nil); } else { - result([FlutterError - errorWithCode:[[NSString alloc] initWithInt:error.code] - message:error.localizedDescription - details:error.domain]); + result([FlutterError errorWithCode:[[NSString alloc] initWithInt:error.code] + message:error.localizedDescription + details:error.domain]); } }]; } else if ([call.method isEqualToString:@"ConsentForm#dispose"]) { diff --git a/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformReaderWriter.m b/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformReaderWriter.m index 7056f984f..6f9b8d5de 100644 --- a/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformReaderWriter.m +++ b/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformReaderWriter.m @@ -13,8 +13,8 @@ // limitations under the License. #import "FLTUserMessagingPlatformReaderWriter.h" -#import "../FLTAdUtil.h" #include +#import "../FLTAdUtil.h" // The type values below must be consistent for each platform. typedef NS_ENUM(NSInteger, FLTUserMessagingPlatformField) { @@ -62,8 +62,7 @@ - (FlutterStandardReader *_Nonnull)readerWithData:(NSData *_Nonnull)data { return reader; } -- (FlutterStandardWriter *_Nonnull)writerWithData: - (NSMutableData *_Nonnull)data { +- (FlutterStandardWriter *_Nonnull)writerWithData:(NSMutableData *_Nonnull)data { FLTUserMessagingPlatformWriter *writer = [[FLTUserMessagingPlatformWriter alloc] initWithData:data]; writer.consentFormDict = self.consentFormDict; @@ -83,14 +82,12 @@ - (void)writeValue:(id)value { UMPRequestParameters *params = (UMPRequestParameters *)value; [self writeByte:FLTValueConsentRequestParameters]; - [self writeValue:[[NSNumber alloc] - initWithBool:params.tagForUnderAgeOfConsent]]; + [self writeValue:[[NSNumber alloc] initWithBool:params.tagForUnderAgeOfConsent]]; [self writeValue:params.debugSettings]; } else if ([value isKindOfClass:[UMPDebugSettings class]]) { UMPDebugSettings *debugSettings = (UMPDebugSettings *)value; [self writeByte:FLTValueConsentDebugSettings]; - [self - writeValue:[[NSNumber alloc] initWithInteger:debugSettings.geography]]; + [self writeValue:[[NSNumber alloc] initWithInteger:debugSettings.geography]]; [self writeValue:debugSettings.testDeviceIdentifiers]; } else { [super writeValue:value]; @@ -104,34 +101,33 @@ @implementation FLTUserMessagingPlatformReader - (id _Nullable)readValueOfType:(UInt8)type { FLTUserMessagingPlatformField field = (FLTUserMessagingPlatformField)type; switch (field) { - case FLTValueConsentRequestParameters: { - UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init]; - NSNumber *tfuac = [self readValueOfType:[self readByte]]; - - parameters.tagForUnderAgeOfConsent = tfuac.boolValue; - UMPDebugSettings *debugSettings = [self readValueOfType:[self readByte]]; - parameters.debugSettings = debugSettings; - return parameters; - } - case FLTValueConsentDebugSettings: { - UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init]; - NSNumber *geography = [self readValueOfType:[self readByte]]; - NSArray *testIdentifiers = - [self readValueOfType:[self readByte]]; - if ([FLTAdUtil isNotNull:geography]) { - debugSettings.geography = geography.intValue; + case FLTValueConsentRequestParameters: { + UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init]; + NSNumber *tfuac = [self readValueOfType:[self readByte]]; + + parameters.tagForUnderAgeOfConsent = tfuac.boolValue; + UMPDebugSettings *debugSettings = [self readValueOfType:[self readByte]]; + parameters.debugSettings = debugSettings; + return parameters; } - if ([FLTAdUtil isNotNull:testIdentifiers]) { - debugSettings.testDeviceIdentifiers = testIdentifiers; + case FLTValueConsentDebugSettings: { + UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init]; + NSNumber *geography = [self readValueOfType:[self readByte]]; + NSArray *testIdentifiers = [self readValueOfType:[self readByte]]; + if ([FLTAdUtil isNotNull:geography]) { + debugSettings.geography = geography.intValue; + } + if ([FLTAdUtil isNotNull:testIdentifiers]) { + debugSettings.testDeviceIdentifiers = testIdentifiers; + } + return debugSettings; } - return debugSettings; - } - case FLTValueConsentForm: { - NSNumber *hash = [self readValueOfType:[self readByte]]; - return _consentFormDict[hash]; - } - default: - return [super readValueOfType:type]; + case FLTValueConsentForm: { + NSNumber *hash = [self readValueOfType:[self readByte]]; + return _consentFormDict[hash]; + } + default: + return [super readValueOfType:type]; } } From 994dcc2ce46845fd85d3560b987e2fd70df810e9 Mon Sep 17 00:00:00 2001 From: Aldo Becerril Date: Fri, 9 Aug 2024 09:56:37 -0700 Subject: [PATCH 03/15] Format fix --- .../example/ios/Runner/AppDelegate.m | 12 +- .../example/ios/Runner/main.m | 5 +- .../ios/RunnerTests/FLTAdRequestTest.m | 6 +- .../example/ios/RunnerTests/FLTAdUtilTest.m | 53 +-- .../ios/RunnerTests/FLTAppOpenAdTest.m | 73 ++-- .../example/ios/RunnerTests/FLTBannerAdTest.m | 56 ++- .../ios/RunnerTests/FLTFluidGAMBannerAdTest.m | 125 +++--- .../ios/RunnerTests/FLTGAMAdRequestTest.m | 6 +- .../ios/RunnerTests/FLTGAMBannerAdTest.m | 55 +-- .../RunnerTests/FLTGamInterstitialAdTest.m | 91 ++--- .../FLTGoogleMobileAdsPluginMethodCallsTest.m | 280 ++++++------- .../FLTGoogleMobileAdsReaderWriterTest.m | 368 ++++++------------ .../ios/RunnerTests/FLTGoogleMobileAdsTest.m | 336 +++++++--------- .../ios/RunnerTests/FLTInterstitialAdTest.m | 77 ++-- .../example/ios/RunnerTests/FLTNativeAdTest.m | 94 ++--- .../ios/RunnerTests/FLTRewardedAdTest.m | 89 ++--- .../FLTRewardedInterstitialAdTest.m | 122 +++--- .../FLTUserMessagingPlatformManagerTest.m | 174 ++++----- ...FLTUserMessagingPlatformReaderWriterTest.m | 18 +- .../FLTNativeTemplateColorTest.m | 12 +- .../FLTNativeTemplateFontStyleTest.m | 2 +- .../FLTNativeTemplateStyleTest.m | 132 +++---- .../FLTNativeTemplateTextStyleTest.m | 24 +- .../FLTNativeTemplateTypeTest.m | 14 +- 24 files changed, 895 insertions(+), 1329 deletions(-) diff --git a/packages/google_mobile_ads/example/ios/Runner/AppDelegate.m b/packages/google_mobile_ads/example/ios/Runner/AppDelegate.m index ffbad4233..48fc1759c 100644 --- a/packages/google_mobile_ads/example/ios/Runner/AppDelegate.m +++ b/packages/google_mobile_ads/example/ios/Runner/AppDelegate.m @@ -25,10 +25,8 @@ @implementation NativeAdFactoryExample - (GADNativeAdView *)createNativeAd:(GADNativeAd *)nativeAd customOptions:(NSDictionary *)customOptions { // Create and place ad in view hierarchy. - GADNativeAdView *adView = [[NSBundle mainBundle] loadNibNamed:@"NativeAdView" - owner:nil - options:nil] - .firstObject; + GADNativeAdView *adView = + [[NSBundle mainBundle] loadNibNamed:@"NativeAdView" owner:nil options:nil].firstObject; // Associate the native ad view with the native ad object. This is // required to make the ad clickable. @@ -72,13 +70,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [GeneratedPluginRegistrant registerWithRegistry:self]; - NativeAdFactoryExample *nativeAdFactory = - [[NativeAdFactoryExample alloc] init]; + NativeAdFactoryExample *nativeAdFactory = [[NativeAdFactoryExample alloc] init]; [FLTGoogleMobileAdsPlugin registerNativeAdFactory:self factoryId:@"adFactoryExample" nativeAdFactory:nativeAdFactory]; - return [super application:application - didFinishLaunchingWithOptions:launchOptions]; + return [super application:application didFinishLaunchingWithOptions:launchOptions]; } @end diff --git a/packages/google_mobile_ads/example/ios/Runner/main.m b/packages/google_mobile_ads/example/ios/Runner/main.m index 80af04fa0..460e03555 100644 --- a/packages/google_mobile_ads/example/ios/Runner/main.m +++ b/packages/google_mobile_ads/example/ios/Runner/main.m @@ -12,13 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "AppDelegate.h" #import #import +#import "AppDelegate.h" int main(int argc, char *argv[]) { @autoreleasepool { - return UIApplicationMain(argc, argv, nil, - NSStringFromClass([AppDelegate class])); + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } } diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAdRequestTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAdRequestTest.m index 89aa5c845..c5049a73f 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAdRequestTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAdRequestTest.m @@ -66,8 +66,7 @@ - (void)testAsAdRequestAllParams { GADExtras *updatedExtras = [gadRequest adNetworkExtrasFor:[GADExtras class]]; XCTAssertEqualObjects(updatedExtras, extras); XCTAssertEqualObjects(updatedExtras.additionalParameters[@"npa"], @"1"); - OCMVerify( - [gadRequestSpy registerAdNetworkExtras:[OCMArg isEqual:testExtras]]); + OCMVerify([gadRequestSpy registerAdNetworkExtras:[OCMArg isEqual:testExtras]]); } - (void)testAsAdRequestNoParams { @@ -138,8 +137,7 @@ - (void)testGADExtrasWithoutNpa { GADRequest *gadRequest = [fltAdRequest asGADRequest:@"test-ad-unit"]; XCTAssertNil([gadRequest adNetworkExtrasFor:[GADExtras class]]); - OCMVerify( - [gadRequestSpy registerAdNetworkExtras:[OCMArg isEqual:testExtras]]); + OCMVerify([gadRequestSpy registerAdNetworkExtras:[OCMArg isEqual:testExtras]]); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAdUtilTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAdUtilTest.m index 77d8122e0..f8f2e4f8b 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAdUtilTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAdUtilTest.m @@ -32,65 +32,40 @@ - (void)setUp { } - (void)testRequestAgent_noTemplateMetadata { - OCMStub( - [_mockMainBundle - objectForInfoDictionaryKey:[OCMArg - isEqual:@"FLTNewsTemplateVersion"]]) + OCMStub([_mockMainBundle objectForInfoDictionaryKey:[OCMArg isEqual:@"FLTNewsTemplateVersion"]]) .andReturn(nil); - OCMStub( - [_mockMainBundle - objectForInfoDictionaryKey:[OCMArg - isEqual:@"FLTGameTemplateVersion"]]) + OCMStub([_mockMainBundle objectForInfoDictionaryKey:[OCMArg isEqual:@"FLTGameTemplateVersion"]]) .andReturn(nil); XCTAssertEqualObjects([FLTAdUtil requestAgent], FLT_REQUEST_AGENT_VERSIONED); } - (void)testRequestAgent_newsTemplateMetadata { - OCMStub( - [_mockMainBundle - objectForInfoDictionaryKey:[OCMArg - isEqual:@"FLTNewsTemplateVersion"]]) + OCMStub([_mockMainBundle objectForInfoDictionaryKey:[OCMArg isEqual:@"FLTNewsTemplateVersion"]]) .andReturn(@"v1.2.3"); - OCMStub( - [_mockMainBundle - objectForInfoDictionaryKey:[OCMArg - isEqual:@"FLTGameTemplateVersion"]]) + OCMStub([_mockMainBundle objectForInfoDictionaryKey:[OCMArg isEqual:@"FLTGameTemplateVersion"]]) .andReturn(nil); - NSString *expected = [NSString - stringWithFormat:@"%@%@", FLT_REQUEST_AGENT_VERSIONED, @"_News-v1.2.3"]; + NSString *expected = + [NSString stringWithFormat:@"%@%@", FLT_REQUEST_AGENT_VERSIONED, @"_News-v1.2.3"]; XCTAssertEqualObjects([FLTAdUtil requestAgent], expected); } - (void)testRequestAgent_gameTemplateMetadata { - OCMStub( - [_mockMainBundle - objectForInfoDictionaryKey:[OCMArg - isEqual:@"FLTNewsTemplateVersion"]]) + OCMStub([_mockMainBundle objectForInfoDictionaryKey:[OCMArg isEqual:@"FLTNewsTemplateVersion"]]) .andReturn(nil); - OCMStub( - [_mockMainBundle - objectForInfoDictionaryKey:[OCMArg - isEqual:@"FLTGameTemplateVersion"]]) + OCMStub([_mockMainBundle objectForInfoDictionaryKey:[OCMArg isEqual:@"FLTGameTemplateVersion"]]) .andReturn(@"123456"); - NSString *expected = [NSString - stringWithFormat:@"%@%@", FLT_REQUEST_AGENT_VERSIONED, @"_Game-123456"]; + NSString *expected = + [NSString stringWithFormat:@"%@%@", FLT_REQUEST_AGENT_VERSIONED, @"_Game-123456"]; XCTAssertEqualObjects([FLTAdUtil requestAgent], expected); } - (void)testRequestAgent_gameAndNewsTemplateMetadata { - OCMStub( - [_mockMainBundle - objectForInfoDictionaryKey:[OCMArg - isEqual:@"FLTNewsTemplateVersion"]]) + OCMStub([_mockMainBundle objectForInfoDictionaryKey:[OCMArg isEqual:@"FLTNewsTemplateVersion"]]) .andReturn(@"123456"); - OCMStub( - [_mockMainBundle - objectForInfoDictionaryKey:[OCMArg - isEqual:@"FLTGameTemplateVersion"]]) + OCMStub([_mockMainBundle objectForInfoDictionaryKey:[OCMArg isEqual:@"FLTGameTemplateVersion"]]) .andReturn(@"789z"); - NSString *expected = - [NSString stringWithFormat:@"%@%@%@", FLT_REQUEST_AGENT_VERSIONED, - @"_News-123456", @"_Game-789z"]; + NSString *expected = [NSString + stringWithFormat:@"%@%@%@", FLT_REQUEST_AGENT_VERSIONED, @"_News-123456", @"_Game-789z"]; XCTAssertEqualObjects([FLTAdUtil requestAgent], expected); } diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m index dfc65a59d..93286f3cb 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m @@ -47,8 +47,7 @@ - (void)testLoadShowGAMRequest { OCMClassMock([FLTServerSideVerificationOptions class]); GADServerSideVerificationOptions *gadOptions = OCMClassMock([GADServerSideVerificationOptions class]); - OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]) - .andReturn(gadOptions); + OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]).andReturn(gadOptions); [self testLoadShowAppOpenAd:request gadOrGAMRequest:gamRequest]; } @@ -56,12 +55,8 @@ - (void)testLoadShowGAMRequest { // Helper method for testing with FLTAdRequest and FLTGAMAdRequest. - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request gadOrGAMRequest:(GADRequest *)gadOrGAMRequest { - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); - FLTAppOpenAd *ad = - [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); + FLTAppOpenAd *ad = [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" request:request adId:@1]; ad.manager = mockManager; // Stub the load call to invoke successful load callback. @@ -86,8 +81,7 @@ - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request [delegate adDidDismissFullScreenContent:appOpenClassMock]; [delegate adWillPresentFullScreenContent:appOpenClassMock]; [delegate adWillDismissFullScreenContent:appOpenClassMock]; - [delegate ad:appOpenClassMock - didFailToPresentFullScreenContentWithError:error]; + [delegate ad:appOpenClassMock didFailToPresentFullScreenContentWithError:error]; }); GADResponseInfo *responseInfo = OCMClassMock([GADResponseInfo class]); OCMStub([appOpenClassMock responseInfo]).andReturn(responseInfo); @@ -97,40 +91,36 @@ - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request OCMStub([adValue value]).andReturn(NSDecimalNumber.one); OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated); OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); - OCMStub([appOpenClassMock - setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - GADPaidEventHandler handler = obj; - handler(adValue); - return YES; - }]]); + OCMStub([appOpenClassMock setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + GADPaidEventHandler handler = obj; + handler(adValue); + return YES; + }]]); // Call load and check expected interactions with mocks. [ad load]; - OCMVerify(ClassMethod([appOpenClassMock - loadWithAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadOrGAMRequest] - completionHandler:[OCMArg any]])); + OCMVerify(ClassMethod([appOpenClassMock loadWithAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadOrGAMRequest] + completionHandler:[OCMArg any]])); OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad] responseInfo:[OCMArg isEqual:responseInfo]]); - OCMVerify( - [appOpenClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); + OCMVerify([appOpenClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); XCTAssertEqual(ad.appOpenAd, appOpenClassMock); - OCMVerify([mockManager - onPaidEvent:[OCMArg isEqual:ad] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); [ad showFromRootViewController:mockRootViewController]; - OCMVerify([appOpenClassMock - presentFromRootViewController:[OCMArg isEqual:mockRootViewController]]); + OCMVerify( + [appOpenClassMock presentFromRootViewController:[OCMArg isEqual:mockRootViewController]]); // Verify full screen callbacks. OCMVerify([mockManager adWillPresentFullScreenContent:[OCMArg isEqual:ad]]); @@ -138,9 +128,8 @@ - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request OCMVerify([mockManager adWillDismissFullScreenContent:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordImpression:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:ad]]); - OCMVerify([mockManager - didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); } - (void)testFailedToLoadGADRequest { @@ -161,10 +150,7 @@ - (void)testFailedToLoadGAMRequest { // Helper for testing failed to load. - (void)testFailedToLoad:(FLTAdRequest *)request { - FLTAppOpenAd *ad = - [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + FLTAppOpenAd *ad = [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" request:request adId:@1]; ad.manager = mockManager; id appOpenClassMock = OCMClassMock([GADAppOpenAd class]); @@ -183,8 +169,7 @@ - (void)testFailedToLoad:(FLTAdRequest *)request { OCMVerify(ClassMethod([appOpenClassMock loadWithAdUnitID:[OCMArg any] request:[OCMArg any] completionHandler:[OCMArg any]])); - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTBannerAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTBannerAdTest.m index 278875cd7..8d9ef9216 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTBannerAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTBannerAdTest.m @@ -31,14 +31,12 @@ - (void)setUp { - (void)testDelegates { FLTAdSize *size = [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)]; - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); - FLTBannerAd *bannerAd = - [[FLTBannerAd alloc] initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:mockRootViewController - adId:@1]; + UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); + FLTBannerAd *bannerAd = [[FLTBannerAd alloc] initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:mockRootViewController + adId:@1]; bannerAd.manager = mockManager; [bannerAd load]; @@ -75,38 +73,35 @@ - (void)testDelegates { OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); bannerAd.bannerView.paidEventHandler(adValue); - OCMVerify([mockManager - onPaidEvent:[OCMArg isEqual:bannerAd] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:bannerAd] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); NSString *domain = @"domain"; NSDictionary *userInfo = @{NSLocalizedDescriptionKey : @"description"}; NSError *error = [NSError errorWithDomain:domain code:1 userInfo:userInfo]; [bannerAd.bannerView.delegate bannerView:OCMClassMock([GADBannerView class]) didFailToReceiveAdWithError:error]; - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:bannerAd] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:bannerAd] error:[OCMArg isEqual:error]]); } - (void)testLoad { FLTAdRequest *request = [[FLTAdRequest alloc] init]; request.keywords = @[ @"apple" ]; - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); - FLTBannerAd *ad = [[FLTBannerAd alloc] - initWithAdUnitId:@"testId" - size:[[FLTAdSize alloc] initWithWidth:@(1) height:@(2)] - request:request - rootViewController:mockRootViewController - adId:@1]; + UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); + FLTBannerAd *ad = [[FLTBannerAd alloc] initWithAdUnitId:@"testId" + size:[[FLTAdSize alloc] initWithWidth:@(1) + height:@(2)] + request:request + rootViewController:mockRootViewController + adId:@1]; XCTAssertEqual(ad.bannerView.adUnitID, @"testId"); XCTAssertEqual(ad.bannerView.rootViewController, mockRootViewController); @@ -118,8 +113,7 @@ - (void)testLoad { OCMVerify([mockView loadRequest:[OCMArg checkWithBlock:^BOOL(id obj) { GADRequest *requestArg = obj; - return - [requestArg.keywords isEqualToArray:@[ @"apple" ]]; + return [requestArg.keywords isEqualToArray:@[ @"apple" ]]; }]]); } diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTFluidGAMBannerAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTFluidGAMBannerAdTest.m index 5ca92fa9c..8f1bc145b 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTFluidGAMBannerAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTFluidGAMBannerAdTest.m @@ -32,13 +32,12 @@ - (void)setUp { - (void)testDelegates { FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init]; request.keywords = @[ @"apple" ]; - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); - FLTFluidGAMBannerAd *fluidAd = [[FLTFluidGAMBannerAd alloc] - initWithAdUnitId:@"testId" - request:[[FLTGAMAdRequest alloc] init] - rootViewController:mockRootViewController - adId:@1]; + UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); + FLTFluidGAMBannerAd *fluidAd = + [[FLTFluidGAMBannerAd alloc] initWithAdUnitId:@"testId" + request:[[FLTGAMAdRequest alloc] init] + rootViewController:mockRootViewController + adId:@1]; fluidAd.manager = mockManager; [fluidAd load]; @@ -46,29 +45,23 @@ - (void)testDelegates { XCTAssertEqual(adView.appEventDelegate, fluidAd); XCTAssertEqual(adView.delegate, fluidAd); - [fluidAd.bannerView.delegate - bannerViewDidReceiveAd:OCMClassMock([GADBannerView class])]; + [fluidAd.bannerView.delegate bannerViewDidReceiveAd:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:fluidAd] responseInfo:[OCMArg isEqual:adView.responseInfo]]); - [fluidAd.bannerView.delegate - bannerViewDidDismissScreen:OCMClassMock([GADBannerView class])]; + [fluidAd.bannerView.delegate bannerViewDidDismissScreen:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager onBannerDidDismissScreen:[OCMArg isEqual:fluidAd]]); - [fluidAd.bannerView.delegate - bannerViewWillDismissScreen:OCMClassMock([GADBannerView class])]; + [fluidAd.bannerView.delegate bannerViewWillDismissScreen:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager onBannerWillDismissScreen:[OCMArg isEqual:fluidAd]]); - [fluidAd.bannerView.delegate - bannerViewWillPresentScreen:OCMClassMock([GADBannerView class])]; + [fluidAd.bannerView.delegate bannerViewWillPresentScreen:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager onBannerWillPresentScreen:[OCMArg isEqual:fluidAd]]); - [fluidAd.bannerView.delegate - bannerViewDidRecordImpression:OCMClassMock([GADBannerView class])]; + [fluidAd.bannerView.delegate bannerViewDidRecordImpression:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager onBannerImpression:[OCMArg isEqual:fluidAd]]); - [fluidAd.bannerView.delegate - bannerViewDidRecordClick:OCMClassMock([GADBannerView class])]; + [fluidAd.bannerView.delegate bannerViewDidRecordClick:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:fluidAd]]); // Mock callback of paid event handler. @@ -78,29 +71,25 @@ - (void)testDelegates { OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); fluidAd.bannerView.paidEventHandler(adValue); - OCMVerify([mockManager - onPaidEvent:[OCMArg isEqual:fluidAd] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:fluidAd] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); NSString *domain = @"domain"; NSDictionary *userInfo = @{NSLocalizedDescriptionKey : @"description"}; NSError *error = [NSError errorWithDomain:domain code:1 userInfo:userInfo]; [fluidAd.bannerView.delegate bannerView:OCMClassMock([GADBannerView class]) didFailToReceiveAdWithError:error]; - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:fluidAd] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:fluidAd] error:[OCMArg isEqual:error]]); - [adView.appEventDelegate adView:adView - didReceiveAppEvent:@"appEvent" - withInfo:@"info"]; + [adView.appEventDelegate adView:adView didReceiveAppEvent:@"appEvent" withInfo:@"info"]; OCMVerify([mockManager onAppEvent:[OCMArg isEqual:fluidAd] name:[OCMArg isEqual:@"appEvent"] data:[OCMArg isEqual:@"info"]]); @@ -110,40 +99,34 @@ - (void)testPlatformViewSetup { // Setup mocks FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init]; request.keywords = @[ @"apple" ]; - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); + UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); id scrollViewClassMock = OCMClassMock([UIScrollView class]); OCMStub([scrollViewClassMock alloc]).andReturn(scrollViewClassMock); - OCMStub([scrollViewClassMock initWithFrame:CGRectZero]) - .andReturn(scrollViewClassMock); + OCMStub([scrollViewClassMock initWithFrame:CGRectZero]).andReturn(scrollViewClassMock); id gamBannerClassMock = OCMClassMock([GAMBannerView class]); OCMStub([gamBannerClassMock alloc]).andReturn(gamBannerClassMock); - OCMStub([gamBannerClassMock initWithAdSize:GADAdSizeFluid]) - .andReturn(gamBannerClassMock); + OCMStub([gamBannerClassMock initWithAdSize:GADAdSizeFluid]).andReturn(gamBannerClassMock); // Create and load an ad. - FLTFluidGAMBannerAd *fluidAd = [[FLTFluidGAMBannerAd alloc] - initWithAdUnitId:@"testId" - request:[[FLTGAMAdRequest alloc] init] - rootViewController:mockRootViewController - adId:@1]; + FLTFluidGAMBannerAd *fluidAd = + [[FLTFluidGAMBannerAd alloc] initWithAdUnitId:@"testId" + request:[[FLTGAMAdRequest alloc] init] + rootViewController:mockRootViewController + adId:@1]; fluidAd.manager = mockManager; // Mimic successful loading of an ad. [fluidAd load]; - [fluidAd.bannerView.delegate - bannerViewDidReceiveAd:OCMClassMock([GADBannerView class])]; + [fluidAd.bannerView.delegate bannerViewDidReceiveAd:OCMClassMock([GADBannerView class])]; // The banner view should be contained within a scrollview. XCTAssertEqualObjects(fluidAd.view, scrollViewClassMock); - OCMVerify([(UIScrollView *)scrollViewClassMock - addSubview:[OCMArg isKindOfClass:GAMBannerView.class]]); - OCMVerify([(UIScrollView *)scrollViewClassMock - setShowsHorizontalScrollIndicator:NO]); OCMVerify( - [(UIScrollView *)scrollViewClassMock setShowsVerticalScrollIndicator:NO]); + [(UIScrollView *)scrollViewClassMock addSubview:[OCMArg isKindOfClass:GAMBannerView.class]]); + OCMVerify([(UIScrollView *)scrollViewClassMock setShowsHorizontalScrollIndicator:NO]); + OCMVerify([(UIScrollView *)scrollViewClassMock setShowsVerticalScrollIndicator:NO]); [scrollViewClassMock stopMocking]; [gamBannerClassMock stopMocking]; @@ -153,38 +136,33 @@ - (void)testSizeChangedEvent { // Setup mocks FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init]; request.keywords = @[ @"apple" ]; - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); + UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); // Create and load an ad. - FLTFluidGAMBannerAd *fluidAd = [[FLTFluidGAMBannerAd alloc] - initWithAdUnitId:@"testId" - request:[[FLTGAMAdRequest alloc] init] - rootViewController:mockRootViewController - adId:@1]; + FLTFluidGAMBannerAd *fluidAd = + [[FLTFluidGAMBannerAd alloc] initWithAdUnitId:@"testId" + request:[[FLTGAMAdRequest alloc] init] + rootViewController:mockRootViewController + adId:@1]; fluidAd.manager = mockManager; // Mimic successful loading of an ad. [fluidAd load]; - [fluidAd.bannerView.delegate - bannerViewDidReceiveAd:OCMClassMock([GADBannerView class])]; + [fluidAd.bannerView.delegate bannerViewDidReceiveAd:OCMClassMock([GADBannerView class])]; - [fluidAd.bannerView.adSizeDelegate - adView:fluidAd.bannerView - willChangeAdSizeTo:GADAdSizeFromCGSize(CGSizeMake(0, 25))]; + [fluidAd.bannerView.adSizeDelegate adView:fluidAd.bannerView + willChangeAdSizeTo:GADAdSizeFromCGSize(CGSizeMake(0, 25))]; OCMVerify([mockManager onFluidAdHeightChanged:fluidAd height:25]); } - (void)testLoad { FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init]; request.keywords = @[ @"apple" ]; - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); - FLTFluidGAMBannerAd *ad = - [[FLTFluidGAMBannerAd alloc] initWithAdUnitId:@"testId" - request:request - rootViewController:mockRootViewController - adId:@1]; + UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); + FLTFluidGAMBannerAd *ad = [[FLTFluidGAMBannerAd alloc] initWithAdUnitId:@"testId" + request:request + rootViewController:mockRootViewController + adId:@1]; XCTAssertEqual(ad.bannerView.adUnitID, @"testId"); XCTAssertEqual(ad.bannerView.rootViewController, mockRootViewController); @@ -196,8 +174,7 @@ - (void)testLoad { OCMVerify([mockView loadRequest:[OCMArg checkWithBlock:^BOOL(id obj) { GADRequest *requestArg = obj; - return - [requestArg.keywords isEqualToArray:@[ @"apple" ]]; + return [requestArg.keywords isEqualToArray:@[ @"apple" ]]; }]]); } diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGAMAdRequestTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGAMAdRequestTest.m index 44b7a1c8f..4e788a635 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGAMAdRequestTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGAMAdRequestTest.m @@ -71,8 +71,7 @@ - (void)testAsAdRequestAllParams { GADExtras *updatedExtras = [gamRequest adNetworkExtrasFor:[GADExtras class]]; XCTAssertEqualObjects(updatedExtras, extras); XCTAssertEqualObjects(updatedExtras.additionalParameters[@"npa"], @"1"); - OCMVerify( - [gamRequestSpy registerAdNetworkExtras:[OCMArg isEqual:testExtras]]); + OCMVerify([gamRequestSpy registerAdNetworkExtras:[OCMArg isEqual:testExtras]]); } - (void)testAsAdRequestNoParams { @@ -145,8 +144,7 @@ - (void)testGADExtrasWithoutNpa { GADRequest *gamRequest = [fltGAMAdRequest asGAMRequest:@"test-ad-unit"]; XCTAssertNil([gamRequest adNetworkExtrasFor:[GADExtras class]]); - OCMVerify( - [gamRequestSpy registerAdNetworkExtras:[OCMArg isEqual:testExtras]]); + OCMVerify([gamRequestSpy registerAdNetworkExtras:[OCMArg isEqual:testExtras]]); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGAMBannerAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGAMBannerAdTest.m index 1baf1f4ca..acdf81f35 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGAMBannerAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGAMBannerAdTest.m @@ -32,8 +32,7 @@ - (void)setUp { - (void)testDelegates { FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init]; request.keywords = @[ @"apple" ]; - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); + UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); FLTGAMBannerAd *bannerAd = [[FLTGAMBannerAd alloc] initWithAdUnitId:@"testId" sizes:@[ [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)] ] @@ -47,29 +46,23 @@ - (void)testDelegates { XCTAssertEqual(adView.appEventDelegate, bannerAd); XCTAssertEqual(adView.delegate, bannerAd); - [bannerAd.bannerView.delegate - bannerViewDidReceiveAd:OCMClassMock([GADBannerView class])]; + [bannerAd.bannerView.delegate bannerViewDidReceiveAd:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:bannerAd] responseInfo:[OCMArg isEqual:adView.responseInfo]]); - [bannerAd.bannerView.delegate - bannerViewDidDismissScreen:OCMClassMock([GADBannerView class])]; + [bannerAd.bannerView.delegate bannerViewDidDismissScreen:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager onBannerDidDismissScreen:[OCMArg isEqual:bannerAd]]); - [bannerAd.bannerView.delegate - bannerViewWillDismissScreen:OCMClassMock([GADBannerView class])]; + [bannerAd.bannerView.delegate bannerViewWillDismissScreen:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager onBannerWillDismissScreen:[OCMArg isEqual:bannerAd]]); - [bannerAd.bannerView.delegate - bannerViewWillPresentScreen:OCMClassMock([GADBannerView class])]; + [bannerAd.bannerView.delegate bannerViewWillPresentScreen:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager onBannerWillPresentScreen:[OCMArg isEqual:bannerAd]]); - [bannerAd.bannerView.delegate - bannerViewDidRecordImpression:OCMClassMock([GADBannerView class])]; + [bannerAd.bannerView.delegate bannerViewDidRecordImpression:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager onBannerImpression:[OCMArg isEqual:bannerAd]]); - [bannerAd.bannerView.delegate - bannerViewDidRecordClick:OCMClassMock([GADBannerView class])]; + [bannerAd.bannerView.delegate bannerViewDidRecordClick:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:bannerAd]]); // Mock callback of paid event handler. @@ -79,29 +72,25 @@ - (void)testDelegates { OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); bannerAd.bannerView.paidEventHandler(adValue); - OCMVerify([mockManager - onPaidEvent:[OCMArg isEqual:bannerAd] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:bannerAd] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); NSString *domain = @"domain"; NSDictionary *userInfo = @{NSLocalizedDescriptionKey : @"description"}; NSError *error = [NSError errorWithDomain:domain code:1 userInfo:userInfo]; [bannerAd.bannerView.delegate bannerView:OCMClassMock([GADBannerView class]) didFailToReceiveAdWithError:error]; - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:bannerAd] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:bannerAd] error:[OCMArg isEqual:error]]); - [adView.appEventDelegate adView:adView - didReceiveAppEvent:@"appEvent" - withInfo:@"info"]; + [adView.appEventDelegate adView:adView didReceiveAppEvent:@"appEvent" withInfo:@"info"]; OCMVerify([mockManager onAppEvent:[OCMArg isEqual:bannerAd] name:[OCMArg isEqual:@"appEvent"] data:[OCMArg isEqual:@"info"]]); @@ -110,8 +99,7 @@ - (void)testDelegates { - (void)testLoad { FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init]; request.keywords = @[ @"apple" ]; - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); + UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); FLTGAMBannerAd *ad = [[FLTGAMBannerAd alloc] initWithAdUnitId:@"testId" sizes:@[ [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)] ] @@ -129,8 +117,7 @@ - (void)testLoad { OCMVerify([mockView loadRequest:[OCMArg checkWithBlock:^BOOL(id obj) { GADRequest *requestArg = obj; - return - [requestArg.keywords isEqualToArray:@[ @"apple" ]]; + return [requestArg.keywords isEqualToArray:@[ @"apple" ]]; }]]); } diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m index c3d55f8d7..3cc61b069 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m @@ -35,19 +35,16 @@ - (void)testLoadShowInterstitialAd { GAMRequest *gadRequest = OCMClassMock([GAMRequest class]); OCMStub([request asGAMRequest:[OCMArg any]]).andReturn(gadRequest); - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); - FLTGAMInterstitialAd *ad = - [[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); + FLTGAMInterstitialAd *ad = [[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id interstitialClassMock = OCMClassMock([GAMInterstitialAd class]); - OCMStub(ClassMethod([interstitialClassMock - loadWithAdManagerAdUnitID:[OCMArg any] - request:[OCMArg any] - completionHandler:[OCMArg any]])) + OCMStub(ClassMethod([interstitialClassMock loadWithAdManagerAdUnitID:[OCMArg any] + request:[OCMArg any] + completionHandler:[OCMArg any]])) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(GAMInterstitialAd *ad, NSError *error); [invocation getArgument:&completionHandler atIndex:4]; @@ -64,8 +61,7 @@ - (void)testLoadShowInterstitialAd { [delegate adDidDismissFullScreenContent:interstitialClassMock]; [delegate adWillPresentFullScreenContent:interstitialClassMock]; [delegate adWillDismissFullScreenContent:interstitialClassMock]; - [delegate ad:interstitialClassMock - didFailToPresentFullScreenContentWithError:error]; + [delegate ad:interstitialClassMock didFailToPresentFullScreenContentWithError:error]; }); OCMStub([interstitialClassMock setAppEventDelegate:[OCMArg any]]) @@ -86,35 +82,31 @@ - (void)testLoadShowInterstitialAd { OCMStub([adValue value]).andReturn(NSDecimalNumber.one); OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated); OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); - OCMStub([interstitialClassMock - setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - GADPaidEventHandler handler = obj; - handler(adValue); - return YES; - }]]); + OCMStub([interstitialClassMock setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + GADPaidEventHandler handler = obj; + handler(adValue); + return YES; + }]]); // Call load and verify interactions with mocks. [ad load]; - OCMVerify(ClassMethod([interstitialClassMock - loadWithAdManagerAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadRequest] - completionHandler:[OCMArg any]])); + OCMVerify(ClassMethod([interstitialClassMock loadWithAdManagerAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadRequest] + completionHandler:[OCMArg any]])); OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad] responseInfo:[OCMArg isEqual:responseInfo]]); - OCMVerify( - [interstitialClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); + OCMVerify([interstitialClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); XCTAssertEqual(ad.interstitial, interstitialClassMock); - OCMVerify([mockManager - onPaidEvent:[OCMArg isEqual:ad] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); // Show the ad [ad showFromRootViewController:mockRootViewController]; @@ -128,9 +120,8 @@ - (void)testLoadShowInterstitialAd { OCMVerify([mockManager adWillDismissFullScreenContent:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordImpression:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:ad]]); - OCMVerify([mockManager - didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); // Verify app event OCMVerify([mockManager onAppEvent:ad @@ -144,18 +135,16 @@ - (void)testFailToLoad { GAMRequest *gadRequest = OCMClassMock([GAMRequest class]); OCMStub([request asGAMRequest:[OCMArg any]]).andReturn(gadRequest); - FLTGAMInterstitialAd *ad = - [[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + FLTGAMInterstitialAd *ad = [[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id interstitialClassMock = OCMClassMock([GAMInterstitialAd class]); NSError *error = OCMClassMock([NSError class]); - OCMStub(ClassMethod([interstitialClassMock - loadWithAdManagerAdUnitID:[OCMArg any] - request:[OCMArg any] - completionHandler:[OCMArg any]])) + OCMStub(ClassMethod([interstitialClassMock loadWithAdManagerAdUnitID:[OCMArg any] + request:[OCMArg any] + completionHandler:[OCMArg any]])) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(GAMInterstitialAd *ad, NSError *error); [invocation getArgument:&completionHandler atIndex:4]; @@ -164,12 +153,10 @@ - (void)testFailToLoad { [ad load]; - OCMVerify(ClassMethod([interstitialClassMock - loadWithAdManagerAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadRequest] - completionHandler:[OCMArg any]])); - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify(ClassMethod([interstitialClassMock loadWithAdManagerAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadRequest] + completionHandler:[OCMArg any]])); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsPluginMethodCallsTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsPluginMethodCallsTest.m index a4164b0ce..6e3f7b486 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsPluginMethodCallsTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsPluginMethodCallsTest.m @@ -34,20 +34,16 @@ @implementation FLTGoogleMobileAdsPluginMethodCallsTest { } - (void)setUp { - id messenger = - OCMProtocolMock(@protocol(FlutterBinaryMessenger)); - FLTAdInstanceManager *manager = - [[FLTAdInstanceManager alloc] initWithBinaryMessenger:messenger]; + id messenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger)); + FLTAdInstanceManager *manager = [[FLTAdInstanceManager alloc] initWithBinaryMessenger:messenger]; _mockAdInstanceManager = OCMPartialMock(manager); _fltGoogleMobileAdsPlugin = [[FLTGoogleMobileAdsPlugin alloc] init]; - [_fltGoogleMobileAdsPlugin setValue:_mockAdInstanceManager - forKey:@"_manager"]; + [_fltGoogleMobileAdsPlugin setValue:_mockAdInstanceManager forKey:@"_manager"]; } - (void)testDisposeAd { - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"disposeAd" - arguments:@{@"adId" : @1}]; + FlutterMethodCall *methodCall = [FlutterMethodCall methodCallWithMethodName:@"disposeAd" + arguments:@{@"adId" : @1}]; __block bool resultInvoked = false; __block id _Nullable returnedResult; FlutterResult result = ^(id _Nullable result) { @@ -65,13 +61,12 @@ - (void)testDisposeAd { - (void)testLoadRewardedAd { FLTAdRequest *request = [[FLTAdRequest alloc] init]; request.keywords = @[ @"apple" ]; - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"loadRewardedAd" - arguments:@{ - @"adId" : @2, - @"adUnitId" : @"testId", - @"request" : request, - }]; + FlutterMethodCall *methodCall = [FlutterMethodCall methodCallWithMethodName:@"loadRewardedAd" + arguments:@{ + @"adId" : @2, + @"adUnitId" : @"testId", + @"request" : request, + }]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -91,13 +86,12 @@ - (void)testLoadRewardedAd { XCTAssertEqualObjects(adUnit, @"testId"); return YES; }; - OCMVerify([_mockAdInstanceManager - loadAd:[OCMArg checkWithBlock:verificationBlock]]); + OCMVerify([_mockAdInstanceManager loadAd:[OCMArg checkWithBlock:verificationBlock]]); } - (void)testInternalInit { - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"_init" arguments:@{}]; + FlutterMethodCall *methodCall = [FlutterMethodCall methodCallWithMethodName:@"_init" + arguments:@{}]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -117,22 +111,19 @@ - (void)testMobileAdsInitialize { id gadMobileAdsClassMock = OCMClassMock([GADMobileAds class]); OCMStub(ClassMethod([gadMobileAdsClassMock sharedInstance])) .andReturn((GADMobileAds *)gadMobileAdsClassMock); - GADInitializationStatus *mockInitStatus = - OCMClassMock([GADInitializationStatus class]); + GADInitializationStatus *mockInitStatus = OCMClassMock([GADInitializationStatus class]); OCMStub([mockInitStatus adapterStatusesByClassName]).andReturn(@{}); OCMStub([gadMobileAdsClassMock startWithCompletionHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { // Invoke the init handler twice. - __unsafe_unretained GADInitializationCompletionHandler - completionHandler; + __unsafe_unretained GADInitializationCompletionHandler completionHandler; [invocation getArgument:&completionHandler atIndex:2]; completionHandler(mockInitStatus); completionHandler(mockInitStatus); }); FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"MobileAds#initialize" - arguments:@{}]; + [FlutterMethodCall methodCallWithMethodName:@"MobileAds#initialize" arguments:@{}]; __block int resultInvokedCount = 0; __block id _Nullable returnedResult; FlutterResult result = ^(id _Nullable result) { @@ -142,8 +133,7 @@ - (void)testMobileAdsInitialize { [_fltGoogleMobileAdsPlugin handleMethodCall:methodCall result:result]; XCTAssertEqual(resultInvokedCount, 1); - XCTAssertEqual( - [((FLTInitializationStatus *)returnedResult) adapterStatuses].count, 0); + XCTAssertEqual([((FLTInitializationStatus *)returnedResult) adapterStatuses].count, 0); } - (void)testSetSameAppKeyEnabledYes { @@ -152,12 +142,11 @@ - (void)testSetSameAppKeyEnabledYes { .andReturn((GADMobileAds *)gadMobileAdsClassMock); GADRequestConfiguration *gadRequestConfigurationMock = OCMClassMock([GADRequestConfiguration class]); - OCMStub([gadMobileAdsClassMock requestConfiguration]) - .andReturn(gadRequestConfigurationMock); + OCMStub([gadMobileAdsClassMock requestConfiguration]).andReturn(gadRequestConfigurationMock); - FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"MobileAds#setSameAppKeyEnabled" - arguments:@{@"isEnabled" : @(YES)}]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"MobileAds#setSameAppKeyEnabled" + arguments:@{@"isEnabled" : @(YES)}]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -170,8 +159,7 @@ - (void)testSetSameAppKeyEnabledYes { XCTAssertTrue(resultInvoked); XCTAssertNil(returnedResult); - OCMVerify([gadRequestConfigurationMock - setPublisherFirstPartyIDEnabled:[OCMArg isEqual:@(YES)]]); + OCMVerify([gadRequestConfigurationMock setPublisherFirstPartyIDEnabled:[OCMArg isEqual:@(YES)]]); } - (void)testRegisterWebView { @@ -181,8 +169,7 @@ - (void)testRegisterWebView { WKWebView *mockWebView = OCMClassMock([WKWebView class]); id fltAdUtilMock = OCMClassMock([FLTAdUtil class]); - OCMStub(ClassMethod([fltAdUtilMock getWebView:[OCMArg any] - flutterPluginRegistry:[OCMArg any]])) + OCMStub(ClassMethod([fltAdUtilMock getWebView:[OCMArg any] flutterPluginRegistry:[OCMArg any]])) .andReturn(mockWebView); FlutterMethodCall *methodCall = @@ -208,12 +195,11 @@ - (void)testSetSameAppKeyEnabledNo { .andReturn((GADMobileAds *)gadMobileAdsClassMock); GADRequestConfiguration *gadRequestConfigurationMock = OCMClassMock([GADRequestConfiguration class]); - OCMStub([gadMobileAdsClassMock requestConfiguration]) - .andReturn(gadRequestConfigurationMock); + OCMStub([gadMobileAdsClassMock requestConfiguration]).andReturn(gadRequestConfigurationMock); - FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"MobileAds#setSameAppKeyEnabled" - arguments:@{@"isEnabled" : @0}]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"MobileAds#setSameAppKeyEnabled" + arguments:@{@"isEnabled" : @0}]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -228,9 +214,9 @@ - (void)testSetSameAppKeyEnabledNo { XCTAssertNil(returnedResult); OCMVerify([gadRequestConfigurationMock setPublisherFirstPartyIDEnabled:NO]); - FlutterMethodCall *methodCallWithBool = [FlutterMethodCall - methodCallWithMethodName:@"MobileAds#setSameAppKeyEnabled" - arguments:@{@"isEnabled" : @NO}]; + FlutterMethodCall *methodCallWithBool = + [FlutterMethodCall methodCallWithMethodName:@"MobileAds#setSameAppKeyEnabled" + arguments:@{@"isEnabled" : @NO}]; __block bool resultInvokedWithBool = false; __block id _Nullable returnedResultWithBool; @@ -239,8 +225,7 @@ - (void)testSetSameAppKeyEnabledNo { returnedResultWithBool = result; }; - [_fltGoogleMobileAdsPlugin handleMethodCall:methodCallWithBool - result:resultWithBool]; + [_fltGoogleMobileAdsPlugin handleMethodCall:methodCallWithBool result:resultWithBool]; XCTAssertTrue(resultInvokedWithBool); XCTAssertNil(returnedResultWithBool); @@ -265,9 +250,8 @@ - (void)testSetAppMuted { XCTAssertNil(returnedResult); XCTAssertTrue(GADMobileAds.sharedInstance.applicationMuted); - methodCall = - [FlutterMethodCall methodCallWithMethodName:@"MobileAds#setAppMuted" - arguments:@{@"muted" : @(NO)}]; + methodCall = [FlutterMethodCall methodCallWithMethodName:@"MobileAds#setAppMuted" + arguments:@{@"muted" : @(NO)}]; resultInvoked = false; result = ^(id _Nullable result) { @@ -305,9 +289,9 @@ - (void)testDisableSDKCrashReporting { id gadMobileAdsClassMock = OCMClassMock([GADMobileAds class]); OCMStub(ClassMethod([gadMobileAdsClassMock sharedInstance])) .andReturn((GADMobileAds *)gadMobileAdsClassMock); - FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"MobileAds#disableSDKCrashReporting" - arguments:@{}]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"MobileAds#disableSDKCrashReporting" + arguments:@{}]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -328,9 +312,9 @@ - (void)testDisableMediationInitialization { OCMStub(ClassMethod([gadMobileAdsClassMock sharedInstance])) .andReturn((GADMobileAds *)gadMobileAdsClassMock); - FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"MobileAds#disableMediationInitialization" - arguments:@{}]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"MobileAds#disableMediationInitialization" + arguments:@{}]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -348,8 +332,7 @@ - (void)testDisableMediationInitialization { - (void)testGetVersionString { FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"MobileAds#getVersionString" - arguments:@{}]; + [FlutterMethodCall methodCallWithMethodName:@"MobileAds#getVersionString" arguments:@{}]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -361,15 +344,14 @@ - (void)testGetVersionString { [_fltGoogleMobileAdsPlugin handleMethodCall:methodCall result:result]; XCTAssertTrue(resultInvoked); - XCTAssertEqual( - returnedResult, - GADGetStringFromVersionNumber(GADMobileAds.sharedInstance.versionNumber)); + XCTAssertEqual(returnedResult, + GADGetStringFromVersionNumber(GADMobileAds.sharedInstance.versionNumber)); } - (void)testOpenDebugMenu { - FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"MobileAds#openDebugMenu" - arguments:@{@"adUnitId" : @"test-ad-unit"}]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"MobileAds#openDebugMenu" + arguments:@{@"adUnitId" : @"test-ad-unit"}]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -378,16 +360,14 @@ - (void)testOpenDebugMenu { returnedResult = result; }; - FLTGoogleMobileAdsPlugin *mockPlugin = - OCMPartialMock(_fltGoogleMobileAdsPlugin); + FLTGoogleMobileAdsPlugin *mockPlugin = OCMPartialMock(_fltGoogleMobileAdsPlugin); UIViewController *mockUIViewController = OCMClassMock(UIViewController.class); OCMStub([mockPlugin rootController]).andReturn(mockUIViewController); [_fltGoogleMobileAdsPlugin handleMethodCall:methodCall result:result]; OCMVerify([mockUIViewController - presentViewController:[OCMArg isKindOfClass:[GADDebugOptionsViewController - class]] + presentViewController:[OCMArg isKindOfClass:[GADDebugOptionsViewController class]] animated:[OCMArg any] completion:[OCMArg isNil]]); XCTAssertTrue(resultInvoked); @@ -396,8 +376,7 @@ - (void)testOpenDebugMenu { - (void)testOpenAdInspectorSuccess { FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"MobileAds#openAdInspector" - arguments:@{}]; + [FlutterMethodCall methodCallWithMethodName:@"MobileAds#openAdInspector" arguments:@{}]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -410,9 +389,8 @@ - (void)testOpenAdInspectorSuccess { OCMStub(ClassMethod([gadMobileAdsClassMock sharedInstance])) .andReturn((GADMobileAds *)gadMobileAdsClassMock); - OCMStub([gadMobileAdsClassMock - presentAdInspectorFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]) + OCMStub([gadMobileAdsClassMock presentAdInspectorFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { __unsafe_unretained GADAdInspectorCompletionHandler completionHandler; [invocation getArgument:&completionHandler atIndex:3]; @@ -421,17 +399,15 @@ - (void)testOpenAdInspectorSuccess { [_fltGoogleMobileAdsPlugin handleMethodCall:methodCall result:result]; - OCMVerify([gadMobileAdsClassMock - presentAdInspectorFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]); + OCMVerify([gadMobileAdsClassMock presentAdInspectorFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]); XCTAssertTrue(resultInvoked); XCTAssertEqual(returnedResult, nil); } - (void)testOpenAdInspectorError { FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"MobileAds#openAdInspector" - arguments:@{}]; + [FlutterMethodCall methodCallWithMethodName:@"MobileAds#openAdInspector" arguments:@{}]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -448,9 +424,8 @@ - (void)testOpenAdInspectorError { }; NSError *error = [NSError errorWithDomain:@"domain" code:1 userInfo:userInfo]; - OCMStub([gadMobileAdsClassMock - presentAdInspectorFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]) + OCMStub([gadMobileAdsClassMock presentAdInspectorFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { __unsafe_unretained GADAdInspectorCompletionHandler completionHandler; [invocation getArgument:&completionHandler atIndex:3]; @@ -459,9 +434,8 @@ - (void)testOpenAdInspectorError { [_fltGoogleMobileAdsPlugin handleMethodCall:methodCall result:result]; - OCMVerify([gadMobileAdsClassMock - presentAdInspectorFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]); + OCMVerify([gadMobileAdsClassMock presentAdInspectorFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]); XCTAssertTrue(resultInvoked); FlutterError *resultError = (FlutterError *)returnedResult; @@ -471,9 +445,9 @@ - (void)testOpenAdInspectorError { } - (void)testGetRequestConfiguration { - FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"MobileAds#getRequestConfiguration" - arguments:@{}]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"MobileAds#getRequestConfiguration" + arguments:@{}]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -485,17 +459,16 @@ - (void)testGetRequestConfiguration { [_fltGoogleMobileAdsPlugin handleMethodCall:methodCall result:result]; XCTAssertTrue(resultInvoked); - XCTAssertEqual(returnedResult, - [GADMobileAds.sharedInstance requestConfiguration]); + XCTAssertEqual(returnedResult, [GADMobileAds.sharedInstance requestConfiguration]); } - (void)testGetAnchoredAdaptiveBannerAdSize { - FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"AdSize#getAnchoredAdaptiveBannerAdSize" - arguments:@{ - @"orientation" : @"portrait", - @"width" : @23, - }]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"AdSize#getAnchoredAdaptiveBannerAdSize" + arguments:@{ + @"orientation" : @"portrait", + @"width" : @23, + }]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -507,16 +480,14 @@ - (void)testGetAnchoredAdaptiveBannerAdSize { [_fltGoogleMobileAdsPlugin handleMethodCall:methodCall result:result]; XCTAssertTrue(resultInvoked); - XCTAssertEqual( - [returnedResult doubleValue], - GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth(23).size.height); + XCTAssertEqual([returnedResult doubleValue], + GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth(23).size.height); - methodCall = [FlutterMethodCall - methodCallWithMethodName:@"AdSize#getAnchoredAdaptiveBannerAdSize" - arguments:@{ - @"orientation" : @"landscape", - @"width" : @34, - }]; + methodCall = [FlutterMethodCall methodCallWithMethodName:@"AdSize#getAnchoredAdaptiveBannerAdSize" + arguments:@{ + @"orientation" : @"landscape", + @"width" : @34, + }]; resultInvoked = false; result = ^(id _Nullable result) { @@ -527,15 +498,13 @@ - (void)testGetAnchoredAdaptiveBannerAdSize { [_fltGoogleMobileAdsPlugin handleMethodCall:methodCall result:result]; XCTAssertTrue(resultInvoked); - XCTAssertEqual( - [returnedResult doubleValue], - GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth(34).size.height); + XCTAssertEqual([returnedResult doubleValue], + GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth(34).size.height); - methodCall = [FlutterMethodCall - methodCallWithMethodName:@"AdSize#getAnchoredAdaptiveBannerAdSize" - arguments:@{ - @"width" : @45, - }]; + methodCall = [FlutterMethodCall methodCallWithMethodName:@"AdSize#getAnchoredAdaptiveBannerAdSize" + arguments:@{ + @"width" : @45, + }]; resultInvoked = false; result = ^(id _Nullable result) { @@ -547,20 +516,19 @@ - (void)testGetAnchoredAdaptiveBannerAdSize { XCTAssertTrue(resultInvoked); XCTAssertEqual([returnedResult doubleValue], - GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(45) - .size.height); + GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(45).size.height); } - (void)testGetAdSize_bannerAd { // Method calls to load a banner ad. - FlutterMethodCall *loadAdMethodCall = [FlutterMethodCall - methodCallWithMethodName:@"loadBannerAd" - arguments:@{ - @"adId" : @(1), - @"adUnitId" : @"ad-unit-id", - @"size" : [[FLTAdSize alloc] initWithWidth:@1 height:@2], - @"request" : [[FLTAdRequest alloc] init], - }]; + FlutterMethodCall *loadAdMethodCall = + [FlutterMethodCall methodCallWithMethodName:@"loadBannerAd" + arguments:@{ + @"adId" : @(1), + @"adUnitId" : @"ad-unit-id", + @"size" : [[FLTAdSize alloc] initWithWidth:@1 height:@2], + @"request" : [[FLTAdRequest alloc] init], + }]; __block bool loadAdResultInvoked = false; __block id _Nullable returnedLoadAdResult; @@ -569,8 +537,7 @@ - (void)testGetAdSize_bannerAd { returnedLoadAdResult = result; }; - [_fltGoogleMobileAdsPlugin handleMethodCall:loadAdMethodCall - result:loadAdResult]; + [_fltGoogleMobileAdsPlugin handleMethodCall:loadAdMethodCall result:loadAdResult]; XCTAssertTrue(loadAdResultInvoked); XCTAssertNil(returnedLoadAdResult); @@ -584,10 +551,8 @@ - (void)testGetAdSize_bannerAd { }; FlutterMethodCall *getAdSizeMethodCall = - [FlutterMethodCall methodCallWithMethodName:@"getAdSize" - arguments:@{@"adId" : @(1)}]; - [_fltGoogleMobileAdsPlugin handleMethodCall:getAdSizeMethodCall - result:getAdSizeResult]; + [FlutterMethodCall methodCallWithMethodName:@"getAdSize" arguments:@{@"adId" : @(1)}]; + [_fltGoogleMobileAdsPlugin handleMethodCall:getAdSizeMethodCall result:getAdSizeResult]; XCTAssertTrue(getAdSizeResultInvoked); XCTAssertEqualObjects(returnedGetAdSizeResult.width, @1); @@ -602,13 +567,13 @@ - (void)testServerSideVerificationOptions_rewardedAd { // Method calls to set ssv FLTServerSideVerificationOptions *mockSSV = OCMClassMock([FLTServerSideVerificationOptions class]); - FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"setServerSideVerificationOptions" - arguments:@{ - @"adId" : @(1), - @"adUnitId" : @"ad-unit-id", - @"serverSideVerificationOptions" : mockSSV, - }]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"setServerSideVerificationOptions" + arguments:@{ + @"adId" : @(1), + @"adUnitId" : @"ad-unit-id", + @"serverSideVerificationOptions" : mockSSV, + }]; __block bool resultInvoked = false; FlutterResult result = ^(id _Nullable result) { @@ -623,20 +588,19 @@ - (void)testServerSideVerificationOptions_rewardedAd { - (void)testServerSideVerificationOptions_rewardedInterstitialAd { // Mock having already loaded an ad - FLTRewardedInterstitialAd *mockAd = - OCMClassMock([FLTRewardedInterstitialAd class]); + FLTRewardedInterstitialAd *mockAd = OCMClassMock([FLTRewardedInterstitialAd class]); OCMStub([_mockAdInstanceManager adFor:[OCMArg isEqual:@1]]).andReturn(mockAd); // Method calls to set ssv FLTServerSideVerificationOptions *mockSSV = OCMClassMock([FLTServerSideVerificationOptions class]); - FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"setServerSideVerificationOptions" - arguments:@{ - @"adId" : @(1), - @"adUnitId" : @"ad-unit-id", - @"serverSideVerificationOptions" : mockSSV, - }]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"setServerSideVerificationOptions" + arguments:@{ + @"adId" : @(1), + @"adUnitId" : @"ad-unit-id", + @"serverSideVerificationOptions" : mockSSV, + }]; __block bool resultInvoked = false; FlutterResult result = ^(id _Nullable result) { @@ -653,13 +617,13 @@ - (void)testServerSideVerificationOptions_nullAd { // Try to set ssv without any ads being loaded FLTServerSideVerificationOptions *mockSSV = OCMClassMock([FLTServerSideVerificationOptions class]); - FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"setServerSideVerificationOptions" - arguments:@{ - @"adId" : @(1), - @"adUnitId" : @"ad-unit-id", - @"serverSideVerificationOptions" : mockSSV, - }]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"setServerSideVerificationOptions" + arguments:@{ + @"adId" : @(1), + @"adUnitId" : @"ad-unit-id", + @"serverSideVerificationOptions" : mockSSV, + }]; __block bool resultInvoked = false; FlutterResult result = ^(id _Nullable result) { @@ -681,13 +645,13 @@ - (void)testServerSideVerificationOptions_invalidAdType { // Try to set ssv without any ads being loaded FLTServerSideVerificationOptions *mockSSV = OCMClassMock([FLTServerSideVerificationOptions class]); - FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"setServerSideVerificationOptions" - arguments:@{ - @"adId" : @(1), - @"adUnitId" : @"ad-unit-id", - @"serverSideVerificationOptions" : mockSSV, - }]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"setServerSideVerificationOptions" + arguments:@{ + @"adId" : @(1), + @"adUnitId" : @"ad-unit-id", + @"serverSideVerificationOptions" : mockSSV, + }]; __block bool resultInvoked = false; FlutterResult result = ^(id _Nullable result) { diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsReaderWriterTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsReaderWriterTest.m index e60d75356..f409335dd 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsReaderWriterTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsReaderWriterTest.m @@ -46,12 +46,10 @@ @implementation FLTGoogleMobileAdsReaderWriterTest { - (void)setUp { id fltAdUtilMock = OCMClassMock([FLTAdUtil class]); - OCMStub(ClassMethod([fltAdUtilMock requestAgent])) - .andReturn(@"request-agent"); - _readerWriter = [[FLTGoogleMobileAdsReaderWriter alloc] - initWithFactory:[[FLTTestAdSizeFactory alloc] init]]; - _messageCodec = - [FlutterStandardMessageCodec codecWithReaderWriter:_readerWriter]; + OCMStub(ClassMethod([fltAdUtilMock requestAgent])).andReturn(@"request-agent"); + _readerWriter = + [[FLTGoogleMobileAdsReaderWriter alloc] initWithFactory:[[FLTTestAdSizeFactory alloc] init]]; + _messageCodec = [FlutterStandardMessageCodec codecWithReaderWriter:_readerWriter]; } - (void)testEncodeDecodeAdSize { @@ -66,20 +64,14 @@ - (void)testEncodeDecodeAdSize { - (void)testEncodeDecodeRequestConfiguration { GADMobileAds.sharedInstance.requestConfiguration.maxAdContentRating = GADMaxAdContentRatingMatureAudience; - GADMobileAds.sharedInstance.requestConfiguration - .tagForChildDirectedTreatment = @YES; - GADMobileAds.sharedInstance.requestConfiguration.tagForUnderAgeOfConsent = - @NO; - NSArray *testDeviceIds = - [[NSArray alloc] initWithObjects:@"test-device-id", nil]; - GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = - testDeviceIds; - NSData *encodedMessage = - [_messageCodec encode:GADMobileAds.sharedInstance.requestConfiguration]; + GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment = @YES; + GADMobileAds.sharedInstance.requestConfiguration.tagForUnderAgeOfConsent = @NO; + NSArray *testDeviceIds = [[NSArray alloc] initWithObjects:@"test-device-id", nil]; + GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = testDeviceIds; + NSData *encodedMessage = [_messageCodec encode:GADMobileAds.sharedInstance.requestConfiguration]; GADRequestConfiguration *decodedSize = [_messageCodec decode:encodedMessage]; - XCTAssertEqualObjects(decodedSize.maxAdContentRating, - GADMaxAdContentRatingMatureAudience); + XCTAssertEqualObjects(decodedSize.maxAdContentRating, GADMaxAdContentRatingMatureAudience); XCTAssertEqualObjects(decodedSize.testDeviceIdentifiers, testDeviceIds); } @@ -98,13 +90,10 @@ - (void)testEncodeDecodeInlineAdaptiveBannerAdSize_currentOrientation { NSData *encodedMessage = [_messageCodec encode:inlineAdaptiveBannerSize]; - FLTInlineAdaptiveBannerSize *decodedSize = - [_messageCodec decode:encodedMessage]; + FLTInlineAdaptiveBannerSize *decodedSize = [_messageCodec decode:encodedMessage]; XCTAssertEqual(decodedSize.size.size.width, testAdSize.size.width); - XCTAssertEqualObjects(decodedSize.maxHeight, - inlineAdaptiveBannerSize.maxHeight); - XCTAssertEqualObjects(decodedSize.orientation, - inlineAdaptiveBannerSize.orientation); + XCTAssertEqualObjects(decodedSize.maxHeight, inlineAdaptiveBannerSize.maxHeight); + XCTAssertEqualObjects(decodedSize.orientation, inlineAdaptiveBannerSize.orientation); } - (void)testEncodeDecodeInlineAdaptiveBannerAdSize_portraitOrientation { @@ -122,21 +111,17 @@ - (void)testEncodeDecodeInlineAdaptiveBannerAdSize_portraitOrientation { NSData *encodedMessage = [_messageCodec encode:inlineAdaptiveBannerSize]; - FLTInlineAdaptiveBannerSize *decodedSize = - [_messageCodec decode:encodedMessage]; + FLTInlineAdaptiveBannerSize *decodedSize = [_messageCodec decode:encodedMessage]; XCTAssertEqual(decodedSize.size.size.width, testAdSize.size.width); - XCTAssertEqualObjects(decodedSize.maxHeight, - inlineAdaptiveBannerSize.maxHeight); - XCTAssertEqualObjects(decodedSize.orientation, - inlineAdaptiveBannerSize.orientation); + XCTAssertEqualObjects(decodedSize.maxHeight, inlineAdaptiveBannerSize.maxHeight); + XCTAssertEqualObjects(decodedSize.orientation, inlineAdaptiveBannerSize.orientation); } - (void)testEncodeDecodeInlineAdaptiveBannerAdSize_landscapeOrientation { GADAdSize testAdSize = GADAdSizeFromCGSize(CGSizeMake(25, 10)); FLTAdSizeFactory *factory = OCMClassMock([FLTAdSizeFactory class]); - OCMStub([factory landscapeInlineAdaptiveBannerAdSizeWithWidth:@(23)]) - .andReturn(testAdSize); + OCMStub([factory landscapeInlineAdaptiveBannerAdSizeWithWidth:@(23)]).andReturn(testAdSize); FLTInlineAdaptiveBannerSize *inlineAdaptiveBannerSize = [[FLTInlineAdaptiveBannerSize alloc] initWithFactory:factory @@ -146,21 +131,17 @@ - (void)testEncodeDecodeInlineAdaptiveBannerAdSize_landscapeOrientation { NSData *encodedMessage = [_messageCodec encode:inlineAdaptiveBannerSize]; - FLTInlineAdaptiveBannerSize *decodedSize = - [_messageCodec decode:encodedMessage]; + FLTInlineAdaptiveBannerSize *decodedSize = [_messageCodec decode:encodedMessage]; XCTAssertEqual(decodedSize.size.size.width, testAdSize.size.width); - XCTAssertEqualObjects(decodedSize.maxHeight, - inlineAdaptiveBannerSize.maxHeight); - XCTAssertEqualObjects(decodedSize.orientation, - inlineAdaptiveBannerSize.orientation); + XCTAssertEqualObjects(decodedSize.maxHeight, inlineAdaptiveBannerSize.maxHeight); + XCTAssertEqualObjects(decodedSize.orientation, inlineAdaptiveBannerSize.orientation); } - (void)testEncodeDecodeInlineAdaptiveBannerAdSize_withMaxHeight { GADAdSize testAdSize = GADAdSizeFromCGSize(CGSizeMake(25, 10)); FLTAdSizeFactory *factory = OCMClassMock([FLTAdSizeFactory class]); - OCMStub([factory inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:@(23) - maxHeight:@50]) + OCMStub([factory inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:@(23) maxHeight:@50]) .andReturn(testAdSize); FLTInlineAdaptiveBannerSize *inlineAdaptiveBannerSize = @@ -171,21 +152,17 @@ - (void)testEncodeDecodeInlineAdaptiveBannerAdSize_withMaxHeight { NSData *encodedMessage = [_messageCodec encode:inlineAdaptiveBannerSize]; - FLTInlineAdaptiveBannerSize *decodedSize = - [_messageCodec decode:encodedMessage]; + FLTInlineAdaptiveBannerSize *decodedSize = [_messageCodec decode:encodedMessage]; XCTAssertEqual(decodedSize.size.size.width, testAdSize.size.width); - XCTAssertEqualObjects(decodedSize.maxHeight, - inlineAdaptiveBannerSize.maxHeight); - XCTAssertEqualObjects(decodedSize.orientation, - inlineAdaptiveBannerSize.orientation); + XCTAssertEqualObjects(decodedSize.maxHeight, inlineAdaptiveBannerSize.maxHeight); + XCTAssertEqualObjects(decodedSize.orientation, inlineAdaptiveBannerSize.orientation); } - (void)testEncodeDecodeAnchoredAdaptiveBannerAdSize_portraitOrientation { GADAdSize testAdSize = GADAdSizeFromCGSize(CGSizeMake(23, 34)); FLTAdSizeFactory *factory = OCMClassMock([FLTAdSizeFactory class]); - OCMStub([factory portraitAnchoredAdaptiveBannerAdSizeWithWidth:@(23)]) - .andReturn(testAdSize); + OCMStub([factory portraitAnchoredAdaptiveBannerAdSizeWithWidth:@(23)]).andReturn(testAdSize); FLTAnchoredAdaptiveBannerSize *size = [[FLTAnchoredAdaptiveBannerSize alloc] initWithFactory:factory @@ -193,8 +170,7 @@ - (void)testEncodeDecodeAnchoredAdaptiveBannerAdSize_portraitOrientation { width:@(23)]; NSData *encodedMessage = [_messageCodec encode:size]; - FLTAnchoredAdaptiveBannerSize *decodedSize = - [_messageCodec decode:encodedMessage]; + FLTAnchoredAdaptiveBannerSize *decodedSize = [_messageCodec decode:encodedMessage]; XCTAssertEqual(decodedSize.size.size.width, testAdSize.size.width); } @@ -202,8 +178,7 @@ - (void)testEncodeDecodeAnchoredAdaptiveBannerAdSize_landscapeOrientation { GADAdSize testAdSize = GADAdSizeFromCGSize(CGSizeMake(34, 45)); FLTAdSizeFactory *factory = OCMClassMock([FLTAdSizeFactory class]); - OCMStub([factory landscapeAnchoredAdaptiveBannerAdSizeWithWidth:@(34)]) - .andReturn(testAdSize); + OCMStub([factory landscapeAnchoredAdaptiveBannerAdSizeWithWidth:@(34)]).andReturn(testAdSize); FLTAnchoredAdaptiveBannerSize *size = [[FLTAnchoredAdaptiveBannerSize alloc] initWithFactory:factory @@ -211,8 +186,7 @@ - (void)testEncodeDecodeAnchoredAdaptiveBannerAdSize_landscapeOrientation { width:@(34)]; NSData *encodedMessage = [_messageCodec encode:size]; - FLTAnchoredAdaptiveBannerSize *decodedSize = - [_messageCodec decode:encodedMessage]; + FLTAnchoredAdaptiveBannerSize *decodedSize = [_messageCodec decode:encodedMessage]; XCTAssertEqual(decodedSize.size.size.width, testAdSize.size.width); } @@ -220,24 +194,19 @@ - (void)testEncodeDecodeAnchoredAdaptiveBannerAdSize_currentOrientation { GADAdSize testAdSize = GADAdSizeFromCGSize(CGSizeMake(45, 56)); FLTAdSizeFactory *factory = OCMClassMock([FLTAdSizeFactory class]); - OCMStub( - [factory currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:@(45)]) + OCMStub([factory currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:@(45)]) .andReturn(testAdSize); FLTAnchoredAdaptiveBannerSize *size = - [[FLTAnchoredAdaptiveBannerSize alloc] initWithFactory:factory - orientation:NULL - width:@(45)]; + [[FLTAnchoredAdaptiveBannerSize alloc] initWithFactory:factory orientation:NULL width:@(45)]; NSData *encodedMessage = [_messageCodec encode:size]; - FLTAnchoredAdaptiveBannerSize *decodedSize = - [_messageCodec decode:encodedMessage]; + FLTAnchoredAdaptiveBannerSize *decodedSize = [_messageCodec decode:encodedMessage]; XCTAssertEqual(decodedSize.size.size.width, testAdSize.size.width); } - (void)testEncodeDecodeSmartBannerAdSize { - FLTSmartBannerSize *size = - [[FLTSmartBannerSize alloc] initWithOrientation:@"landscape"]; + FLTSmartBannerSize *size = [[FLTSmartBannerSize alloc] initWithOrientation:@"landscape"]; NSData *encodedMessage = [_messageCodec encode:size]; FLTSmartBannerSize *decodedSize = [_messageCodec decode:encodedMessage]; @@ -245,10 +214,8 @@ - (void)testEncodeDecodeSmartBannerAdSize { XCTAssertTrue([decodedSize isKindOfClass:FLTSmartBannerSize.class]); #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - XCTAssertEqual(decodedSize.size.size.width, - kGADAdSizeSmartBannerPortrait.size.width); - XCTAssertEqual(decodedSize.size.size.height, - kGADAdSizeSmartBannerPortrait.size.height); + XCTAssertEqual(decodedSize.size.size.width, kGADAdSizeSmartBannerPortrait.size.width); + XCTAssertEqual(decodedSize.size.size.height, kGADAdSizeSmartBannerPortrait.size.height); #pragma clang diagnostic pop } @@ -264,8 +231,7 @@ - (void)testEncodeDecodeFluidAdSize { } - (void)testEncodeDecodeAdRequest { - id mediationExtras = - [[_FlutterMediationExtras alloc] init]; + id mediationExtras = [[_FlutterMediationExtras alloc] init]; mediationExtras.extras = @{@"test_key" : @"test_value"}; FLTAdRequest *request = [[FLTAdRequest alloc] init]; request.keywords = @[ @"apple" ]; @@ -275,8 +241,7 @@ - (void)testEncodeDecodeAdRequest { request.neighboringContentURLs = contentURLs; request.mediationExtrasIdentifier = @"identifier"; request.adMobExtras = @{@"key" : @"value"}; - NSArray> *mediationExtrasArray = - @[ mediationExtras ]; + NSArray> *mediationExtrasArray = @[ mediationExtras ]; request.mediationExtras = mediationExtrasArray; NSData *encodedMessage = [_messageCodec encode:request]; @@ -285,17 +250,14 @@ - (void)testEncodeDecodeAdRequest { XCTAssertEqualObjects(decodedRequest.contentURL, @"banana"); XCTAssertTrue(decodedRequest.nonPersonalizedAds); XCTAssertEqualObjects(decodedRequest.neighboringContentURLs, contentURLs); - XCTAssertEqualObjects(decodedRequest.mediationExtrasIdentifier, - @"identifier"); + XCTAssertEqualObjects(decodedRequest.mediationExtrasIdentifier, @"identifier"); XCTAssertEqualObjects(decodedRequest.adMobExtras, @{@"key" : @"value"}); XCTAssertEqualObjects(decodedRequest.requestAgent, @"request-agent"); - XCTAssertEqualObjects(decodedRequest.mediationExtras[0].extras, - @{@"test_key" : @"test_value"}); + XCTAssertEqualObjects(decodedRequest.mediationExtras[0].extras, @{@"test_key" : @"test_value"}); } - (void)testEncodeDecodeGAMAdRequest { - id mediationExtras = - [[_FlutterMediationExtras alloc] init]; + id mediationExtras = [[_FlutterMediationExtras alloc] init]; mediationExtras.extras = @{@"test_key" : @"test_value"}; FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init]; request.keywords = @[ @"apple" ]; @@ -308,32 +270,27 @@ - (void)testEncodeDecodeGAMAdRequest { request.pubProvidedID = @"pub-id"; request.mediationExtrasIdentifier = @"identifier"; request.adMobExtras = @{@"key" : @"value"}; - NSArray> *mediationExtrasArray = - @[ mediationExtras ]; + NSArray> *mediationExtrasArray = @[ mediationExtras ]; request.mediationExtras = mediationExtrasArray; NSData *encodedMessage = [_messageCodec encode:request]; FLTGAMAdRequest *decodedRequest = [_messageCodec decode:encodedMessage]; XCTAssertTrue([decodedRequest.keywords isEqualToArray:@[ @"apple" ]]); XCTAssertEqualObjects(decodedRequest.contentURL, @"banana"); - XCTAssertTrue([decodedRequest.customTargeting - isEqualToDictionary:@{@"table" : @"linen"}]); - XCTAssertTrue([decodedRequest.customTargetingLists - isEqualToDictionary:@{@"go" : @[ @"lakers" ]}]); + XCTAssertTrue([decodedRequest.customTargeting isEqualToDictionary:@{@"table" : @"linen"}]); + XCTAssertTrue( + [decodedRequest.customTargetingLists isEqualToDictionary:@{@"go" : @[ @"lakers" ]}]); XCTAssertTrue(decodedRequest.nonPersonalizedAds); XCTAssertEqualObjects(decodedRequest.neighboringContentURLs, contentURLs); XCTAssertEqualObjects(decodedRequest.pubProvidedID, @"pub-id"); - XCTAssertEqualObjects(decodedRequest.mediationExtrasIdentifier, - @"identifier"); + XCTAssertEqualObjects(decodedRequest.mediationExtrasIdentifier, @"identifier"); XCTAssertEqualObjects(decodedRequest.adMobExtras, @{@"key" : @"value"}); XCTAssertEqualObjects(decodedRequest.requestAgent, @"request-agent"); - XCTAssertEqualObjects(decodedRequest.mediationExtras[0].extras, - @{@"test_key" : @"test_value"}); + XCTAssertEqualObjects(decodedRequest.mediationExtras[0].extras, @{@"test_key" : @"test_value"}); } - (void)testEncodeDecodeRewardItem { - FLTRewardItem *item = [[FLTRewardItem alloc] initWithAmount:@(1) - type:@"apple"]; + FLTRewardItem *item = [[FLTRewardItem alloc] initWithAmount:@(1) type:@"apple"]; NSData *encodedMessage = [_messageCodec encode:item]; FLTRewardItem *decodedItem = [_messageCodec decode:encodedMessage]; @@ -348,44 +305,36 @@ - (void)testEncodeDecodeServerSideVerification { serverSideVerificationOptions.userIdentifier = @"user-id"; NSData *encodedMessage = [_messageCodec encode:serverSideVerificationOptions]; - FLTServerSideVerificationOptions *decoded = - [_messageCodec decode:encodedMessage]; + FLTServerSideVerificationOptions *decoded = [_messageCodec decode:encodedMessage]; XCTAssertEqualObjects(decoded.customRewardString, serverSideVerificationOptions.customRewardString); - XCTAssertEqualObjects(decoded.userIdentifier, - serverSideVerificationOptions.userIdentifier); + XCTAssertEqualObjects(decoded.userIdentifier, serverSideVerificationOptions.userIdentifier); // With customRewardString not defined. - serverSideVerificationOptions = - [[FLTServerSideVerificationOptions alloc] init]; + serverSideVerificationOptions = [[FLTServerSideVerificationOptions alloc] init]; serverSideVerificationOptions.userIdentifier = @"user-id"; encodedMessage = [_messageCodec encode:serverSideVerificationOptions]; decoded = [_messageCodec decode:encodedMessage]; XCTAssertEqualObjects(decoded.customRewardString, serverSideVerificationOptions.customRewardString); - XCTAssertEqualObjects(decoded.userIdentifier, - serverSideVerificationOptions.userIdentifier); + XCTAssertEqualObjects(decoded.userIdentifier, serverSideVerificationOptions.userIdentifier); // With userId not defined. - serverSideVerificationOptions = - [[FLTServerSideVerificationOptions alloc] init]; + serverSideVerificationOptions = [[FLTServerSideVerificationOptions alloc] init]; serverSideVerificationOptions.customRewardString = @"reward"; encodedMessage = [_messageCodec encode:serverSideVerificationOptions]; decoded = [_messageCodec decode:encodedMessage]; XCTAssertEqualObjects(decoded.customRewardString, serverSideVerificationOptions.customRewardString); - XCTAssertEqualObjects(decoded.userIdentifier, - serverSideVerificationOptions.userIdentifier); + XCTAssertEqualObjects(decoded.userIdentifier, serverSideVerificationOptions.userIdentifier); // Both undefined. - serverSideVerificationOptions = - [[FLTServerSideVerificationOptions alloc] init]; + serverSideVerificationOptions = [[FLTServerSideVerificationOptions alloc] init]; encodedMessage = [_messageCodec encode:serverSideVerificationOptions]; decoded = [_messageCodec decode:encodedMessage]; XCTAssertEqualObjects(decoded.customRewardString, serverSideVerificationOptions.customRewardString); - XCTAssertEqualObjects(decoded.userIdentifier, - serverSideVerificationOptions.userIdentifier); + XCTAssertEqualObjects(decoded.userIdentifier, serverSideVerificationOptions.userIdentifier); } - (void)testEncodeDecodeNSError { @@ -407,13 +356,10 @@ - (void)testEncodeDecodeFLTGADLoadError { NSString *identifier = @"test-identifier"; NSString *className = @"test-class-name"; OCMStub([mockResponseInfo responseIdentifier]).andReturn(identifier); - OCMStub(mockResponseInfo.loadedAdNetworkResponseInfo) - .andReturn(mockAdNetworkResponseInfo); + OCMStub(mockResponseInfo.loadedAdNetworkResponseInfo).andReturn(mockAdNetworkResponseInfo); OCMStub(mockAdNetworkResponseInfo.adNetworkClassName).andReturn(className); - NSDictionary *userInfo = @{ - NSLocalizedDescriptionKey : @"message", - GADErrorUserInfoKeyResponseInfo : mockResponseInfo - }; + NSDictionary *userInfo = + @{NSLocalizedDescriptionKey : @"message", GADErrorUserInfoKeyResponseInfo : mockResponseInfo}; NSError *error = [NSError errorWithDomain:@"domain" code:1 userInfo:userInfo]; FLTLoadAdError *loadAdError = [[FLTLoadAdError alloc] initWithError:error]; @@ -423,16 +369,13 @@ - (void)testEncodeDecodeFLTGADLoadError { XCTAssertEqual(decodedError.code, 1); XCTAssertEqualObjects(decodedError.domain, @"domain"); XCTAssertEqualObjects(decodedError.message, @"message"); - XCTAssertEqualObjects(decodedError.responseInfo.adNetworkClassName, - className); - XCTAssertEqualObjects(decodedError.responseInfo.responseIdentifier, - identifier); + XCTAssertEqualObjects(decodedError.responseInfo.adNetworkClassName, className); + XCTAssertEqualObjects(decodedError.responseInfo.responseIdentifier, identifier); XCTAssertTrue(decodedError.responseInfo.adNetworkInfoArray.count == 0); } - (void)testEncodeDecodeFLTGADLoadErrorWithResponseInfo { - GADAdNetworkResponseInfo *mockNetworkResponse = - OCMClassMock([GADAdNetworkResponseInfo class]); + GADAdNetworkResponseInfo *mockNetworkResponse = OCMClassMock([GADAdNetworkResponseInfo class]); OCMStub([mockNetworkResponse adNetworkClassName]).andReturn(@"adapter-class"); GADResponseInfo *mockResponseInfo = OCMClassMock([GADResponseInfo class]); @@ -441,16 +384,11 @@ - (void)testEncodeDecodeFLTGADLoadErrorWithResponseInfo { NSString *identifier = @"test-identifier"; NSString *className = @"test-class-name"; OCMStub([mockResponseInfo responseIdentifier]).andReturn(identifier); - OCMStub(mockResponseInfo.loadedAdNetworkResponseInfo) - .andReturn(mockAdNetworkResponseInfo); + OCMStub(mockResponseInfo.loadedAdNetworkResponseInfo).andReturn(mockAdNetworkResponseInfo); OCMStub(mockAdNetworkResponseInfo.adNetworkClassName).andReturn(className); - OCMStub([mockResponseInfo adNetworkInfoArray]).andReturn(@[ - mockNetworkResponse - ]); - NSDictionary *userInfo = @{ - NSLocalizedDescriptionKey : @"message", - GADErrorUserInfoKeyResponseInfo : mockResponseInfo - }; + OCMStub([mockResponseInfo adNetworkInfoArray]).andReturn(@[ mockNetworkResponse ]); + NSDictionary *userInfo = + @{NSLocalizedDescriptionKey : @"message", GADErrorUserInfoKeyResponseInfo : mockResponseInfo}; NSError *error = [NSError errorWithDomain:@"domain" code:1 userInfo:userInfo]; FLTLoadAdError *loadAdError = [[FLTLoadAdError alloc] initWithError:error]; @@ -460,13 +398,10 @@ - (void)testEncodeDecodeFLTGADLoadErrorWithResponseInfo { XCTAssertEqual(decodedError.code, 1); XCTAssertEqualObjects(decodedError.domain, @"domain"); XCTAssertEqualObjects(decodedError.message, @"message"); - XCTAssertEqualObjects(decodedError.responseInfo.adNetworkClassName, - className); - XCTAssertEqualObjects(decodedError.responseInfo.responseIdentifier, - identifier); + XCTAssertEqualObjects(decodedError.responseInfo.adNetworkClassName, className); + XCTAssertEqualObjects(decodedError.responseInfo.responseIdentifier, identifier); XCTAssertTrue(decodedError.responseInfo.adNetworkInfoArray.count == 1); - XCTAssertEqualObjects(decodedError.responseInfo.adNetworkInfoArray.firstObject - .adNetworkClassName, + XCTAssertEqualObjects(decodedError.responseInfo.adNetworkInfoArray.firstObject.adNetworkClassName, @"adapter-class"); } @@ -479,38 +414,29 @@ - (void)testEncodeDecodeFLTGADResponseInfo { OCMStub([error code]).andReturn(1); OCMStub([error localizedDescription]).andReturn(@"error"); - GADAdNetworkResponseInfo *mockGADResponseInfo = - OCMClassMock([GADAdNetworkResponseInfo class]); + GADAdNetworkResponseInfo *mockGADResponseInfo = OCMClassMock([GADAdNetworkResponseInfo class]); OCMStub([mockGADResponseInfo adNetworkClassName]).andReturn(@"adapter-class"); OCMStub([mockGADResponseInfo latency]).andReturn(123.1234); - OCMStub([mockGADResponseInfo dictionaryRepresentation]) - .andReturn(descriptionsDict); + OCMStub([mockGADResponseInfo dictionaryRepresentation]).andReturn(descriptionsDict); OCMStub([mockGADResponseInfo adUnitMapping]).andReturn(adUnitMappingsDict); OCMStub([mockGADResponseInfo error]).andReturn(error); GADAdNetworkResponseInfo *mockLoadedGADResponseInfo = OCMClassMock([GADAdNetworkResponseInfo class]); - OCMStub([mockLoadedGADResponseInfo adNetworkClassName]) - .andReturn(@"loaded-adapter"); + OCMStub([mockLoadedGADResponseInfo adNetworkClassName]).andReturn(@"loaded-adapter"); OCMStub([mockLoadedGADResponseInfo latency]).andReturn(123.1234); - OCMStub([mockLoadedGADResponseInfo dictionaryRepresentation]) - .andReturn(descriptionsDict); - OCMStub([mockLoadedGADResponseInfo adUnitMapping]) - .andReturn(adUnitMappingsDict); + OCMStub([mockLoadedGADResponseInfo dictionaryRepresentation]).andReturn(descriptionsDict); + OCMStub([mockLoadedGADResponseInfo adUnitMapping]).andReturn(adUnitMappingsDict); OCMStub([mockLoadedGADResponseInfo error]).andReturn(error); OCMStub([mockLoadedGADResponseInfo adSourceName]).andReturn(@"adSourceName"); OCMStub([mockLoadedGADResponseInfo adSourceID]).andReturn(@"adSourceID"); - OCMStub([mockLoadedGADResponseInfo adSourceInstanceName]) - .andReturn(@"adSourceInstanceName"); - OCMStub([mockLoadedGADResponseInfo adSourceInstanceID]) - .andReturn(@"adSourceInstanceID"); + OCMStub([mockLoadedGADResponseInfo adSourceInstanceName]).andReturn(@"adSourceInstanceName"); + OCMStub([mockLoadedGADResponseInfo adSourceInstanceID]).andReturn(@"adSourceInstanceID"); FLTGADAdNetworkResponseInfo *adNetworkResponseInfo = - [[FLTGADAdNetworkResponseInfo alloc] - initWithResponseInfo:mockGADResponseInfo]; + [[FLTGADAdNetworkResponseInfo alloc] initWithResponseInfo:mockGADResponseInfo]; FLTGADAdNetworkResponseInfo *loadedNetworkResponseInfo = - [[FLTGADAdNetworkResponseInfo alloc] - initWithResponseInfo:mockLoadedGADResponseInfo]; + [[FLTGADAdNetworkResponseInfo alloc] initWithResponseInfo:mockLoadedGADResponseInfo]; FLTGADResponseInfo *responseInfo = [[FLTGADResponseInfo alloc] init]; responseInfo.adNetworkClassName = @"class-name"; @@ -520,55 +446,43 @@ - (void)testEncodeDecodeFLTGADResponseInfo { responseInfo.extrasDictionary = @{@"key" : @"value"}; NSData *encodedMessage = [_messageCodec encode:responseInfo]; - FLTGADResponseInfo *decodedResponseInfo = - [_messageCodec decode:encodedMessage]; + FLTGADResponseInfo *decodedResponseInfo = [_messageCodec decode:encodedMessage]; XCTAssertEqualObjects(decodedResponseInfo.adNetworkClassName, @"class-name"); XCTAssertEqualObjects(decodedResponseInfo.responseIdentifier, @"identifier"); - XCTAssertEqualObjects(decodedResponseInfo.extrasDictionary, - @{@"key" : @"value"}); + XCTAssertEqualObjects(decodedResponseInfo.extrasDictionary, @{@"key" : @"value"}); XCTAssertEqual(decodedResponseInfo.adNetworkInfoArray.count, 1); - FLTGADAdNetworkResponseInfo *decodedInfo = - decodedResponseInfo.adNetworkInfoArray.firstObject; + FLTGADAdNetworkResponseInfo *decodedInfo = decodedResponseInfo.adNetworkInfoArray.firstObject; XCTAssertEqualObjects(decodedInfo.adNetworkClassName, @"adapter-class"); XCTAssertEqualObjects(decodedInfo.latency, @(123123)); - XCTAssertEqualObjects(decodedInfo.dictionaryDescription, - @"{\n descriptions = dict;\n}"); + XCTAssertEqualObjects(decodedInfo.dictionaryDescription, @"{\n descriptions = dict;\n}"); XCTAssertEqualObjects(decodedInfo.adUnitMapping, adUnitMappingsDict); XCTAssertEqual(decodedInfo.error.code, 1); XCTAssertEqualObjects(decodedInfo.error.domain, @"domain"); XCTAssertEqualObjects(decodedInfo.error.localizedDescription, @"error"); - FLTGADAdNetworkResponseInfo *decodedLoadedInfo = - decodedResponseInfo.loadedAdNetworkResponseInfo; - XCTAssertEqualObjects(decodedLoadedInfo.adNetworkClassName, - @"loaded-adapter"); + FLTGADAdNetworkResponseInfo *decodedLoadedInfo = decodedResponseInfo.loadedAdNetworkResponseInfo; + XCTAssertEqualObjects(decodedLoadedInfo.adNetworkClassName, @"loaded-adapter"); XCTAssertEqualObjects(decodedLoadedInfo.latency, @(123123)); - XCTAssertEqualObjects(decodedLoadedInfo.dictionaryDescription, - @"{\n descriptions = dict;\n}"); + XCTAssertEqualObjects(decodedLoadedInfo.dictionaryDescription, @"{\n descriptions = dict;\n}"); XCTAssertEqualObjects(decodedLoadedInfo.adUnitMapping, adUnitMappingsDict); XCTAssertEqual(decodedLoadedInfo.error.code, 1); XCTAssertEqualObjects(decodedLoadedInfo.error.domain, @"domain"); XCTAssertEqualObjects(decodedLoadedInfo.error.localizedDescription, @"error"); XCTAssertEqualObjects(decodedLoadedInfo.adSourceName, @"adSourceName"); XCTAssertEqualObjects(decodedLoadedInfo.adSourceID, @"adSourceID"); - XCTAssertEqualObjects(decodedLoadedInfo.adSourceInstanceName, - @"adSourceInstanceName"); - XCTAssertEqualObjects(decodedLoadedInfo.adSourceInstanceID, - @"adSourceInstanceID"); + XCTAssertEqualObjects(decodedLoadedInfo.adSourceInstanceName, @"adSourceInstanceName"); + XCTAssertEqualObjects(decodedLoadedInfo.adSourceInstanceID, @"adSourceInstanceID"); } - (void)testEncodeDecodeFLTGADLoadErrorWithEmptyValues { GADResponseInfo *mockResponseInfo = OCMClassMock([GADResponseInfo class]); OCMStub([mockResponseInfo responseIdentifier]).andReturn(nil); - OCMStub([mockResponseInfo.loadedAdNetworkResponseInfo adNetworkClassName]) - .andReturn(nil); - NSDictionary *userInfo = @{ - NSLocalizedDescriptionKey : @"message", - GADErrorUserInfoKeyResponseInfo : mockResponseInfo - }; + OCMStub([mockResponseInfo.loadedAdNetworkResponseInfo adNetworkClassName]).andReturn(nil); + NSDictionary *userInfo = + @{NSLocalizedDescriptionKey : @"message", GADErrorUserInfoKeyResponseInfo : mockResponseInfo}; NSError *error = [NSError errorWithDomain:@"domain" code:1 userInfo:userInfo]; FLTLoadAdError *loadAdError = [[FLTLoadAdError alloc] initWithError:error]; @@ -602,8 +516,7 @@ - (void)testEncodeDecodeInitializationStatus { NSData *encodedMessage = [_messageCodec encode:status]; - FLTInitializationStatus *decodedStatus = - [_messageCodec decode:encodedMessage]; + FLTInitializationStatus *decodedStatus = [_messageCodec decode:encodedMessage]; XCTAssertEqual(decodedStatus.adapterStatuses.count, 1); XCTAssertEqualObjects(decodedStatus.adapterStatuses.allKeys[0], @"name"); XCTAssertNil(decodedStatus.adapterStatuses.allValues[0].state); @@ -612,12 +525,10 @@ - (void)testEncodeDecodeInitializationStatus { } - (void)testEncodeDecodeNativeTemplateType { - FLTNativeTemplateType *templateType = - [[FLTNativeTemplateType alloc] initWithInt:1]; + FLTNativeTemplateType *templateType = [[FLTNativeTemplateType alloc] initWithInt:1]; NSData *encodedMessage = [_messageCodec encode:templateType]; - FLTNativeTemplateType *decodedTemplateType = - [_messageCodec decode:encodedMessage]; + FLTNativeTemplateType *decodedTemplateType = [_messageCodec decode:encodedMessage]; [self assertEqualTemplateTypes:templateType second:decodedTemplateType]; } @@ -626,17 +537,15 @@ - (void)testEncodeDecodeNativeTemplateFontStyle { [[FLTNativeTemplateFontStyleWrapper alloc] initWithInt:2]; NSData *encodedMessage = [_messageCodec encode:fontStyle]; - FLTNativeTemplateFontStyleWrapper *decoded = - [_messageCodec decode:encodedMessage]; + FLTNativeTemplateFontStyleWrapper *decoded = [_messageCodec decode:encodedMessage]; [self assertEqualTemplateFontStyles:fontStyle second:decoded]; } - (void)testEncodeDecodeNativeTemplateColor { - FLTNativeTemplateColor *color = - [[FLTNativeTemplateColor alloc] initWithAlpha:@2.0f - red:@3.0f - green:@4.0f - blue:@5.0f]; + FLTNativeTemplateColor *color = [[FLTNativeTemplateColor alloc] initWithAlpha:@2.0f + red:@3.0f + green:@4.0f + blue:@5.0f]; NSData *encodedMessage = [_messageCodec encode:color]; FLTNativeTemplateColor *decoded = [_messageCodec decode:encodedMessage]; @@ -644,16 +553,14 @@ - (void)testEncodeDecodeNativeTemplateColor { } - (void)testEncodeDecodeNativeTemplateTextStyle { - FLTNativeTemplateColor *textColor = - [[FLTNativeTemplateColor alloc] initWithAlpha:@2.0f - red:@3.0f - green:@4.0f - blue:@5.0f]; - FLTNativeTemplateColor *backgroundColor = - [[FLTNativeTemplateColor alloc] initWithAlpha:@6.0f - red:@7.0f - green:@8.0f - blue:@9.0f]; + FLTNativeTemplateColor *textColor = [[FLTNativeTemplateColor alloc] initWithAlpha:@2.0f + red:@3.0f + green:@4.0f + blue:@5.0f]; + FLTNativeTemplateColor *backgroundColor = [[FLTNativeTemplateColor alloc] initWithAlpha:@6.0f + red:@7.0f + green:@8.0f + blue:@9.0f]; FLTNativeTemplateFontStyleWrapper *fontStyle = [[FLTNativeTemplateFontStyleWrapper alloc] initWithInt:1]; @@ -669,24 +576,18 @@ - (void)testEncodeDecodeNativeTemplateTextStyle { } - (void)testEncodeDecodeNativeTemplateStyle { - FLTNativeTemplateType *templateType = - [[FLTNativeTemplateType alloc] initWithInt:0]; + FLTNativeTemplateType *templateType = [[FLTNativeTemplateType alloc] initWithInt:0]; FLTNativeTemplateColor *mainBackgroundColor = - [[FLTNativeTemplateColor alloc] initWithAlpha:@2.0f - red:@3.0f - green:@4.0f - blue:@5.0f]; - - FLTNativeTemplateColor *ctaTextColor = - [[FLTNativeTemplateColor alloc] initWithAlpha:@2.0f - red:@3.0f - green:@4.0f - blue:@5.0f]; - FLTNativeTemplateColor *ctaBackgroundColor = - [[FLTNativeTemplateColor alloc] initWithAlpha:@6.0f - red:@7.0f - green:@8.0f - blue:@9.0f]; + [[FLTNativeTemplateColor alloc] initWithAlpha:@2.0f red:@3.0f green:@4.0f blue:@5.0f]; + + FLTNativeTemplateColor *ctaTextColor = [[FLTNativeTemplateColor alloc] initWithAlpha:@2.0f + red:@3.0f + green:@4.0f + blue:@5.0f]; + FLTNativeTemplateColor *ctaBackgroundColor = [[FLTNativeTemplateColor alloc] initWithAlpha:@6.0f + red:@7.0f + green:@8.0f + blue:@9.0f]; FLTNativeTemplateFontStyleWrapper *ctaFontStyle = [[FLTNativeTemplateFontStyleWrapper alloc] initWithInt:1]; @@ -707,11 +608,10 @@ - (void)testEncodeDecodeNativeTemplateStyle { fontStyle:nil size:@30.0f]; - FLTNativeTemplateColor *tertiaryTextColor = - [[FLTNativeTemplateColor alloc] initWithAlpha:@12.0f - red:@13.0f - green:@14.0f - blue:@15.0f]; + FLTNativeTemplateColor *tertiaryTextColor = [[FLTNativeTemplateColor alloc] initWithAlpha:@12.0f + red:@13.0f + green:@14.0f + blue:@15.0f]; FLTNativeTemplateTextStyle *tertiaryTextStyle = [[FLTNativeTemplateTextStyle alloc] initWithTextColor:tertiaryTextColor backgroundColor:nil @@ -730,20 +630,13 @@ - (void)testEncodeDecodeNativeTemplateStyle { NSData *encodedMessage = [_messageCodec encode:style]; FLTNativeTemplateStyle *decoded = [_messageCodec decode:encodedMessage]; - [self assertEqualTemplateTypes:style.templateType - second:decoded.templateType]; - [self assertEqualTemplateColors:style.mainBackgroundColor - second:decoded.mainBackgroundColor]; - [self assertEqualTextStyles:style.callToActionStyle - second:decoded.callToActionStyle]; - [self assertEqualTextStyles:style.primaryTextStyle - second:decoded.primaryTextStyle]; - [self assertEqualTextStyles:style.secondaryTextStyle - second:decoded.secondaryTextStyle]; - [self assertEqualTextStyles:style.tertiaryTextStyle - second:decoded.tertiaryTextStyle]; - XCTAssertEqual(style.cornerRadius.floatValue, - decoded.cornerRadius.floatValue); + [self assertEqualTemplateTypes:style.templateType second:decoded.templateType]; + [self assertEqualTemplateColors:style.mainBackgroundColor second:decoded.mainBackgroundColor]; + [self assertEqualTextStyles:style.callToActionStyle second:decoded.callToActionStyle]; + [self assertEqualTextStyles:style.primaryTextStyle second:decoded.primaryTextStyle]; + [self assertEqualTextStyles:style.secondaryTextStyle second:decoded.secondaryTextStyle]; + [self assertEqualTextStyles:style.tertiaryTextStyle second:decoded.tertiaryTextStyle]; + XCTAssertEqual(style.cornerRadius.floatValue, decoded.cornerRadius.floatValue); } #pragma mark - Helper methods to compare native templates types @@ -751,16 +644,14 @@ - (void)testEncodeDecodeNativeTemplateStyle { - (void)assertEqualTextStyles:(FLTNativeTemplateTextStyle *)first second:(FLTNativeTemplateTextStyle *)second { [self assertEqualTemplateColors:first.textColor second:second.textColor]; - [self assertEqualTemplateColors:first.backgroundColor - second:second.backgroundColor]; + [self assertEqualTemplateColors:first.backgroundColor second:second.backgroundColor]; XCTAssertEqual(first.fontStyle.intValue, second.fontStyle.intValue); XCTAssertEqual(first.size.floatValue, second.size.floatValue); } - (void)assertEqualTemplateFontStyles:(FLTNativeTemplateFontStyleWrapper *)first - second: - (FLTNativeTemplateFontStyleWrapper *)second { + second:(FLTNativeTemplateFontStyleWrapper *)second { XCTAssertEqual(first.intValue, second.intValue); } @@ -796,8 +687,7 @@ - (GADAdSize)landscapeAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *)width { return GADAdSizeFromCGSize(CGSizeMake(width.doubleValue, 0)); } -- (GADAdSize)currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth: - (NSNumber *)width { +- (GADAdSize)currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *)width { return GADAdSizeFromCGSize(CGSizeMake(width.doubleValue, 0)); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m index 5cccc781f..fbebd24e7 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m @@ -35,20 +35,19 @@ @implementation FLTGoogleMobileAdsTest { - (void)setUp { _mockMessenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger)); - _manager = - [[FLTAdInstanceManager alloc] initWithBinaryMessenger:_mockMessenger]; + _manager = [[FLTAdInstanceManager alloc] initWithBinaryMessenger:_mockMessenger]; _methodCodec = [FlutterStandardMethodCodec codecWithReaderWriter:[[FLTGoogleMobileAdsReaderWriter alloc] init]]; } - (void)testAdInstanceManagerLoadAd { FLTAdSize *size = [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)]; - FLTBannerAd *bannerAd = [[FLTBannerAd alloc] - initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@1]; + FLTBannerAd *bannerAd = + [[FLTBannerAd alloc] initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@1]; FLTBannerAd *mockBannerAd = OCMPartialMock(bannerAd); OCMStub([mockBannerAd load]); @@ -62,12 +61,12 @@ - (void)testAdInstanceManagerLoadAd { - (void)testAdInstanceManagerDisposeAd { FLTAdSize *size = [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)]; - FLTBannerAd *bannerAd = [[FLTBannerAd alloc] - initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@1]; + FLTBannerAd *bannerAd = + [[FLTBannerAd alloc] initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@1]; FLTBannerAd *mockBannerAd = OCMPartialMock(bannerAd); OCMStub([mockBannerAd load]); @@ -80,21 +79,21 @@ - (void)testAdInstanceManagerDisposeAd { - (void)testAdInstanceManagerDisposeAllAds { FLTAdSize *size = [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)]; - FLTBannerAd *bannerAd1 = [[FLTBannerAd alloc] - initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@1]; + FLTBannerAd *bannerAd1 = + [[FLTBannerAd alloc] initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@1]; FLTBannerAd *mockBannerAd1 = OCMPartialMock(bannerAd1); OCMStub([mockBannerAd1 load]); - FLTBannerAd *bannerAd2 = [[FLTBannerAd alloc] - initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@2]; + FLTBannerAd *bannerAd2 = + [[FLTBannerAd alloc] initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@2]; FLTBannerAd *mockBannerAd2 = OCMPartialMock(bannerAd2); OCMStub([mockBannerAd2 load]); @@ -109,15 +108,15 @@ - (void)testAdInstanceManagerDisposeAllAds { } - (void)testAdInstanceManagerOnAdLoaded { - FLTNativeAd *ad = [[FLTNativeAd alloc] - initWithAdUnitId:@"testAdUnitId" - request:[[FLTAdRequest alloc] init] - nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) - customOptions:nil - rootViewController:OCMClassMock([UIViewController class]) - adId:@1 - nativeAdOptions:nil - nativeTemplateStyle:nil]; + FLTNativeAd *ad = + [[FLTNativeAd alloc] initWithAdUnitId:@"testAdUnitId" + request:[[FLTAdRequest alloc] init] + nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) + customOptions:nil + rootViewController:OCMClassMock([UIViewController class]) + adId:@1 + nativeAdOptions:nil + nativeTemplateStyle:nil]; [_manager loadAd:ad]; GADResponseInfo *responseInfo = OCMClassMock([GADResponseInfo class]); @@ -125,26 +124,25 @@ - (void)testAdInstanceManagerOnAdLoaded { [[FLTGADResponseInfo alloc] initWithResponseInfo:responseInfo]; [_manager onAdLoaded:ad responseInfo:responseInfo]; NSData *data = [_methodCodec - encodeMethodCall:[FlutterMethodCall - methodCallWithMethodName:@"onAdEvent" - arguments:@{ - @"adId" : @1, - @"eventName" : @"onAdLoaded", - @"responseInfo" : fltResponseInfo, - }]]; + encodeMethodCall:[FlutterMethodCall methodCallWithMethodName:@"onAdEvent" + arguments:@{ + @"adId" : @1, + @"eventName" : @"onAdLoaded", + @"responseInfo" : fltResponseInfo, + }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); } - (void)testAdInstanceManagerOnAdFailedToLoad { - FLTNativeAd *ad = [[FLTNativeAd alloc] - initWithAdUnitId:@"testAdUnitId" - request:[[FLTAdRequest alloc] init] - nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) - customOptions:nil - rootViewController:OCMClassMock([UIViewController class]) - adId:@1 - nativeAdOptions:nil - nativeTemplateStyle:nil]; + FLTNativeAd *ad = + [[FLTNativeAd alloc] initWithAdUnitId:@"testAdUnitId" + request:[[FLTAdRequest alloc] init] + nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) + customOptions:nil + rootViewController:OCMClassMock([UIViewController class]) + adId:@1 + nativeAdOptions:nil + nativeTemplateStyle:nil]; [_manager loadAd:ad]; NSDictionary *userInfo = @{NSLocalizedDescriptionKey : @"message"}; @@ -153,13 +151,12 @@ - (void)testAdInstanceManagerOnAdFailedToLoad { FLTLoadAdError *loadAdError = [[FLTLoadAdError alloc] initWithError:error]; [_manager onAdFailedToLoad:ad error:error]; NSData *data = [_methodCodec - encodeMethodCall:[FlutterMethodCall - methodCallWithMethodName:@"onAdEvent" - arguments:@{ - @"adId" : @1, - @"eventName" : @"onAdFailedToLoad", - @"loadAdError" : loadAdError, - }]]; + encodeMethodCall:[FlutterMethodCall methodCallWithMethodName:@"onAdEvent" + arguments:@{ + @"adId" : @1, + @"eventName" : @"onAdFailedToLoad", + @"loadAdError" : loadAdError, + }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); } @@ -177,50 +174,44 @@ - (void)testAdInstanceManagerOnAdFailedToShow { methodCallWithMethodName:@"onAdEvent" arguments:@{ @"adId" : @1, - @"eventName" : - @"didFailToPresentFullScreenCon" - @"tentWithError", + @"eventName" : @"didFailToPresentFullScreenCon" + @"tentWithError", @"error" : error, }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); } - (void)testAdInstanceManagerOnAppEvent { - FLTNativeAd *ad = [[FLTNativeAd alloc] - initWithAdUnitId:@"testAdUnitId" - request:[[FLTAdRequest alloc] init] - nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) - customOptions:nil - rootViewController:OCMClassMock([UIViewController class]) - adId:@1 - nativeAdOptions:nil - nativeTemplateStyle:nil]; - FlutterMethodChannel *mockMethodChannel = - OCMClassMock([FlutterMethodChannel class]); + FLTNativeAd *ad = + [[FLTNativeAd alloc] initWithAdUnitId:@"testAdUnitId" + request:[[FLTAdRequest alloc] init] + nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) + customOptions:nil + rootViewController:OCMClassMock([UIViewController class]) + adId:@1 + nativeAdOptions:nil + nativeTemplateStyle:nil]; + FlutterMethodChannel *mockMethodChannel = OCMClassMock([FlutterMethodChannel class]); [_manager setValue:mockMethodChannel forKey:@"_channel"]; [_manager loadAd:ad]; [_manager onAppEvent:ad name:@"color" data:@"red"]; - NSDictionary *arguments = @{ - @"adId" : @1, - @"eventName" : @"onAppEvent", - @"name" : @"color", - @"data" : @"red" - }; + NSDictionary *arguments = + @{@"adId" : @1, @"eventName" : @"onAppEvent", @"name" : @"color", @"data" : @"red"}; OCMVerify([mockMethodChannel invokeMethod:@"onAdEvent" arguments:arguments]); } - (void)testAdInstanceManagerOnNativeAdEvents { - FLTNativeAd *ad = [[FLTNativeAd alloc] - initWithAdUnitId:@"testAdUnitId" - request:[[FLTAdRequest alloc] init] - nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) - customOptions:nil - rootViewController:OCMClassMock([UIViewController class]) - adId:@1 - nativeAdOptions:nil - nativeTemplateStyle:nil]; + FLTNativeAd *ad = + [[FLTNativeAd alloc] initWithAdUnitId:@"testAdUnitId" + request:[[FLTAdRequest alloc] init] + nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) + customOptions:nil + rootViewController:OCMClassMock([UIViewController class]) + adId:@1 + nativeAdOptions:nil + nativeTemplateStyle:nil]; [_manager loadAd:ad]; [_manager adDidRecordClick:ad]; @@ -228,89 +219,78 @@ - (void)testAdInstanceManagerOnNativeAdEvents { OCMVerify([_mockMessenger sendOnChannel:channel message:clickData]); [_manager onNativeAdImpression:ad]; - NSData *impressionData = [self getDataForEvent:@"onNativeAdImpression" - adId:@1]; + NSData *impressionData = [self getDataForEvent:@"onNativeAdImpression" adId:@1]; OCMVerify([_mockMessenger sendOnChannel:channel message:impressionData]); [_manager onNativeAdWillPresentScreen:ad]; - NSData *presentScreenData = - [self getDataForEvent:@"onNativeAdWillPresentScreen" adId:@1]; + NSData *presentScreenData = [self getDataForEvent:@"onNativeAdWillPresentScreen" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:presentScreenData])); [_manager onNativeAdDidDismissScreen:ad]; - NSData *didDismissData = [self getDataForEvent:@"onNativeAdDidDismissScreen" - adId:@1]; + NSData *didDismissData = [self getDataForEvent:@"onNativeAdDidDismissScreen" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didDismissData])); [_manager onNativeAdWillDismissScreen:ad]; - NSData *willDismissData = [self getDataForEvent:@"onNativeAdWillDismissScreen" - adId:@1]; + NSData *willDismissData = [self getDataForEvent:@"onNativeAdWillDismissScreen" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:willDismissData])); } - (void)testAdInstanceManagerOnRewardedAdUserEarnedReward { - FLTRewardedAd *ad = [[FLTRewardedAd alloc] - initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager loadAd:ad]; [_manager onRewardedAdUserEarnedReward:ad - reward:[[FLTRewardItem alloc] - initWithAmount:@(1) - type:@"type"]]; + reward:[[FLTRewardItem alloc] initWithAmount:@(1) type:@"type"]]; NSData *data = [_methodCodec encodeMethodCall:[FlutterMethodCall methodCallWithMethodName:@"onAdEvent" arguments:@{ @"adId" : @1, - @"eventName" : - @"onRewardedAdUserEarnedReward", + @"eventName" : @"onRewardedAdUserEarnedReward", @"rewardItem" : - [[FLTRewardItem alloc] - initWithAmount:@(1) - type:@"type"] + [[FLTRewardItem alloc] initWithAmount:@(1) + type:@"type"] }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); } - (void)testAdInstanceManagerOnRewardedInterstitialAdUserEarnedReward { - FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] - initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + FLTRewardedInterstitialAd *ad = + [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager loadAd:ad]; [_manager onRewardedInterstitialAdUserEarnedReward:ad - reward:[[FLTRewardItem alloc] - initWithAmount:@(1) - type:@"type"]]; + reward:[[FLTRewardItem alloc] initWithAmount:@(1) + type:@"type"]]; NSData *data = [_methodCodec - encodeMethodCall: - [FlutterMethodCall - methodCallWithMethodName:@"onAdEvent" - arguments:@{ - @"adId" : @1, - @"eventName" : - @"onRewardedInterstitialAdUserEarnedReward", - @"rewardItem" : [[FLTRewardItem alloc] - initWithAmount:@(1) - type:@"type"] - }]]; + encodeMethodCall:[FlutterMethodCall + methodCallWithMethodName:@"onAdEvent" + arguments:@{ + @"adId" : @1, + @"eventName" : + @"onRewardedInterstitialAdUserEarnedReward", + @"rewardItem" : + [[FLTRewardItem alloc] initWithAmount:@(1) + type:@"type"] + }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); } - (void)testAdInstanceManagerOnPaidEvent { - FLTNativeAd *ad = [[FLTNativeAd alloc] - initWithAdUnitId:@"testAdUnitId" - request:[[FLTAdRequest alloc] init] - nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) - customOptions:nil - rootViewController:OCMClassMock([UIViewController class]) - adId:@1 - nativeAdOptions:nil - nativeTemplateStyle:nil]; + FLTNativeAd *ad = + [[FLTNativeAd alloc] initWithAdUnitId:@"testAdUnitId" + request:[[FLTAdRequest alloc] init] + nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) + customOptions:nil + rootViewController:OCMClassMock([UIViewController class]) + adId:@1 + nativeAdOptions:nil + nativeTemplateStyle:nil]; [_manager loadAd:ad]; NSDecimalNumber *valueDecimal = [[NSDecimalNumber alloc] initWithInt:1]; @@ -326,8 +306,7 @@ - (void)testAdInstanceManagerOnPaidEvent { @"adId" : @1, @"eventName" : @"onPaidEvent", @"valueMicros" : value.valueMicros, - @"precision" : - [NSNumber numberWithInteger:12], + @"precision" : [NSNumber numberWithInteger:12], @"currencyCode" : @"code" }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); @@ -335,12 +314,11 @@ - (void)testAdInstanceManagerOnPaidEvent { - (void)testBannerEvents { FLTAdSize *size = [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)]; - FLTBannerAd *ad = [[FLTBannerAd alloc] - initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@1]; + FLTBannerAd *ad = [[FLTBannerAd alloc] initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@1]; FLTBannerAd *mockBannerAd = OCMPartialMock(ad); OCMStub([mockBannerAd load]); @@ -351,86 +329,73 @@ - (void)testBannerEvents { OCMVerify(([_mockMessenger sendOnChannel:channel message:impressionData])); [_manager onBannerWillDismissScreen:ad]; - NSData *willDismissData = [self getDataForEvent:@"onBannerWillDismissScreen" - adId:@1]; + NSData *willDismissData = [self getDataForEvent:@"onBannerWillDismissScreen" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:willDismissData])); [_manager onBannerDidDismissScreen:ad]; - NSData *didDismissData = [self getDataForEvent:@"onBannerDidDismissScreen" - adId:@1]; + NSData *didDismissData = [self getDataForEvent:@"onBannerDidDismissScreen" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didDismissData])); [_manager onBannerWillPresentScreen:ad]; - NSData *willPresentData = [self getDataForEvent:@"onBannerWillPresentScreen" - adId:@1]; + NSData *willPresentData = [self getDataForEvent:@"onBannerWillPresentScreen" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:willPresentData])); } - (void)testFullScreenEventsRewardedAd { - FLTRewardedAd *rewardedAd = [[FLTRewardedAd alloc] - initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + FLTRewardedAd *rewardedAd = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager loadAd:rewardedAd]; [_manager adWillPresentFullScreenContent:rewardedAd]; - NSData *didPresentData = - [self getDataForEvent:@"adWillPresentFullScreenContent" adId:@1]; + NSData *didPresentData = [self getDataForEvent:@"adWillPresentFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didPresentData])); [_manager adDidDismissFullScreenContent:rewardedAd]; - NSData *didDismissData = - [self getDataForEvent:@"adDidDismissFullScreenContent" adId:@1]; + NSData *didDismissData = [self getDataForEvent:@"adDidDismissFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didDismissData])); [_manager adWillDismissFullScreenContent:rewardedAd]; - NSData *willDismissData = - [self getDataForEvent:@"adWillDismissFullScreenContent" adId:@1]; + NSData *willDismissData = [self getDataForEvent:@"adWillDismissFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:willDismissData])); [_manager adDidRecordImpression:rewardedAd]; - NSData *impressionData = [self getDataForEvent:@"adDidRecordImpression" - adId:@1]; + NSData *impressionData = [self getDataForEvent:@"adDidRecordImpression" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:impressionData])); } - (void)testFullScreenEventsRewardedInterstitialAd { FLTRewardedInterstitialAd *rewardedInterstitialAd = - [[FLTRewardedInterstitialAd alloc] - initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager loadAd:rewardedInterstitialAd]; [_manager adWillPresentFullScreenContent:rewardedInterstitialAd]; - NSData *didPresentData = - [self getDataForEvent:@"adWillPresentFullScreenContent" adId:@1]; + NSData *didPresentData = [self getDataForEvent:@"adWillPresentFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didPresentData])); [_manager adDidDismissFullScreenContent:rewardedInterstitialAd]; - NSData *didDismissData = - [self getDataForEvent:@"adDidDismissFullScreenContent" adId:@1]; + NSData *didDismissData = [self getDataForEvent:@"adDidDismissFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didDismissData])); [_manager adWillDismissFullScreenContent:rewardedInterstitialAd]; - NSData *willDismissData = - [self getDataForEvent:@"adWillDismissFullScreenContent" adId:@1]; + NSData *willDismissData = [self getDataForEvent:@"adWillDismissFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:willDismissData])); [_manager adDidRecordImpression:rewardedInterstitialAd]; - NSData *impressionData = [self getDataForEvent:@"adDidRecordImpression" - adId:@1]; + NSData *impressionData = [self getDataForEvent:@"adDidRecordImpression" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:impressionData])); } - (void)testEventSentForDisposedAd { FLTAdSize *size = [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)]; - FLTBannerAd *bannerAd = [[FLTBannerAd alloc] - initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@1]; + FLTBannerAd *bannerAd = + [[FLTBannerAd alloc] initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@1]; FLTBannerAd *mockBannerAd = OCMPartialMock(bannerAd); OCMStub([mockBannerAd load]); @@ -450,19 +415,16 @@ - (void)testEventSentForDisposedAd { // Helper method to create encoded data for an event and ad id. - (NSData *)getDataForEvent:(NSString *)name adId:(NSNumber *)adId { return [_methodCodec - encodeMethodCall:[FlutterMethodCall methodCallWithMethodName:@"onAdEvent" - arguments:@{ - @"adId" : @1, - @"eventName" : name - }]]; + encodeMethodCall:[FlutterMethodCall + methodCallWithMethodName:@"onAdEvent" + arguments:@{@"adId" : @1, @"eventName" : name}]]; } - (void)testAdClick { FLTRewardedInterstitialAd *rewardedInterstitialAd = - [[FLTRewardedInterstitialAd alloc] - initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager adDidRecordClick:rewardedInterstitialAd]; NSData *impressionData = [self getDataForEvent:@"adDidRecordClick" adId:@1]; diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m index 02819d7f3..6b4bf4654 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m @@ -35,12 +35,10 @@ - (void)testLoadShowInterstitialAd { GADRequest *gadRequest = OCMClassMock([GADRequest class]); OCMStub([request asGADRequest:[OCMArg any]]).andReturn(gadRequest); - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); - FLTInterstitialAd *ad = - [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); + FLTInterstitialAd *ad = [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id interstitialClassMock = OCMClassMock([GADInterstitialAd class]); @@ -63,8 +61,7 @@ - (void)testLoadShowInterstitialAd { [delegate adDidDismissFullScreenContent:interstitialClassMock]; [delegate adWillPresentFullScreenContent:interstitialClassMock]; [delegate adWillDismissFullScreenContent:interstitialClassMock]; - [delegate ad:interstitialClassMock - didFailToPresentFullScreenContentWithError:error]; + [delegate ad:interstitialClassMock didFailToPresentFullScreenContentWithError:error]; }); GADResponseInfo *mockResponseInfo = OCMClassMock([GADResponseInfo class]); @@ -75,35 +72,31 @@ - (void)testLoadShowInterstitialAd { OCMStub([adValue value]).andReturn(NSDecimalNumber.one); OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated); OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); - OCMStub([interstitialClassMock - setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - GADPaidEventHandler handler = obj; - handler(adValue); - return YES; - }]]); + OCMStub([interstitialClassMock setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + GADPaidEventHandler handler = obj; + handler(adValue); + return YES; + }]]); // Call load and verify interactions with mocks. [ad load]; - OCMVerify(ClassMethod([interstitialClassMock - loadWithAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadRequest] - completionHandler:[OCMArg any]])); + OCMVerify(ClassMethod([interstitialClassMock loadWithAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadRequest] + completionHandler:[OCMArg any]])); OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad] responseInfo:[OCMArg isEqual:mockResponseInfo]]); - OCMVerify( - [interstitialClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); + OCMVerify([interstitialClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); XCTAssertEqual(ad.interstitial, interstitialClassMock); - OCMVerify([mockManager - onPaidEvent:[OCMArg isEqual:ad] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); // Show the ad [ad showFromRootViewController:mockRootViewController]; @@ -117,9 +110,8 @@ - (void)testLoadShowInterstitialAd { OCMVerify([mockManager adWillDismissFullScreenContent:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordImpression:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:ad]]); - OCMVerify([mockManager - didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); } - (void)testFailedToLoad { @@ -128,10 +120,9 @@ - (void)testFailedToLoad { GADRequest *gadRequest = OCMClassMock([GADRequest class]); OCMStub([request asGADRequest:[OCMArg any]]).andReturn(gadRequest); - FLTInterstitialAd *ad = - [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + FLTInterstitialAd *ad = [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id interstitialClassMock = OCMClassMock([GADInterstitialAd class]); @@ -147,12 +138,10 @@ - (void)testFailedToLoad { [ad load]; - OCMVerify(ClassMethod([interstitialClassMock - loadWithAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadRequest] - completionHandler:[OCMArg any]])); - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify(ClassMethod([interstitialClassMock loadWithAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadRequest] + completionHandler:[OCMArg any]])); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTNativeAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTNativeAdTest.m index 4c3b8cb29..b9b4371c0 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTNativeAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTNativeAdTest.m @@ -39,18 +39,14 @@ - (void)testLoadNativeAd { - (void)testLoadNativeAdWithGAMRequest { FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init]; request.keywords = @[ @"apple" ]; - [self testLoadNativeAd:request - customOptions:OCMClassMock([NSDictionary class])]; + [self testLoadNativeAd:request customOptions:OCMClassMock([NSDictionary class])]; } - (void)testLoadNativeAd:(FLTAdRequest *)gadOrGAMRequest - customOptions: - (NSDictionary *_Nullable)customOptions { + customOptions:(NSDictionary *_Nullable)customOptions { id mockNativeAdFactory = OCMProtocolMock(@protocol(FLTNativeAdFactory)); - FLTNativeAdOptions *mockNativeAdOptions = - OCMClassMock([FLTNativeAdOptions class]); - GADAdLoaderOptions *mockGADAdLoaderOptions = - OCMClassMock([GADAdLoaderOptions class]); + FLTNativeAdOptions *mockNativeAdOptions = OCMClassMock([FLTNativeAdOptions class]); + GADAdLoaderOptions *mockGADAdLoaderOptions = OCMClassMock([GADAdLoaderOptions class]); OCMStub([mockNativeAdOptions asGADAdLoaderOptions]) .andReturn([NSArray arrayWithObject:mockGADAdLoaderOptions]); UIViewController *mockViewController = OCMClassMock([UIViewController class]); @@ -76,8 +72,7 @@ - (void)testLoadNativeAd:(FLTAdRequest *)gadOrGAMRequest OCMVerify([mockLoader loadRequest:[OCMArg checkWithBlock:^BOOL(id obj) { GADRequest *requestArg = obj; - return [requestArg.keywords - isEqualToArray:@[ @"apple" ]]; + return [requestArg.keywords isEqualToArray:@[ @"apple" ]]; }]]); // Check that nil is used instead of null when customOptions is Null @@ -86,41 +81,36 @@ - (void)testLoadNativeAd:(FLTAdRequest *)gadOrGAMRequest OCMStub([mockGADNativeAd responseInfo]).andReturn(mockResponseInfo); [ad adLoader:mockLoader didReceiveNativeAd:mockGADNativeAd]; if ([NSNull.null isEqual:customOptions] || customOptions == nil) { - OCMVerify([mockNativeAdFactory createNativeAd:mockGADNativeAd - customOptions:[OCMArg isNil]]); + OCMVerify([mockNativeAdFactory createNativeAd:mockGADNativeAd customOptions:[OCMArg isNil]]); } else { - OCMVerify([mockNativeAdFactory - createNativeAd:mockGADNativeAd - customOptions:[OCMArg isEqual:customOptions]]); + OCMVerify([mockNativeAdFactory createNativeAd:mockGADNativeAd + customOptions:[OCMArg isEqual:customOptions]]); } - OCMStub( - [mockGADNativeAd setDelegate:[OCMArg checkWithBlock:^BOOL(id obj) { - id delegate = obj; - [delegate nativeAdDidRecordClick:mockGADNativeAd]; - [delegate nativeAdDidRecordImpression:mockGADNativeAd]; - [delegate nativeAdWillPresentScreen:mockGADNativeAd]; - [delegate nativeAdDidDismissScreen:mockGADNativeAd]; - [delegate nativeAdWillDismissScreen:mockGADNativeAd]; - return YES; - }]]); + OCMStub([mockGADNativeAd setDelegate:[OCMArg checkWithBlock:^BOOL(id obj) { + id delegate = obj; + [delegate nativeAdDidRecordClick:mockGADNativeAd]; + [delegate nativeAdDidRecordImpression:mockGADNativeAd]; + [delegate nativeAdWillPresentScreen:mockGADNativeAd]; + [delegate nativeAdDidDismissScreen:mockGADNativeAd]; + [delegate nativeAdWillDismissScreen:mockGADNativeAd]; + return YES; + }]]); // Mock callback of paid event handler. GADAdValue *adValue = OCMClassMock([GADAdValue class]); OCMStub([adValue value]).andReturn(NSDecimalNumber.one); OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated); OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); - OCMStub([mockGADNativeAd - setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - GADPaidEventHandler handler = obj; - handler(adValue); - return YES; - }]]); + OCMStub([mockGADNativeAd setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + GADPaidEventHandler handler = obj; + handler(adValue); + return YES; + }]]); // Check ad loader delegate methods forward to ad instance manager. - [(id)ad.adLoader.delegate - adLoader:mockLoader - didReceiveNativeAd:mockGADNativeAd]; + [(id)ad.adLoader.delegate adLoader:mockLoader + didReceiveNativeAd:mockGADNativeAd]; OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad] responseInfo:[OCMArg isEqual:mockResponseInfo]]); @@ -128,8 +118,7 @@ - (void)testLoadNativeAd:(FLTAdRequest *)gadOrGAMRequest NSError *error = OCMClassMock([NSError class]); [(id)ad.adLoader.delegate adLoader:mockLoader didFailToReceiveAdWithError:error]; - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]); OCMVerify([mockGADNativeAd setPaidEventHandler:[OCMArg any]]); @@ -140,35 +129,30 @@ - (void)testLoadNativeAd:(FLTAdRequest *)gadOrGAMRequest OCMVerify([mockManager onNativeAdWillPresentScreen:[OCMArg isEqual:ad]]); OCMVerify([mockManager onNativeAdDidDismissScreen:[OCMArg isEqual:ad]]); OCMVerify([mockManager onNativeAdWillDismissScreen:[OCMArg isEqual:ad]]); - OCMVerify([mockManager - onPaidEvent:[OCMArg isEqual:ad] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); } // Check that native templates are used when template style is provided. - (void)testLoadNativeAdNativeTemplateStyle { FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init]; id mockNativeAdFactory = OCMProtocolMock(@protocol(FLTNativeAdFactory)); - FLTNativeAdOptions *mockNativeAdOptions = - OCMClassMock([FLTNativeAdOptions class]); - GADAdLoaderOptions *mockGADAdLoaderOptions = - OCMClassMock([GADAdLoaderOptions class]); + FLTNativeAdOptions *mockNativeAdOptions = OCMClassMock([FLTNativeAdOptions class]); + GADAdLoaderOptions *mockGADAdLoaderOptions = OCMClassMock([GADAdLoaderOptions class]); OCMStub([mockNativeAdOptions asGADAdLoaderOptions]) .andReturn([NSArray arrayWithObject:mockGADAdLoaderOptions]); UIViewController *mockViewController = OCMClassMock([UIViewController class]); - FLTNativeTemplateStyle *templateStyle = - OCMClassMock([FLTNativeTemplateStyle class]); + FLTNativeTemplateStyle *templateStyle = OCMClassMock([FLTNativeTemplateStyle class]); UIView *mockTemplateView = OCMClassMock([UIView class]); - OCMStub([templateStyle getDisplayedView:[OCMArg any]]) - .andReturn(mockTemplateView); + OCMStub([templateStyle getDisplayedView:[OCMArg any]]).andReturn(mockTemplateView); FLTNativeAd *ad = [[FLTNativeAd alloc] initWithAdUnitId:@"testAdUnitId" request:request diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m index a64936b57..d7c36cfc4 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m @@ -50,12 +50,8 @@ - (void)testLoadShowRewardedAdGAMRequest { // Helper method for testing with FLTAdRequest and FLTGAMAdRequest. - (void)testLoadShowRewardedAd:(FLTAdRequest *)request gadOrGAMRequest:(GADRequest *)gadOrGAMRequest { - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); - FLTRewardedAd *ad = - [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); + FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" request:request adId:@1]; ad.manager = mockManager; // Stub the load call to invoke successful load callback. @@ -96,12 +92,11 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request OCMStub([adValue value]).andReturn(NSDecimalNumber.one); OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated); OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); - OCMStub([rewardedClassMock - setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - GADPaidEventHandler handler = obj; - handler(adValue); - return YES; - }]]); + OCMStub([rewardedClassMock setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + GADPaidEventHandler handler = obj; + handler(adValue); + return YES; + }]]); // Setup mock for UIApplication.sharedInstance id uiApplicationClassMock = OCMClassMock([UIApplication class]); @@ -111,46 +106,40 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request // Call load and check expected interactions with mocks. [ad load]; - OCMVerify(ClassMethod([rewardedClassMock - loadWithAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadOrGAMRequest] - completionHandler:[OCMArg any]])); + OCMVerify(ClassMethod([rewardedClassMock loadWithAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadOrGAMRequest] + completionHandler:[OCMArg any]])); OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad] responseInfo:[OCMArg isEqual:responseInfo]]); - OCMVerify( - [rewardedClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); + OCMVerify([rewardedClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); XCTAssertEqual(ad.rewardedAd, rewardedClassMock); - OCMVerify([mockManager - onPaidEvent:[OCMArg isEqual:ad] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); // Set SSV and verify interactions with mocks FLTServerSideVerificationOptions *serverSideVerificationOptions = OCMClassMock([FLTServerSideVerificationOptions class]); GADServerSideVerificationOptions *gadOptions = OCMClassMock([GADServerSideVerificationOptions class]); - OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]) - .andReturn(gadOptions); + OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]).andReturn(gadOptions); [ad setServerSideVerificationOptions:serverSideVerificationOptions]; - OCMVerify([rewardedClassMock - setServerSideVerificationOptions:[OCMArg isEqual:gadOptions]]); + OCMVerify([rewardedClassMock setServerSideVerificationOptions:[OCMArg isEqual:gadOptions]]); // Show the ad and verify callbacks invoked [ad showFromRootViewController:mockRootViewController]; - OCMVerify([rewardedClassMock - presentFromRootViewController:[OCMArg isEqual:mockRootViewController] - userDidEarnRewardHandler:[OCMArg any]]); + OCMVerify([rewardedClassMock presentFromRootViewController:[OCMArg isEqual:mockRootViewController] + userDidEarnRewardHandler:[OCMArg any]]); [fullScreenContentDelegate adWillPresentFullScreenContent:rewardedClassMock]; OCMVerify([mockManager adWillPresentFullScreenContent:[OCMArg isEqual:ad]]); @@ -177,19 +166,17 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request #pragma clang diagnostic pop [ad ad:rewardedClassMock didFailToPresentFullScreenContentWithError:error]; - OCMVerify([mockManager - didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); // Verify reward callback. - OCMVerify([mockManager - onRewardedAdUserEarnedReward:[OCMArg isEqual:ad] - reward:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTRewardItem *reward = (FLTRewardItem *)obj; - XCTAssertEqual(reward.amount, @1.0); - XCTAssertEqual(reward.type, @"type"); - return true; - }]]); + OCMVerify([mockManager onRewardedAdUserEarnedReward:[OCMArg isEqual:ad] + reward:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTRewardItem *reward = (FLTRewardItem *)obj; + XCTAssertEqual(reward.amount, @1.0); + XCTAssertEqual(reward.type, @"type"); + return true; + }]]); // Explicitly stop mocking. There is an issue when running tests on Github // actions where the mock does not get deallocated properly, so without this @@ -215,10 +202,7 @@ - (void)testFailedToLoadGAMRequest { // Helper for testing failed to load. - (void)testFailedToLoad:(FLTAdRequest *)request { - FLTRewardedAd *ad = - [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" request:request adId:@1]; ad.manager = mockManager; id rewardedClassMock = OCMClassMock([GADRewardedAd class]); @@ -237,8 +221,7 @@ - (void)testFailedToLoad:(FLTAdRequest *)request { OCMVerify(ClassMethod([rewardedClassMock loadWithAdUnitID:[OCMArg any] request:[OCMArg any] completionHandler:[OCMArg any]])); - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m index 261a9e049..a732ef9b8 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m @@ -50,31 +50,25 @@ - (void)testLoadShowRewardedInterstitialAdGAMRequest { // Helper method for testing with FLTAdRequest and FLTGAMAdRequest. - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request gadOrGAMRequest:(GADRequest *)gadOrGAMRequest { - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); - FLTRewardedInterstitialAd *ad = - [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); + FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; // Stub the load call to invoke successful load callback. - id rewardedInterstitialClassMock = - OCMClassMock([GADRewardedInterstitialAd class]); - OCMStub(ClassMethod([rewardedInterstitialClassMock - loadWithAdUnitID:[OCMArg any] - request:[OCMArg any] - completionHandler:[OCMArg any]])) + id rewardedInterstitialClassMock = OCMClassMock([GADRewardedInterstitialAd class]); + OCMStub(ClassMethod([rewardedInterstitialClassMock loadWithAdUnitID:[OCMArg any] + request:[OCMArg any] + completionHandler:[OCMArg any]])) .andDo(^(NSInvocation *invocation) { - void (^completionHandler)(GADRewardedInterstitialAd *ad, - NSError *error); + void (^completionHandler)(GADRewardedInterstitialAd *ad, NSError *error); [invocation getArgument:&completionHandler atIndex:4]; completionHandler(rewardedInterstitialClassMock, nil); }); // Stub setting of FullScreenContentDelegate to invoke delegate callbacks. NSError *error = OCMClassMock([NSError class]); - OCMStub( - [rewardedInterstitialClassMock setFullScreenContentDelegate:[OCMArg any]]) + OCMStub([rewardedInterstitialClassMock setFullScreenContentDelegate:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { id delegate; [invocation getArgument:&delegate atIndex:2]; @@ -94,9 +88,8 @@ - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request OCMStub([mockReward amount]).andReturn(@1.0); OCMStub([mockReward type]).andReturn(@"type"); OCMStub([rewardedInterstitialClassMock adReward]).andReturn(mockReward); - OCMStub([rewardedInterstitialClassMock - presentFromRootViewController:[OCMArg any] - userDidEarnRewardHandler:[OCMArg any]]) + OCMStub([rewardedInterstitialClassMock presentFromRootViewController:[OCMArg any] + userDidEarnRewardHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { GADUserDidEarnRewardHandler rewardHandler; [invocation getArgument:&rewardHandler atIndex:3]; @@ -108,47 +101,43 @@ - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request OCMStub([adValue value]).andReturn(NSDecimalNumber.one); OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated); OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); - OCMStub([rewardedInterstitialClassMock - setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - GADPaidEventHandler handler = obj; - handler(adValue); - return YES; - }]]); + OCMStub([rewardedInterstitialClassMock setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + GADPaidEventHandler handler = obj; + handler(adValue); + return YES; + }]]); // Call load and check expected interactions with mocks. [ad load]; - OCMVerify(ClassMethod([rewardedInterstitialClassMock - loadWithAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadOrGAMRequest] - completionHandler:[OCMArg any]])); + OCMVerify( + ClassMethod([rewardedInterstitialClassMock loadWithAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadOrGAMRequest] + completionHandler:[OCMArg any]])); OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad] responseInfo:[OCMArg isEqual:responseInfo]]); - OCMVerify([rewardedInterstitialClassMock - setFullScreenContentDelegate:[OCMArg isEqual:ad]]); - OCMVerify([mockManager - onPaidEvent:[OCMArg isEqual:ad] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([rewardedInterstitialClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); + OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); // Set SSV and verify interactions with mocks FLTServerSideVerificationOptions *serverSideVerificationOptions = OCMClassMock([FLTServerSideVerificationOptions class]); GADServerSideVerificationOptions *gadOptions = OCMClassMock([GADServerSideVerificationOptions class]); - OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]) - .andReturn(gadOptions); + OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]).andReturn(gadOptions); [ad setServerSideVerificationOptions:serverSideVerificationOptions]; - OCMVerify([rewardedInterstitialClassMock - setServerSideVerificationOptions:[OCMArg isEqual:gadOptions]]); + OCMVerify( + [rewardedInterstitialClassMock setServerSideVerificationOptions:[OCMArg isEqual:gadOptions]]); // Show the ad and verify callbacks are invoked [ad showFromRootViewController:mockRootViewController]; @@ -163,17 +152,14 @@ - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request OCMVerify([mockManager adWillDismissFullScreenContent:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordImpression:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:ad]]); - OCMVerify([mockManager - didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); // Verify reward callback. OCMVerify([mockManager onRewardedInterstitialAdUserEarnedReward:[OCMArg isEqual:ad] - reward:[OCMArg checkWithBlock:^BOOL( - id obj) { - FLTRewardItem *reward = - (FLTRewardItem *)obj; + reward:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTRewardItem *reward = (FLTRewardItem *)obj; XCTAssertEqual(reward.amount, @1.0); XCTAssertEqual(reward.type, @"type"); return true; @@ -201,34 +187,28 @@ - (void)testFailedToLoadGAMRequest { // Helper for testing failed to load. - (void)testFailedToLoad:(FLTAdRequest *)request { - FLTRewardedInterstitialAd *ad = - [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; - id rewardedInterstitialClassMock = - OCMClassMock([GADRewardedInterstitialAd class]); + id rewardedInterstitialClassMock = OCMClassMock([GADRewardedInterstitialAd class]); NSError *error = OCMClassMock([NSError class]); - OCMStub(ClassMethod([rewardedInterstitialClassMock - loadWithAdUnitID:[OCMArg any] - request:[OCMArg any] - completionHandler:[OCMArg any]])) + OCMStub(ClassMethod([rewardedInterstitialClassMock loadWithAdUnitID:[OCMArg any] + request:[OCMArg any] + completionHandler:[OCMArg any]])) .andDo(^(NSInvocation *invocation) { - void (^completionHandler)(GADRewardedInterstitialAd *ad, - NSError *error); + void (^completionHandler)(GADRewardedInterstitialAd *ad, NSError *error); [invocation getArgument:&completionHandler atIndex:4]; completionHandler(nil, error); }); [ad load]; - OCMVerify(ClassMethod([rewardedInterstitialClassMock - loadWithAdUnitID:[OCMArg any] - request:[OCMArg any] - completionHandler:[OCMArg any]])); - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify(ClassMethod([rewardedInterstitialClassMock loadWithAdUnitID:[OCMArg any] + request:[OCMArg any] + completionHandler:[OCMArg any]])); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTUserMessagingPlatformManagerTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTUserMessagingPlatformManagerTest.m index d05146a23..45b551076 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTUserMessagingPlatformManagerTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTUserMessagingPlatformManagerTest.m @@ -37,11 +37,9 @@ @implementation FLTUserMessagingPlatformManagerTest { - (void)setUp { binaryMessenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger)); - umpManager = [[FLTUserMessagingPlatformManager alloc] - initWithBinaryMessenger:binaryMessenger]; + umpManager = [[FLTUserMessagingPlatformManager alloc] initWithBinaryMessenger:binaryMessenger]; id umpInfoClassMock = OCMClassMock([UMPConsentInformation class]); - OCMStub(ClassMethod([umpInfoClassMock sharedInstance])) - .andReturn(umpInfoClassMock); + OCMStub(ClassMethod([umpInfoClassMock sharedInstance])).andReturn(umpInfoClassMock); mockUmpConsentInformation = umpInfoClassMock; resultInvoked = false; @@ -54,8 +52,7 @@ - (void)setUp { - (void)testReset { FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"ConsentInformation#reset" - arguments:@{}]; + [FlutterMethodCall methodCallWithMethodName:@"ConsentInformation#reset" arguments:@{}]; [umpManager handleMethodCall:methodCall result:flutterResult]; @@ -65,26 +62,24 @@ - (void)testReset { } - (void)testGetConsentStatus { - FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"ConsentInformation#getConsentStatus" - arguments:@{}]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"ConsentInformation#getConsentStatus" + arguments:@{}]; - OCMStub([mockUmpConsentInformation consentStatus]) - .andReturn(UMPConsentStatusRequired); + OCMStub([mockUmpConsentInformation consentStatus]).andReturn(UMPConsentStatusRequired); [umpManager handleMethodCall:methodCall result:flutterResult]; XCTAssertTrue(resultInvoked); - NSNumber *expected = - [[NSNumber alloc] initWithInteger:UMPConsentStatusRequired]; + NSNumber *expected = [[NSNumber alloc] initWithInteger:UMPConsentStatusRequired]; XCTAssertEqual(returnedResult, expected); OCMVerify([mockUmpConsentInformation consentStatus]); } - (void)testCanRequestAds_yes { - FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"ConsentInformation#canRequestAds" - arguments:@{}]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"ConsentInformation#canRequestAds" + arguments:@{}]; OCMStub([mockUmpConsentInformation canRequestAds]).andReturn(YES); [umpManager handleMethodCall:methodCall result:flutterResult]; @@ -94,9 +89,9 @@ - (void)testCanRequestAds_yes { } - (void)testCanRequestAds_no { - FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"ConsentInformation#canRequestAds" - arguments:@{}]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"ConsentInformation#canRequestAds" + arguments:@{}]; OCMStub([mockUmpConsentInformation canRequestAds]).andReturn(NO); [umpManager handleMethodCall:methodCall result:flutterResult]; @@ -107,8 +102,7 @@ - (void)testCanRequestAds_no { - (void)testGetPrivacyOptionsRequirementStatus_notRequiredReturns0 { FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName: - @"ConsentInformation#getPrivacyOptionsRequirementStatus" + methodCallWithMethodName:@"ConsentInformation#getPrivacyOptionsRequirementStatus" arguments:@{}]; OCMStub([mockUmpConsentInformation privacyOptionsRequirementStatus]) .andReturn(UMPPrivacyOptionsRequirementStatusNotRequired); @@ -122,8 +116,7 @@ - (void)testGetPrivacyOptionsRequirementStatus_notRequiredReturns0 { - (void)testGetPrivacyOptionsRequirementStatus_requiredReturns1 { FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName: - @"ConsentInformation#getPrivacyOptionsRequirementStatus" + methodCallWithMethodName:@"ConsentInformation#getPrivacyOptionsRequirementStatus" arguments:@{}]; OCMStub([mockUmpConsentInformation privacyOptionsRequirementStatus]) .andReturn(UMPPrivacyOptionsRequirementStatusRequired); @@ -137,8 +130,7 @@ - (void)testGetPrivacyOptionsRequirementStatus_requiredReturns1 { - (void)testGetPrivacyOptionsRequirementStatus_unknownReturns2 { FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName: - @"ConsentInformation#getPrivacyOptionsRequirementStatus" + methodCallWithMethodName:@"ConsentInformation#getPrivacyOptionsRequirementStatus" arguments:@{}]; OCMStub([mockUmpConsentInformation privacyOptionsRequirementStatus]) .andReturn(UMPPrivacyOptionsRequirementStatusUnknown); @@ -153,13 +145,12 @@ - (void)testGetPrivacyOptionsRequirementStatus_unknownReturns2 { - (void)testRequestConsentInfoUpdate_success { UMPRequestParameters *params = OCMClassMock([UMPRequestParameters class]); - FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"ConsentInformation#requestConsentInfoUpdate" - arguments:@{@"params" : params}]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"ConsentInformation#requestConsentInfoUpdate" + arguments:@{@"params" : params}]; - OCMStub([mockUmpConsentInformation - requestConsentInfoUpdateWithParameters:[OCMArg isEqual:params] - completionHandler:[OCMArg any]]) + OCMStub([mockUmpConsentInformation requestConsentInfoUpdateWithParameters:[OCMArg isEqual:params] + completionHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(NSError *error); [invocation getArgument:&completionHandler atIndex:3]; @@ -170,22 +161,20 @@ - (void)testRequestConsentInfoUpdate_success { XCTAssertTrue(resultInvoked); XCTAssertNil(returnedResult); - OCMVerify([mockUmpConsentInformation - requestConsentInfoUpdateWithParameters:[OCMArg any] - completionHandler:[OCMArg any]]); + OCMVerify([mockUmpConsentInformation requestConsentInfoUpdateWithParameters:[OCMArg any] + completionHandler:[OCMArg any]]); } - (void)testRequestConsentInfoUpdate_error { UMPRequestParameters *params = OCMClassMock([UMPRequestParameters class]); - FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"ConsentInformation#requestConsentInfoUpdate" - arguments:@{@"params" : params}]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"ConsentInformation#requestConsentInfoUpdate" + arguments:@{@"params" : params}]; NSDictionary *userInfo = @{NSLocalizedDescriptionKey : @"description"}; NSError *error = [NSError errorWithDomain:@"domain" code:1 userInfo:userInfo]; - OCMStub([mockUmpConsentInformation - requestConsentInfoUpdateWithParameters:[OCMArg isEqual:params] - completionHandler:[OCMArg any]]) + OCMStub([mockUmpConsentInformation requestConsentInfoUpdateWithParameters:[OCMArg isEqual:params] + completionHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(NSError *error); [invocation getArgument:&completionHandler atIndex:3]; @@ -196,9 +185,8 @@ - (void)testRequestConsentInfoUpdate_error { XCTAssertTrue(resultInvoked); - OCMVerify([mockUmpConsentInformation - requestConsentInfoUpdateWithParameters:[OCMArg any] - completionHandler:[OCMArg any]]); + OCMVerify([mockUmpConsentInformation requestConsentInfoUpdateWithParameters:[OCMArg any] + completionHandler:[OCMArg any]]); FlutterError *resultError = (FlutterError *)returnedResult; XCTAssertEqualObjects(resultError.code, @"1"); XCTAssertEqualObjects(resultError.details, @"domain"); @@ -208,13 +196,11 @@ - (void)testRequestConsentInfoUpdate_error { - (void)testLoadAndShowConsentFormIfRequired_success { UMPRequestParameters *params = OCMClassMock([UMPRequestParameters class]); FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName: - @"UserMessagingPlatform#loadAndShowConsentFormIfRequired" + methodCallWithMethodName:@"UserMessagingPlatform#loadAndShowConsentFormIfRequired" arguments:@{@"params" : params}]; id mockUmpConsentForm = OCMClassMock([UMPConsentForm class]); - OCMStub([mockUmpConsentForm - loadAndPresentIfRequiredFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]) + OCMStub([mockUmpConsentForm loadAndPresentIfRequiredFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(NSError *loadError); [invocation getArgument:&completionHandler atIndex:3]; @@ -225,9 +211,8 @@ - (void)testLoadAndShowConsentFormIfRequired_success { XCTAssertTrue(resultInvoked); XCTAssertNil(returnedResult); - OCMVerify([mockUmpConsentForm - loadAndPresentIfRequiredFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]); + OCMVerify([mockUmpConsentForm loadAndPresentIfRequiredFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]); } - (void)testLoadAndShowConsentFormIfRequired_error { @@ -235,13 +220,11 @@ - (void)testLoadAndShowConsentFormIfRequired_error { NSError *error = [NSError errorWithDomain:@"domain" code:1 userInfo:userInfo]; UMPRequestParameters *params = OCMClassMock([UMPRequestParameters class]); FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName: - @"UserMessagingPlatform#loadAndShowConsentFormIfRequired" + methodCallWithMethodName:@"UserMessagingPlatform#loadAndShowConsentFormIfRequired" arguments:@{@"params" : params}]; id mockUmpConsentForm = OCMClassMock([UMPConsentForm class]); - OCMStub([mockUmpConsentForm - loadAndPresentIfRequiredFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]) + OCMStub([mockUmpConsentForm loadAndPresentIfRequiredFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(NSError *loadError); [invocation getArgument:&completionHandler atIndex:3]; @@ -255,15 +238,14 @@ - (void)testLoadAndShowConsentFormIfRequired_error { XCTAssertEqualObjects(resultError.code, @"1"); XCTAssertEqualObjects(resultError.details, @"domain"); XCTAssertEqualObjects(resultError.message, @"description"); - OCMVerify([mockUmpConsentForm - loadAndPresentIfRequiredFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]); + OCMVerify([mockUmpConsentForm loadAndPresentIfRequiredFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]); } - (void)testLoadConsentForm_successAndDispose { - FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"UserMessagingPlatform#loadConsentForm" - arguments:@{}]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"UserMessagingPlatform#loadConsentForm" + arguments:@{}]; id mockUmpConsentForm = OCMClassMock([UMPConsentForm class]); OCMStub([mockUmpConsentForm loadWithCompletionHandler:[OCMArg any]]) @@ -287,9 +269,9 @@ - (void)testLoadConsentForm_successAndDispose { } - (void)testLoadConsentForm_error { - FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"UserMessagingPlatform#loadConsentForm" - arguments:@{}]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"UserMessagingPlatform#loadConsentForm" + arguments:@{}]; NSDictionary *userInfo = @{NSLocalizedDescriptionKey : @"description"}; NSError *error = [NSError errorWithDomain:@"domain" code:1 userInfo:userInfo]; @@ -313,13 +295,12 @@ - (void)testLoadConsentForm_error { - (void)testShowPrivacyOptionsForm_success { UMPRequestParameters *params = OCMClassMock([UMPRequestParameters class]); - FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"UserMessagingPlatform#showPrivacyOptionsForm" - arguments:@{@"params" : params}]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"UserMessagingPlatform#showPrivacyOptionsForm" + arguments:@{@"params" : params}]; id mockUmpConsentForm = OCMClassMock([UMPConsentForm class]); - OCMStub([mockUmpConsentForm - presentPrivacyOptionsFormFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]) + OCMStub([mockUmpConsentForm presentPrivacyOptionsFormFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(NSError *loadError); [invocation getArgument:&completionHandler atIndex:3]; @@ -330,22 +311,20 @@ - (void)testShowPrivacyOptionsForm_success { XCTAssertTrue(resultInvoked); XCTAssertNil(returnedResult); - OCMVerify([mockUmpConsentForm - presentPrivacyOptionsFormFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]); + OCMVerify([mockUmpConsentForm presentPrivacyOptionsFormFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]); } - (void)testShowPrivacyOptionsForm_error { NSDictionary *userInfo = @{NSLocalizedDescriptionKey : @"description"}; NSError *error = [NSError errorWithDomain:@"domain" code:1 userInfo:userInfo]; UMPRequestParameters *params = OCMClassMock([UMPRequestParameters class]); - FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"UserMessagingPlatform#showPrivacyOptionsForm" - arguments:@{@"params" : params}]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"UserMessagingPlatform#showPrivacyOptionsForm" + arguments:@{@"params" : params}]; id mockUmpConsentForm = OCMClassMock([UMPConsentForm class]); - OCMStub([mockUmpConsentForm - presentPrivacyOptionsFormFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]) + OCMStub([mockUmpConsentForm presentPrivacyOptionsFormFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(NSError *loadError); [invocation getArgument:&completionHandler atIndex:3]; @@ -359,18 +338,16 @@ - (void)testShowPrivacyOptionsForm_error { XCTAssertEqualObjects(resultError.code, @"1"); XCTAssertEqualObjects(resultError.details, @"domain"); XCTAssertEqualObjects(resultError.message, @"description"); - OCMVerify([mockUmpConsentForm - presentPrivacyOptionsFormFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]); + OCMVerify([mockUmpConsentForm presentPrivacyOptionsFormFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]); } - (void)testIsConsentFormAvailable_available { - FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"ConsentInformation#isConsentFormAvailable" - arguments:@{}]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"ConsentInformation#isConsentFormAvailable" + arguments:@{}]; - OCMStub([mockUmpConsentInformation formStatus]) - .andReturn(UMPFormStatusAvailable); + OCMStub([mockUmpConsentInformation formStatus]).andReturn(UMPFormStatusAvailable); [umpManager handleMethodCall:methodCall result:flutterResult]; @@ -379,12 +356,11 @@ - (void)testIsConsentFormAvailable_available { } - (void)testIsConsentFormAvailable_notAvailable { - FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"ConsentInformation#isConsentFormAvailable" - arguments:@{}]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"ConsentInformation#isConsentFormAvailable" + arguments:@{}]; - OCMStub([mockUmpConsentInformation formStatus]) - .andReturn(UMPFormStatusUnavailable); + OCMStub([mockUmpConsentInformation formStatus]).andReturn(UMPFormStatusUnavailable); [umpManager handleMethodCall:methodCall result:flutterResult]; @@ -402,8 +378,7 @@ - (void)testShowConsentForm_success { [FlutterMethodCall methodCallWithMethodName:@"ConsentForm#show" arguments:@{@"consentForm" : mockForm}]; - OCMStub([mockForm presentFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]) + OCMStub([mockForm presentFromViewController:[OCMArg any] completionHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(NSError *error); [invocation getArgument:&completionHandler atIndex:3]; @@ -415,8 +390,7 @@ - (void)testShowConsentForm_success { XCTAssertTrue(resultInvoked); XCTAssertNil(returnedResult); - OCMVerify([mockForm presentFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]); + OCMVerify([mockForm presentFromViewController:[OCMArg any] completionHandler:[OCMArg any]]); } - (void)testShowConsentForm_error { @@ -431,8 +405,7 @@ - (void)testShowConsentForm_error { NSDictionary *userInfo = @{NSLocalizedDescriptionKey : @"description"}; NSError *error = [NSError errorWithDomain:@"domain" code:1 userInfo:userInfo]; - OCMStub([mockForm presentFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]) + OCMStub([mockForm presentFromViewController:[OCMArg any] completionHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(NSError *error); [invocation getArgument:&completionHandler atIndex:3]; @@ -443,8 +416,7 @@ - (void)testShowConsentForm_error { [partialMock handleMethodCall:methodCall result:flutterResult]; XCTAssertTrue(resultInvoked); - OCMVerify([mockForm presentFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]); + OCMVerify([mockForm presentFromViewController:[OCMArg any] completionHandler:[OCMArg any]]); FlutterError *resultError = (FlutterError *)returnedResult; XCTAssertEqualObjects(resultError.code, @"1"); XCTAssertEqualObjects(resultError.details, @"domain"); diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTUserMessagingPlatformReaderWriterTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTUserMessagingPlatformReaderWriterTest.m index 721acf207..660dfe8de 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTUserMessagingPlatformReaderWriterTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTUserMessagingPlatformReaderWriterTest.m @@ -28,8 +28,7 @@ @implementation FLTUserMessagingPlatformReaderWriterTest { - (void)setUp { readerWriter = [[FLTUserMessagingPlatformReaderWriter alloc] init]; - messageCodec = - [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; + messageCodec = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; } - (void)testRequestParams_default { @@ -37,8 +36,7 @@ - (void)testRequestParams_default { NSData *encodedMessage = [messageCodec encode:requestParameters]; UMPRequestParameters *decoded = [messageCodec decode:encodedMessage]; - XCTAssertEqual(decoded.tagForUnderAgeOfConsent, - requestParameters.tagForUnderAgeOfConsent); + XCTAssertEqual(decoded.tagForUnderAgeOfConsent, requestParameters.tagForUnderAgeOfConsent); XCTAssertEqual(decoded.debugSettings, requestParameters.debugSettings); } @@ -49,10 +47,8 @@ - (void)testRequestParams_withDebugSettingsTfuac { NSData *encodedMessage = [messageCodec encode:requestParameters]; UMPRequestParameters *decoded = [messageCodec decode:encodedMessage]; - XCTAssertEqual(decoded.tagForUnderAgeOfConsent, - requestParameters.tagForUnderAgeOfConsent); - XCTAssertEqual(decoded.debugSettings.geography, - requestParameters.debugSettings.geography); + XCTAssertEqual(decoded.tagForUnderAgeOfConsent, requestParameters.tagForUnderAgeOfConsent); + XCTAssertEqual(decoded.debugSettings.geography, requestParameters.debugSettings.geography); XCTAssertEqual(decoded.debugSettings.testDeviceIdentifiers, requestParameters.debugSettings.testDeviceIdentifiers); } @@ -63,8 +59,7 @@ - (void)testConsentDebugSettings_default { UMPDebugSettings *decoded = [messageCodec decode:encodedMessage]; XCTAssertEqual(decoded.geography, debugSettings.geography); - XCTAssertEqual(decoded.testDeviceIdentifiers, - debugSettings.testDeviceIdentifiers); + XCTAssertEqual(decoded.testDeviceIdentifiers, debugSettings.testDeviceIdentifiers); } - (void)testConsentDebugSettings_geographyTestDeviceIdentifiers { @@ -75,8 +70,7 @@ - (void)testConsentDebugSettings_geographyTestDeviceIdentifiers { UMPDebugSettings *decoded = [messageCodec decode:encodedMessage]; XCTAssertEqual(decoded.geography, debugSettings.geography); - XCTAssertEqualObjects(decoded.testDeviceIdentifiers, - debugSettings.testDeviceIdentifiers); + XCTAssertEqualObjects(decoded.testDeviceIdentifiers, debugSettings.testDeviceIdentifiers); } - (void)testConsentFormTrackAndDispose { diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateColorTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateColorTest.m index 24ad94e7d..1c9dbd9c4 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateColorTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateColorTest.m @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "FLTNativeTemplateColor.h" #import #import +#import "FLTNativeTemplateColor.h" @interface FLTNativeTemplateColorTest : XCTestCase @end @@ -22,11 +22,11 @@ @interface FLTNativeTemplateColorTest : XCTestCase @implementation FLTNativeTemplateColorTest - (void)testConvertToUiColor { - FLTNativeTemplateColor *color = [[FLTNativeTemplateColor alloc] - initWithAlpha:[[NSNumber alloc] initWithFloat:5.0f] - red:@10.0f - green:[[NSNumber alloc] initWithFloat:15.0f] - blue:[[NSNumber alloc] initWithFloat:20.0f]]; + FLTNativeTemplateColor *color = + [[FLTNativeTemplateColor alloc] initWithAlpha:[[NSNumber alloc] initWithFloat:5.0f] + red:@10.0f + green:[[NSNumber alloc] initWithFloat:15.0f] + blue:[[NSNumber alloc] initWithFloat:20.0f]]; CGFloat alpha; CGFloat red; CGFloat green; diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateFontStyleTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateFontStyleTest.m index 8657b4dee..92953ba0d 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateFontStyleTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateFontStyleTest.m @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "FLTNativeTemplateFontStyle.h" #import +#import "FLTNativeTemplateFontStyle.h" @interface FLTNativeTemplateFontStyleTest : XCTestCase @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateStyleTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateStyleTest.m index 208a21f37..6562e8dc5 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateStyleTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateStyleTest.m @@ -26,17 +26,15 @@ @interface FLTNativeTemplateStyleTest : XCTestCase @implementation FLTNativeTemplateStyleTest - (void)testInitNilParameters { - FLTNativeTemplateType *templateType = - [[FLTNativeTemplateType alloc] initWithInt:0]; - - FLTNativeTemplateStyle *style = - [[FLTNativeTemplateStyle alloc] initWithTemplateType:templateType - mainBackgroundColor:nil - callToActionStyle:nil - primaryTextStyle:nil - secondaryTextStyle:nil - tertiaryTextStyle:nil - cornerRadius:nil]; + FLTNativeTemplateType *templateType = [[FLTNativeTemplateType alloc] initWithInt:0]; + + FLTNativeTemplateStyle *style = [[FLTNativeTemplateStyle alloc] initWithTemplateType:templateType + mainBackgroundColor:nil + callToActionStyle:nil + primaryTextStyle:nil + secondaryTextStyle:nil + tertiaryTextStyle:nil + cornerRadius:nil]; XCTAssertEqual(style.templateType, templateType); XCTAssertNil(style.mainBackgroundColor); XCTAssertNil(style.callToActionStyle); @@ -47,20 +45,14 @@ - (void)testInitNilParameters { } - (void)testInit { - FLTNativeTemplateType *templateType = - [[FLTNativeTemplateType alloc] initWithInt:0]; - FLTNativeTemplateColor *bgColor = - OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateType *templateType = [[FLTNativeTemplateType alloc] initWithInt:0]; + FLTNativeTemplateColor *bgColor = OCMClassMock([FLTNativeTemplateColor class]); UIColor *bgUIColor = OCMClassMock([UIColor class]); OCMStub([bgColor uiColor]).andReturn(bgUIColor); - FLTNativeTemplateTextStyle *ctaStyle = - OCMClassMock([FLTNativeTemplateTextStyle class]); - FLTNativeTemplateTextStyle *primaryStyle = - OCMClassMock([FLTNativeTemplateTextStyle class]); - FLTNativeTemplateTextStyle *secondaryStyle = - OCMClassMock([FLTNativeTemplateTextStyle class]); - FLTNativeTemplateTextStyle *tertiaryStyle = - OCMClassMock([FLTNativeTemplateTextStyle class]); + FLTNativeTemplateTextStyle *ctaStyle = OCMClassMock([FLTNativeTemplateTextStyle class]); + FLTNativeTemplateTextStyle *primaryStyle = OCMClassMock([FLTNativeTemplateTextStyle class]); + FLTNativeTemplateTextStyle *secondaryStyle = OCMClassMock([FLTNativeTemplateTextStyle class]); + FLTNativeTemplateTextStyle *tertiaryStyle = OCMClassMock([FLTNativeTemplateTextStyle class]); FLTNativeTemplateStyle *style = [[FLTNativeTemplateStyle alloc] initWithTemplateType:templateType @@ -81,28 +73,23 @@ - (void)testInit { } - (void)testGetDisplayedView { - FLTNativeTemplateType *templateType = - OCMClassMock([FLTNativeTemplateType class]); + FLTNativeTemplateType *templateType = OCMClassMock([FLTNativeTemplateType class]); GADTTemplateView *templateView = OCMClassMock([GADTTemplateView class]); OCMStub([templateType templateView]).andReturn(templateView); - FLTNativeTemplateColor *bgColor = - OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *bgColor = OCMClassMock([FLTNativeTemplateColor class]); UIColor *bgUIColor = OCMClassMock([UIColor class]); OCMStub([bgColor uiColor]).andReturn(bgUIColor); // Setup mocks for cta - FLTNativeTemplateTextStyle *ctaStyle = - OCMClassMock([FLTNativeTemplateTextStyle class]); + FLTNativeTemplateTextStyle *ctaStyle = OCMClassMock([FLTNativeTemplateTextStyle class]); UIColor *ctaBackgroundUIColor = OCMClassMock([UIColor class]); - FLTNativeTemplateColor *ctaBackgroundColor = - OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *ctaBackgroundColor = OCMClassMock([FLTNativeTemplateColor class]); OCMStub([ctaBackgroundColor uiColor]).andReturn(ctaBackgroundUIColor); OCMStub([ctaStyle backgroundColor]).andReturn(ctaBackgroundColor); UIColor *ctaTextUIColor = OCMClassMock([UIColor class]); - FLTNativeTemplateColor *ctaTextcolor = - OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *ctaTextcolor = OCMClassMock([FLTNativeTemplateColor class]); OCMStub([ctaTextcolor uiColor]).andReturn(ctaTextUIColor); OCMStub([ctaStyle textColor]).andReturn(ctaTextcolor); @@ -110,17 +97,14 @@ - (void)testGetDisplayedView { OCMStub([ctaStyle uiFont]).andReturn(ctaFont); // Setup mocks for primary - FLTNativeTemplateTextStyle *primaryStyle = - OCMClassMock([FLTNativeTemplateTextStyle class]); + FLTNativeTemplateTextStyle *primaryStyle = OCMClassMock([FLTNativeTemplateTextStyle class]); UIColor *primaryBackgroundUIColor = OCMClassMock([UIColor class]); - FLTNativeTemplateColor *primaryBackgroundColor = - OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *primaryBackgroundColor = OCMClassMock([FLTNativeTemplateColor class]); OCMStub([primaryBackgroundColor uiColor]).andReturn(primaryBackgroundUIColor); OCMStub([primaryStyle backgroundColor]).andReturn(primaryBackgroundColor); UIColor *primaryTextUIColor = OCMClassMock([UIColor class]); - FLTNativeTemplateColor *primaryTextcolor = - OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *primaryTextcolor = OCMClassMock([FLTNativeTemplateColor class]); OCMStub([primaryTextcolor uiColor]).andReturn(primaryTextUIColor); OCMStub([primaryStyle textColor]).andReturn(primaryTextcolor); @@ -128,18 +112,14 @@ - (void)testGetDisplayedView { OCMStub([primaryStyle uiFont]).andReturn(primaryFont); // Setup mocks for secondary - FLTNativeTemplateTextStyle *secondaryStyle = - OCMClassMock([FLTNativeTemplateTextStyle class]); + FLTNativeTemplateTextStyle *secondaryStyle = OCMClassMock([FLTNativeTemplateTextStyle class]); UIColor *secondaryBackgroundUIColor = OCMClassMock([UIColor class]); - FLTNativeTemplateColor *secondaryBackgroundColor = - OCMClassMock([FLTNativeTemplateColor class]); - OCMStub([secondaryBackgroundColor uiColor]) - .andReturn(secondaryBackgroundUIColor); + FLTNativeTemplateColor *secondaryBackgroundColor = OCMClassMock([FLTNativeTemplateColor class]); + OCMStub([secondaryBackgroundColor uiColor]).andReturn(secondaryBackgroundUIColor); OCMStub([secondaryStyle backgroundColor]).andReturn(secondaryBackgroundColor); UIColor *secondaryTextUIColor = OCMClassMock([UIColor class]); - FLTNativeTemplateColor *secondaryTextcolor = - OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *secondaryTextcolor = OCMClassMock([FLTNativeTemplateColor class]); OCMStub([secondaryTextcolor uiColor]).andReturn(secondaryTextUIColor); OCMStub([secondaryStyle textColor]).andReturn(secondaryTextcolor); @@ -147,18 +127,14 @@ - (void)testGetDisplayedView { OCMStub([secondaryStyle uiFont]).andReturn(secondaryFont); // Setup mocks for tertiary - FLTNativeTemplateTextStyle *tertiaryStyle = - OCMClassMock([FLTNativeTemplateTextStyle class]); + FLTNativeTemplateTextStyle *tertiaryStyle = OCMClassMock([FLTNativeTemplateTextStyle class]); UIColor *tertiaryBackgroundUIColor = OCMClassMock([UIColor class]); - FLTNativeTemplateColor *tertiaryBackgroundColor = - OCMClassMock([FLTNativeTemplateColor class]); - OCMStub([tertiaryBackgroundColor uiColor]) - .andReturn(tertiaryBackgroundUIColor); + FLTNativeTemplateColor *tertiaryBackgroundColor = OCMClassMock([FLTNativeTemplateColor class]); + OCMStub([tertiaryBackgroundColor uiColor]).andReturn(tertiaryBackgroundUIColor); OCMStub([tertiaryStyle backgroundColor]).andReturn(tertiaryBackgroundColor); UIColor *tertiaryTextUIColor = OCMClassMock([UIColor class]); - FLTNativeTemplateColor *tertiaryTextcolor = - OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *tertiaryTextcolor = OCMClassMock([FLTNativeTemplateColor class]); OCMStub([tertiaryTextcolor uiColor]).andReturn(tertiaryTextUIColor); OCMStub([tertiaryStyle textColor]).andReturn(tertiaryTextcolor); @@ -176,8 +152,7 @@ - (void)testGetDisplayedView { GADNativeAd *gadNativeAd = OCMClassMock([GADNativeAd class]); - FLTNativeTemplateViewWrapper *templateViewWrapper = - [style getDisplayedView:gadNativeAd]; + FLTNativeTemplateViewWrapper *templateViewWrapper = [style getDisplayedView:gadNativeAd]; XCTAssertEqual(templateViewWrapper.templateView, templateView); OCMVerify([templateView setNativeAd:[OCMArg isEqual:gadNativeAd]]); OCMVerify([templateView @@ -185,36 +160,25 @@ - (void)testGetDisplayedView { NSDictionary *styles = obj; XCTAssertEqual(styles[GADTNativeTemplateStyleKeyCornerRadius], @14.0f); - XCTAssertEqual( - styles[GADTNativeTemplateStyleKeyCallToActionBackgroundColor], - ctaBackgroundUIColor); - XCTAssertEqual(styles[GADTNativeTemplateStyleKeyCallToActionFontColor], - ctaTextUIColor); - XCTAssertEqual(styles[GADTNativeTemplateStyleKeyCallToActionFont], - ctaFont); + XCTAssertEqual(styles[GADTNativeTemplateStyleKeyCallToActionBackgroundColor], + ctaBackgroundUIColor); + XCTAssertEqual(styles[GADTNativeTemplateStyleKeyCallToActionFontColor], ctaTextUIColor); + XCTAssertEqual(styles[GADTNativeTemplateStyleKeyCallToActionFont], ctaFont); XCTAssertEqual(styles[GADTNativeTemplateStyleKeyPrimaryBackgroundColor], primaryBackgroundUIColor); - XCTAssertEqual(styles[GADTNativeTemplateStyleKeyPrimaryFontColor], - primaryTextUIColor); - XCTAssertEqual(styles[GADTNativeTemplateStyleKeyPrimaryFont], - primaryFont); - - XCTAssertEqual( - styles[GADTNativeTemplateStyleKeySecondaryBackgroundColor], - secondaryBackgroundUIColor); - XCTAssertEqual(styles[GADTNativeTemplateStyleKeySecondaryFontColor], - secondaryTextUIColor); - XCTAssertEqual(styles[GADTNativeTemplateStyleKeySecondaryFont], - secondaryFont); - - XCTAssertEqual( - styles[GADTNativeTemplateStyleKeyTertiaryBackgroundColor], - tertiaryBackgroundUIColor); - XCTAssertEqual(styles[GADTNativeTemplateStyleKeyTertiaryFontColor], - tertiaryTextUIColor); - XCTAssertEqual(styles[GADTNativeTemplateStyleKeyTertiaryFont], - tertiaryFont); + XCTAssertEqual(styles[GADTNativeTemplateStyleKeyPrimaryFontColor], primaryTextUIColor); + XCTAssertEqual(styles[GADTNativeTemplateStyleKeyPrimaryFont], primaryFont); + + XCTAssertEqual(styles[GADTNativeTemplateStyleKeySecondaryBackgroundColor], + secondaryBackgroundUIColor); + XCTAssertEqual(styles[GADTNativeTemplateStyleKeySecondaryFontColor], secondaryTextUIColor); + XCTAssertEqual(styles[GADTNativeTemplateStyleKeySecondaryFont], secondaryFont); + + XCTAssertEqual(styles[GADTNativeTemplateStyleKeyTertiaryBackgroundColor], + tertiaryBackgroundUIColor); + XCTAssertEqual(styles[GADTNativeTemplateStyleKeyTertiaryFontColor], tertiaryTextUIColor); + XCTAssertEqual(styles[GADTNativeTemplateStyleKeyTertiaryFont], tertiaryFont); return YES; }]]); } diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateTextStyleTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateTextStyleTest.m index 1aff4db1e..d887a6adc 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateTextStyleTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateTextStyleTest.m @@ -36,10 +36,8 @@ - (void)testInitWithNilParameters { } - (void)testInitWithDefinedParams { - FLTNativeTemplateColor *textColor = - OCMClassMock([FLTNativeTemplateColor class]); - FLTNativeTemplateColor *backgroundColor = - OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *textColor = OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *backgroundColor = OCMClassMock([FLTNativeTemplateColor class]); FLTNativeTemplateFontStyleWrapper *fontStyleWrapper = OCMClassMock([FLTNativeTemplateFontStyleWrapper class]); OCMStub([fontStyleWrapper fontStyle]).andReturn(FLTNativeTemplateFontBold); @@ -64,10 +62,8 @@ - (void)testInitWithDefinedParams { } - (void)testUiFontWithMissingSize { - FLTNativeTemplateColor *textColor = - OCMClassMock([FLTNativeTemplateColor class]); - FLTNativeTemplateColor *backgroundColor = - OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *textColor = OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *backgroundColor = OCMClassMock([FLTNativeTemplateColor class]); FLTNativeTemplateFontStyleWrapper *fontStyleWrapper = OCMClassMock([FLTNativeTemplateFontStyleWrapper class]); OCMStub([fontStyleWrapper fontStyle]).andReturn(FLTNativeTemplateFontItalic); @@ -92,10 +88,8 @@ - (void)testUiFontWithMissingSize { } - (void)testUiFontWithMissingFontStyle { - FLTNativeTemplateColor *textColor = - OCMClassMock([FLTNativeTemplateColor class]); - FLTNativeTemplateColor *backgroundColor = - OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *textColor = OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *backgroundColor = OCMClassMock([FLTNativeTemplateColor class]); NSNumber *size = [[NSNumber alloc] initWithFloat:14.0f]; FLTNativeTemplateTextStyle *textStyle = [[FLTNativeTemplateTextStyle alloc] initWithTextColor:textColor @@ -117,10 +111,8 @@ - (void)testUiFontWithMissingFontStyle { } - (void)testUiFontWithUnknownFontStyle { - FLTNativeTemplateColor *textColor = - OCMClassMock([FLTNativeTemplateColor class]); - FLTNativeTemplateColor *backgroundColor = - OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *textColor = OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *backgroundColor = OCMClassMock([FLTNativeTemplateColor class]); NSNumber *size = [[NSNumber alloc] initWithFloat:14.0f]; FLTNativeTemplateFontStyleWrapper *fontStyleWrapper = OCMClassMock([FLTNativeTemplateFontStyleWrapper class]); diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateTypeTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateTypeTest.m index 94b327717..935ea5265 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateTypeTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateTypeTest.m @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import "FLTNativeTemplateType.h" #import +#import "FLTNativeTemplateType.h" @interface FLTNativeTemplateTypeTest : XCTestCase @end @@ -21,21 +21,17 @@ @interface FLTNativeTemplateTypeTest : XCTestCase @implementation FLTNativeTemplateTypeTest - (void)testXibName { - FLTNativeTemplateType *templateTypeSmall = - [[FLTNativeTemplateType alloc] initWithInt:0]; + FLTNativeTemplateType *templateTypeSmall = [[FLTNativeTemplateType alloc] initWithInt:0]; XCTAssertEqualObjects(templateTypeSmall.xibName, @"GADTSmallTemplateView"); - FLTNativeTemplateType *templateTypeMedium = - [[FLTNativeTemplateType alloc] initWithInt:1]; + FLTNativeTemplateType *templateTypeMedium = [[FLTNativeTemplateType alloc] initWithInt:1]; XCTAssertEqualObjects(templateTypeMedium.xibName, @"GADTMediumTemplateView"); // Unknown templates default to medium - FLTNativeTemplateType *templateTypeUnknown = - [[FLTNativeTemplateType alloc] initWithInt:-1]; + FLTNativeTemplateType *templateTypeUnknown = [[FLTNativeTemplateType alloc] initWithInt:-1]; XCTAssertEqualObjects(templateTypeUnknown.xibName, @"GADTMediumTemplateView"); - FLTNativeTemplateType *templateType = - [[FLTNativeTemplateType alloc] initWithInt:2]; + FLTNativeTemplateType *templateType = [[FLTNativeTemplateType alloc] initWithInt:2]; XCTAssertEqualObjects(templateType.xibName, @"GADTMediumTemplateView"); } From 1c497e6086d5d20a4d0771584f2f585a62ca1469 Mon Sep 17 00:00:00 2001 From: Aldo Becerril Date: Fri, 9 Aug 2024 11:50:43 -0700 Subject: [PATCH 04/15] Revert "Format fix" This reverts commit 994dcc2ce46845fd85d3560b987e2fd70df810e9. --- .../example/ios/Runner/AppDelegate.m | 12 +- .../example/ios/Runner/main.m | 5 +- .../ios/RunnerTests/FLTAdRequestTest.m | 6 +- .../example/ios/RunnerTests/FLTAdUtilTest.m | 53 ++- .../ios/RunnerTests/FLTAppOpenAdTest.m | 73 ++-- .../example/ios/RunnerTests/FLTBannerAdTest.m | 56 +-- .../ios/RunnerTests/FLTFluidGAMBannerAdTest.m | 125 +++--- .../ios/RunnerTests/FLTGAMAdRequestTest.m | 6 +- .../ios/RunnerTests/FLTGAMBannerAdTest.m | 55 ++- .../RunnerTests/FLTGamInterstitialAdTest.m | 91 +++-- .../FLTGoogleMobileAdsPluginMethodCallsTest.m | 280 +++++++------ .../FLTGoogleMobileAdsReaderWriterTest.m | 368 ++++++++++++------ .../ios/RunnerTests/FLTGoogleMobileAdsTest.m | 336 +++++++++------- .../ios/RunnerTests/FLTInterstitialAdTest.m | 77 ++-- .../example/ios/RunnerTests/FLTNativeAdTest.m | 94 +++-- .../ios/RunnerTests/FLTRewardedAdTest.m | 89 +++-- .../FLTRewardedInterstitialAdTest.m | 122 +++--- .../FLTUserMessagingPlatformManagerTest.m | 174 +++++---- ...FLTUserMessagingPlatformReaderWriterTest.m | 18 +- .../FLTNativeTemplateColorTest.m | 12 +- .../FLTNativeTemplateFontStyleTest.m | 2 +- .../FLTNativeTemplateStyleTest.m | 132 ++++--- .../FLTNativeTemplateTextStyleTest.m | 24 +- .../FLTNativeTemplateTypeTest.m | 14 +- 24 files changed, 1329 insertions(+), 895 deletions(-) diff --git a/packages/google_mobile_ads/example/ios/Runner/AppDelegate.m b/packages/google_mobile_ads/example/ios/Runner/AppDelegate.m index 48fc1759c..ffbad4233 100644 --- a/packages/google_mobile_ads/example/ios/Runner/AppDelegate.m +++ b/packages/google_mobile_ads/example/ios/Runner/AppDelegate.m @@ -25,8 +25,10 @@ @implementation NativeAdFactoryExample - (GADNativeAdView *)createNativeAd:(GADNativeAd *)nativeAd customOptions:(NSDictionary *)customOptions { // Create and place ad in view hierarchy. - GADNativeAdView *adView = - [[NSBundle mainBundle] loadNibNamed:@"NativeAdView" owner:nil options:nil].firstObject; + GADNativeAdView *adView = [[NSBundle mainBundle] loadNibNamed:@"NativeAdView" + owner:nil + options:nil] + .firstObject; // Associate the native ad view with the native ad object. This is // required to make the ad clickable. @@ -70,11 +72,13 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [GeneratedPluginRegistrant registerWithRegistry:self]; - NativeAdFactoryExample *nativeAdFactory = [[NativeAdFactoryExample alloc] init]; + NativeAdFactoryExample *nativeAdFactory = + [[NativeAdFactoryExample alloc] init]; [FLTGoogleMobileAdsPlugin registerNativeAdFactory:self factoryId:@"adFactoryExample" nativeAdFactory:nativeAdFactory]; - return [super application:application didFinishLaunchingWithOptions:launchOptions]; + return [super application:application + didFinishLaunchingWithOptions:launchOptions]; } @end diff --git a/packages/google_mobile_ads/example/ios/Runner/main.m b/packages/google_mobile_ads/example/ios/Runner/main.m index 460e03555..80af04fa0 100644 --- a/packages/google_mobile_ads/example/ios/Runner/main.m +++ b/packages/google_mobile_ads/example/ios/Runner/main.m @@ -12,12 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +#import "AppDelegate.h" #import #import -#import "AppDelegate.h" int main(int argc, char *argv[]) { @autoreleasepool { - return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + return UIApplicationMain(argc, argv, nil, + NSStringFromClass([AppDelegate class])); } } diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAdRequestTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAdRequestTest.m index c5049a73f..89aa5c845 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAdRequestTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAdRequestTest.m @@ -66,7 +66,8 @@ - (void)testAsAdRequestAllParams { GADExtras *updatedExtras = [gadRequest adNetworkExtrasFor:[GADExtras class]]; XCTAssertEqualObjects(updatedExtras, extras); XCTAssertEqualObjects(updatedExtras.additionalParameters[@"npa"], @"1"); - OCMVerify([gadRequestSpy registerAdNetworkExtras:[OCMArg isEqual:testExtras]]); + OCMVerify( + [gadRequestSpy registerAdNetworkExtras:[OCMArg isEqual:testExtras]]); } - (void)testAsAdRequestNoParams { @@ -137,7 +138,8 @@ - (void)testGADExtrasWithoutNpa { GADRequest *gadRequest = [fltAdRequest asGADRequest:@"test-ad-unit"]; XCTAssertNil([gadRequest adNetworkExtrasFor:[GADExtras class]]); - OCMVerify([gadRequestSpy registerAdNetworkExtras:[OCMArg isEqual:testExtras]]); + OCMVerify( + [gadRequestSpy registerAdNetworkExtras:[OCMArg isEqual:testExtras]]); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAdUtilTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAdUtilTest.m index f8f2e4f8b..77d8122e0 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAdUtilTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAdUtilTest.m @@ -32,40 +32,65 @@ - (void)setUp { } - (void)testRequestAgent_noTemplateMetadata { - OCMStub([_mockMainBundle objectForInfoDictionaryKey:[OCMArg isEqual:@"FLTNewsTemplateVersion"]]) + OCMStub( + [_mockMainBundle + objectForInfoDictionaryKey:[OCMArg + isEqual:@"FLTNewsTemplateVersion"]]) .andReturn(nil); - OCMStub([_mockMainBundle objectForInfoDictionaryKey:[OCMArg isEqual:@"FLTGameTemplateVersion"]]) + OCMStub( + [_mockMainBundle + objectForInfoDictionaryKey:[OCMArg + isEqual:@"FLTGameTemplateVersion"]]) .andReturn(nil); XCTAssertEqualObjects([FLTAdUtil requestAgent], FLT_REQUEST_AGENT_VERSIONED); } - (void)testRequestAgent_newsTemplateMetadata { - OCMStub([_mockMainBundle objectForInfoDictionaryKey:[OCMArg isEqual:@"FLTNewsTemplateVersion"]]) + OCMStub( + [_mockMainBundle + objectForInfoDictionaryKey:[OCMArg + isEqual:@"FLTNewsTemplateVersion"]]) .andReturn(@"v1.2.3"); - OCMStub([_mockMainBundle objectForInfoDictionaryKey:[OCMArg isEqual:@"FLTGameTemplateVersion"]]) + OCMStub( + [_mockMainBundle + objectForInfoDictionaryKey:[OCMArg + isEqual:@"FLTGameTemplateVersion"]]) .andReturn(nil); - NSString *expected = - [NSString stringWithFormat:@"%@%@", FLT_REQUEST_AGENT_VERSIONED, @"_News-v1.2.3"]; + NSString *expected = [NSString + stringWithFormat:@"%@%@", FLT_REQUEST_AGENT_VERSIONED, @"_News-v1.2.3"]; XCTAssertEqualObjects([FLTAdUtil requestAgent], expected); } - (void)testRequestAgent_gameTemplateMetadata { - OCMStub([_mockMainBundle objectForInfoDictionaryKey:[OCMArg isEqual:@"FLTNewsTemplateVersion"]]) + OCMStub( + [_mockMainBundle + objectForInfoDictionaryKey:[OCMArg + isEqual:@"FLTNewsTemplateVersion"]]) .andReturn(nil); - OCMStub([_mockMainBundle objectForInfoDictionaryKey:[OCMArg isEqual:@"FLTGameTemplateVersion"]]) + OCMStub( + [_mockMainBundle + objectForInfoDictionaryKey:[OCMArg + isEqual:@"FLTGameTemplateVersion"]]) .andReturn(@"123456"); - NSString *expected = - [NSString stringWithFormat:@"%@%@", FLT_REQUEST_AGENT_VERSIONED, @"_Game-123456"]; + NSString *expected = [NSString + stringWithFormat:@"%@%@", FLT_REQUEST_AGENT_VERSIONED, @"_Game-123456"]; XCTAssertEqualObjects([FLTAdUtil requestAgent], expected); } - (void)testRequestAgent_gameAndNewsTemplateMetadata { - OCMStub([_mockMainBundle objectForInfoDictionaryKey:[OCMArg isEqual:@"FLTNewsTemplateVersion"]]) + OCMStub( + [_mockMainBundle + objectForInfoDictionaryKey:[OCMArg + isEqual:@"FLTNewsTemplateVersion"]]) .andReturn(@"123456"); - OCMStub([_mockMainBundle objectForInfoDictionaryKey:[OCMArg isEqual:@"FLTGameTemplateVersion"]]) + OCMStub( + [_mockMainBundle + objectForInfoDictionaryKey:[OCMArg + isEqual:@"FLTGameTemplateVersion"]]) .andReturn(@"789z"); - NSString *expected = [NSString - stringWithFormat:@"%@%@%@", FLT_REQUEST_AGENT_VERSIONED, @"_News-123456", @"_Game-789z"]; + NSString *expected = + [NSString stringWithFormat:@"%@%@%@", FLT_REQUEST_AGENT_VERSIONED, + @"_News-123456", @"_Game-789z"]; XCTAssertEqualObjects([FLTAdUtil requestAgent], expected); } diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m index 93286f3cb..dfc65a59d 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m @@ -47,7 +47,8 @@ - (void)testLoadShowGAMRequest { OCMClassMock([FLTServerSideVerificationOptions class]); GADServerSideVerificationOptions *gadOptions = OCMClassMock([GADServerSideVerificationOptions class]); - OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]).andReturn(gadOptions); + OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]) + .andReturn(gadOptions); [self testLoadShowAppOpenAd:request gadOrGAMRequest:gamRequest]; } @@ -55,8 +56,12 @@ - (void)testLoadShowGAMRequest { // Helper method for testing with FLTAdRequest and FLTGAMAdRequest. - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request gadOrGAMRequest:(GADRequest *)gadOrGAMRequest { - UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); - FLTAppOpenAd *ad = [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" request:request adId:@1]; + UIViewController *mockRootViewController = + OCMClassMock([UIViewController class]); + FLTAppOpenAd *ad = + [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; // Stub the load call to invoke successful load callback. @@ -81,7 +86,8 @@ - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request [delegate adDidDismissFullScreenContent:appOpenClassMock]; [delegate adWillPresentFullScreenContent:appOpenClassMock]; [delegate adWillDismissFullScreenContent:appOpenClassMock]; - [delegate ad:appOpenClassMock didFailToPresentFullScreenContentWithError:error]; + [delegate ad:appOpenClassMock + didFailToPresentFullScreenContentWithError:error]; }); GADResponseInfo *responseInfo = OCMClassMock([GADResponseInfo class]); OCMStub([appOpenClassMock responseInfo]).andReturn(responseInfo); @@ -91,36 +97,40 @@ - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request OCMStub([adValue value]).andReturn(NSDecimalNumber.one); OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated); OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); - OCMStub([appOpenClassMock setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - GADPaidEventHandler handler = obj; - handler(adValue); - return YES; - }]]); + OCMStub([appOpenClassMock + setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + GADPaidEventHandler handler = obj; + handler(adValue); + return YES; + }]]); // Call load and check expected interactions with mocks. [ad load]; - OCMVerify(ClassMethod([appOpenClassMock loadWithAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadOrGAMRequest] - completionHandler:[OCMArg any]])); + OCMVerify(ClassMethod([appOpenClassMock + loadWithAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadOrGAMRequest] + completionHandler:[OCMArg any]])); OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad] responseInfo:[OCMArg isEqual:responseInfo]]); - OCMVerify([appOpenClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); + OCMVerify( + [appOpenClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); XCTAssertEqual(ad.appOpenAd, appOpenClassMock); - OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager + onPaidEvent:[OCMArg isEqual:ad] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); [ad showFromRootViewController:mockRootViewController]; - OCMVerify( - [appOpenClassMock presentFromRootViewController:[OCMArg isEqual:mockRootViewController]]); + OCMVerify([appOpenClassMock + presentFromRootViewController:[OCMArg isEqual:mockRootViewController]]); // Verify full screen callbacks. OCMVerify([mockManager adWillPresentFullScreenContent:[OCMArg isEqual:ad]]); @@ -128,8 +138,9 @@ - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request OCMVerify([mockManager adWillDismissFullScreenContent:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordImpression:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:ad]]); - OCMVerify([mockManager didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager + didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); } - (void)testFailedToLoadGADRequest { @@ -150,7 +161,10 @@ - (void)testFailedToLoadGAMRequest { // Helper for testing failed to load. - (void)testFailedToLoad:(FLTAdRequest *)request { - FLTAppOpenAd *ad = [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" request:request adId:@1]; + FLTAppOpenAd *ad = + [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id appOpenClassMock = OCMClassMock([GADAppOpenAd class]); @@ -169,7 +183,8 @@ - (void)testFailedToLoad:(FLTAdRequest *)request { OCMVerify(ClassMethod([appOpenClassMock loadWithAdUnitID:[OCMArg any] request:[OCMArg any] completionHandler:[OCMArg any]])); - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTBannerAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTBannerAdTest.m index 8d9ef9216..278875cd7 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTBannerAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTBannerAdTest.m @@ -31,12 +31,14 @@ - (void)setUp { - (void)testDelegates { FLTAdSize *size = [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)]; - UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); - FLTBannerAd *bannerAd = [[FLTBannerAd alloc] initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:mockRootViewController - adId:@1]; + UIViewController *mockRootViewController = + OCMClassMock([UIViewController class]); + FLTBannerAd *bannerAd = + [[FLTBannerAd alloc] initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:mockRootViewController + adId:@1]; bannerAd.manager = mockManager; [bannerAd load]; @@ -73,35 +75,38 @@ - (void)testDelegates { OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); bannerAd.bannerView.paidEventHandler(adValue); - OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:bannerAd] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager + onPaidEvent:[OCMArg isEqual:bannerAd] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); NSString *domain = @"domain"; NSDictionary *userInfo = @{NSLocalizedDescriptionKey : @"description"}; NSError *error = [NSError errorWithDomain:domain code:1 userInfo:userInfo]; [bannerAd.bannerView.delegate bannerView:OCMClassMock([GADBannerView class]) didFailToReceiveAdWithError:error]; - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:bannerAd] error:[OCMArg isEqual:error]]); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:bannerAd] + error:[OCMArg isEqual:error]]); } - (void)testLoad { FLTAdRequest *request = [[FLTAdRequest alloc] init]; request.keywords = @[ @"apple" ]; - UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); - FLTBannerAd *ad = [[FLTBannerAd alloc] initWithAdUnitId:@"testId" - size:[[FLTAdSize alloc] initWithWidth:@(1) - height:@(2)] - request:request - rootViewController:mockRootViewController - adId:@1]; + UIViewController *mockRootViewController = + OCMClassMock([UIViewController class]); + FLTBannerAd *ad = [[FLTBannerAd alloc] + initWithAdUnitId:@"testId" + size:[[FLTAdSize alloc] initWithWidth:@(1) height:@(2)] + request:request + rootViewController:mockRootViewController + adId:@1]; XCTAssertEqual(ad.bannerView.adUnitID, @"testId"); XCTAssertEqual(ad.bannerView.rootViewController, mockRootViewController); @@ -113,7 +118,8 @@ - (void)testLoad { OCMVerify([mockView loadRequest:[OCMArg checkWithBlock:^BOOL(id obj) { GADRequest *requestArg = obj; - return [requestArg.keywords isEqualToArray:@[ @"apple" ]]; + return + [requestArg.keywords isEqualToArray:@[ @"apple" ]]; }]]); } diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTFluidGAMBannerAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTFluidGAMBannerAdTest.m index 8f1bc145b..5ca92fa9c 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTFluidGAMBannerAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTFluidGAMBannerAdTest.m @@ -32,12 +32,13 @@ - (void)setUp { - (void)testDelegates { FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init]; request.keywords = @[ @"apple" ]; - UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); - FLTFluidGAMBannerAd *fluidAd = - [[FLTFluidGAMBannerAd alloc] initWithAdUnitId:@"testId" - request:[[FLTGAMAdRequest alloc] init] - rootViewController:mockRootViewController - adId:@1]; + UIViewController *mockRootViewController = + OCMClassMock([UIViewController class]); + FLTFluidGAMBannerAd *fluidAd = [[FLTFluidGAMBannerAd alloc] + initWithAdUnitId:@"testId" + request:[[FLTGAMAdRequest alloc] init] + rootViewController:mockRootViewController + adId:@1]; fluidAd.manager = mockManager; [fluidAd load]; @@ -45,23 +46,29 @@ - (void)testDelegates { XCTAssertEqual(adView.appEventDelegate, fluidAd); XCTAssertEqual(adView.delegate, fluidAd); - [fluidAd.bannerView.delegate bannerViewDidReceiveAd:OCMClassMock([GADBannerView class])]; + [fluidAd.bannerView.delegate + bannerViewDidReceiveAd:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:fluidAd] responseInfo:[OCMArg isEqual:adView.responseInfo]]); - [fluidAd.bannerView.delegate bannerViewDidDismissScreen:OCMClassMock([GADBannerView class])]; + [fluidAd.bannerView.delegate + bannerViewDidDismissScreen:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager onBannerDidDismissScreen:[OCMArg isEqual:fluidAd]]); - [fluidAd.bannerView.delegate bannerViewWillDismissScreen:OCMClassMock([GADBannerView class])]; + [fluidAd.bannerView.delegate + bannerViewWillDismissScreen:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager onBannerWillDismissScreen:[OCMArg isEqual:fluidAd]]); - [fluidAd.bannerView.delegate bannerViewWillPresentScreen:OCMClassMock([GADBannerView class])]; + [fluidAd.bannerView.delegate + bannerViewWillPresentScreen:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager onBannerWillPresentScreen:[OCMArg isEqual:fluidAd]]); - [fluidAd.bannerView.delegate bannerViewDidRecordImpression:OCMClassMock([GADBannerView class])]; + [fluidAd.bannerView.delegate + bannerViewDidRecordImpression:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager onBannerImpression:[OCMArg isEqual:fluidAd]]); - [fluidAd.bannerView.delegate bannerViewDidRecordClick:OCMClassMock([GADBannerView class])]; + [fluidAd.bannerView.delegate + bannerViewDidRecordClick:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:fluidAd]]); // Mock callback of paid event handler. @@ -71,25 +78,29 @@ - (void)testDelegates { OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); fluidAd.bannerView.paidEventHandler(adValue); - OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:fluidAd] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager + onPaidEvent:[OCMArg isEqual:fluidAd] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); NSString *domain = @"domain"; NSDictionary *userInfo = @{NSLocalizedDescriptionKey : @"description"}; NSError *error = [NSError errorWithDomain:domain code:1 userInfo:userInfo]; [fluidAd.bannerView.delegate bannerView:OCMClassMock([GADBannerView class]) didFailToReceiveAdWithError:error]; - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:fluidAd] error:[OCMArg isEqual:error]]); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:fluidAd] + error:[OCMArg isEqual:error]]); - [adView.appEventDelegate adView:adView didReceiveAppEvent:@"appEvent" withInfo:@"info"]; + [adView.appEventDelegate adView:adView + didReceiveAppEvent:@"appEvent" + withInfo:@"info"]; OCMVerify([mockManager onAppEvent:[OCMArg isEqual:fluidAd] name:[OCMArg isEqual:@"appEvent"] data:[OCMArg isEqual:@"info"]]); @@ -99,34 +110,40 @@ - (void)testPlatformViewSetup { // Setup mocks FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init]; request.keywords = @[ @"apple" ]; - UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); + UIViewController *mockRootViewController = + OCMClassMock([UIViewController class]); id scrollViewClassMock = OCMClassMock([UIScrollView class]); OCMStub([scrollViewClassMock alloc]).andReturn(scrollViewClassMock); - OCMStub([scrollViewClassMock initWithFrame:CGRectZero]).andReturn(scrollViewClassMock); + OCMStub([scrollViewClassMock initWithFrame:CGRectZero]) + .andReturn(scrollViewClassMock); id gamBannerClassMock = OCMClassMock([GAMBannerView class]); OCMStub([gamBannerClassMock alloc]).andReturn(gamBannerClassMock); - OCMStub([gamBannerClassMock initWithAdSize:GADAdSizeFluid]).andReturn(gamBannerClassMock); + OCMStub([gamBannerClassMock initWithAdSize:GADAdSizeFluid]) + .andReturn(gamBannerClassMock); // Create and load an ad. - FLTFluidGAMBannerAd *fluidAd = - [[FLTFluidGAMBannerAd alloc] initWithAdUnitId:@"testId" - request:[[FLTGAMAdRequest alloc] init] - rootViewController:mockRootViewController - adId:@1]; + FLTFluidGAMBannerAd *fluidAd = [[FLTFluidGAMBannerAd alloc] + initWithAdUnitId:@"testId" + request:[[FLTGAMAdRequest alloc] init] + rootViewController:mockRootViewController + adId:@1]; fluidAd.manager = mockManager; // Mimic successful loading of an ad. [fluidAd load]; - [fluidAd.bannerView.delegate bannerViewDidReceiveAd:OCMClassMock([GADBannerView class])]; + [fluidAd.bannerView.delegate + bannerViewDidReceiveAd:OCMClassMock([GADBannerView class])]; // The banner view should be contained within a scrollview. XCTAssertEqualObjects(fluidAd.view, scrollViewClassMock); + OCMVerify([(UIScrollView *)scrollViewClassMock + addSubview:[OCMArg isKindOfClass:GAMBannerView.class]]); + OCMVerify([(UIScrollView *)scrollViewClassMock + setShowsHorizontalScrollIndicator:NO]); OCMVerify( - [(UIScrollView *)scrollViewClassMock addSubview:[OCMArg isKindOfClass:GAMBannerView.class]]); - OCMVerify([(UIScrollView *)scrollViewClassMock setShowsHorizontalScrollIndicator:NO]); - OCMVerify([(UIScrollView *)scrollViewClassMock setShowsVerticalScrollIndicator:NO]); + [(UIScrollView *)scrollViewClassMock setShowsVerticalScrollIndicator:NO]); [scrollViewClassMock stopMocking]; [gamBannerClassMock stopMocking]; @@ -136,33 +153,38 @@ - (void)testSizeChangedEvent { // Setup mocks FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init]; request.keywords = @[ @"apple" ]; - UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); + UIViewController *mockRootViewController = + OCMClassMock([UIViewController class]); // Create and load an ad. - FLTFluidGAMBannerAd *fluidAd = - [[FLTFluidGAMBannerAd alloc] initWithAdUnitId:@"testId" - request:[[FLTGAMAdRequest alloc] init] - rootViewController:mockRootViewController - adId:@1]; + FLTFluidGAMBannerAd *fluidAd = [[FLTFluidGAMBannerAd alloc] + initWithAdUnitId:@"testId" + request:[[FLTGAMAdRequest alloc] init] + rootViewController:mockRootViewController + adId:@1]; fluidAd.manager = mockManager; // Mimic successful loading of an ad. [fluidAd load]; - [fluidAd.bannerView.delegate bannerViewDidReceiveAd:OCMClassMock([GADBannerView class])]; + [fluidAd.bannerView.delegate + bannerViewDidReceiveAd:OCMClassMock([GADBannerView class])]; - [fluidAd.bannerView.adSizeDelegate adView:fluidAd.bannerView - willChangeAdSizeTo:GADAdSizeFromCGSize(CGSizeMake(0, 25))]; + [fluidAd.bannerView.adSizeDelegate + adView:fluidAd.bannerView + willChangeAdSizeTo:GADAdSizeFromCGSize(CGSizeMake(0, 25))]; OCMVerify([mockManager onFluidAdHeightChanged:fluidAd height:25]); } - (void)testLoad { FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init]; request.keywords = @[ @"apple" ]; - UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); - FLTFluidGAMBannerAd *ad = [[FLTFluidGAMBannerAd alloc] initWithAdUnitId:@"testId" - request:request - rootViewController:mockRootViewController - adId:@1]; + UIViewController *mockRootViewController = + OCMClassMock([UIViewController class]); + FLTFluidGAMBannerAd *ad = + [[FLTFluidGAMBannerAd alloc] initWithAdUnitId:@"testId" + request:request + rootViewController:mockRootViewController + adId:@1]; XCTAssertEqual(ad.bannerView.adUnitID, @"testId"); XCTAssertEqual(ad.bannerView.rootViewController, mockRootViewController); @@ -174,7 +196,8 @@ - (void)testLoad { OCMVerify([mockView loadRequest:[OCMArg checkWithBlock:^BOOL(id obj) { GADRequest *requestArg = obj; - return [requestArg.keywords isEqualToArray:@[ @"apple" ]]; + return + [requestArg.keywords isEqualToArray:@[ @"apple" ]]; }]]); } diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGAMAdRequestTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGAMAdRequestTest.m index 4e788a635..44b7a1c8f 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGAMAdRequestTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGAMAdRequestTest.m @@ -71,7 +71,8 @@ - (void)testAsAdRequestAllParams { GADExtras *updatedExtras = [gamRequest adNetworkExtrasFor:[GADExtras class]]; XCTAssertEqualObjects(updatedExtras, extras); XCTAssertEqualObjects(updatedExtras.additionalParameters[@"npa"], @"1"); - OCMVerify([gamRequestSpy registerAdNetworkExtras:[OCMArg isEqual:testExtras]]); + OCMVerify( + [gamRequestSpy registerAdNetworkExtras:[OCMArg isEqual:testExtras]]); } - (void)testAsAdRequestNoParams { @@ -144,7 +145,8 @@ - (void)testGADExtrasWithoutNpa { GADRequest *gamRequest = [fltGAMAdRequest asGAMRequest:@"test-ad-unit"]; XCTAssertNil([gamRequest adNetworkExtrasFor:[GADExtras class]]); - OCMVerify([gamRequestSpy registerAdNetworkExtras:[OCMArg isEqual:testExtras]]); + OCMVerify( + [gamRequestSpy registerAdNetworkExtras:[OCMArg isEqual:testExtras]]); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGAMBannerAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGAMBannerAdTest.m index acdf81f35..1baf1f4ca 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGAMBannerAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGAMBannerAdTest.m @@ -32,7 +32,8 @@ - (void)setUp { - (void)testDelegates { FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init]; request.keywords = @[ @"apple" ]; - UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); + UIViewController *mockRootViewController = + OCMClassMock([UIViewController class]); FLTGAMBannerAd *bannerAd = [[FLTGAMBannerAd alloc] initWithAdUnitId:@"testId" sizes:@[ [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)] ] @@ -46,23 +47,29 @@ - (void)testDelegates { XCTAssertEqual(adView.appEventDelegate, bannerAd); XCTAssertEqual(adView.delegate, bannerAd); - [bannerAd.bannerView.delegate bannerViewDidReceiveAd:OCMClassMock([GADBannerView class])]; + [bannerAd.bannerView.delegate + bannerViewDidReceiveAd:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:bannerAd] responseInfo:[OCMArg isEqual:adView.responseInfo]]); - [bannerAd.bannerView.delegate bannerViewDidDismissScreen:OCMClassMock([GADBannerView class])]; + [bannerAd.bannerView.delegate + bannerViewDidDismissScreen:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager onBannerDidDismissScreen:[OCMArg isEqual:bannerAd]]); - [bannerAd.bannerView.delegate bannerViewWillDismissScreen:OCMClassMock([GADBannerView class])]; + [bannerAd.bannerView.delegate + bannerViewWillDismissScreen:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager onBannerWillDismissScreen:[OCMArg isEqual:bannerAd]]); - [bannerAd.bannerView.delegate bannerViewWillPresentScreen:OCMClassMock([GADBannerView class])]; + [bannerAd.bannerView.delegate + bannerViewWillPresentScreen:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager onBannerWillPresentScreen:[OCMArg isEqual:bannerAd]]); - [bannerAd.bannerView.delegate bannerViewDidRecordImpression:OCMClassMock([GADBannerView class])]; + [bannerAd.bannerView.delegate + bannerViewDidRecordImpression:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager onBannerImpression:[OCMArg isEqual:bannerAd]]); - [bannerAd.bannerView.delegate bannerViewDidRecordClick:OCMClassMock([GADBannerView class])]; + [bannerAd.bannerView.delegate + bannerViewDidRecordClick:OCMClassMock([GADBannerView class])]; OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:bannerAd]]); // Mock callback of paid event handler. @@ -72,25 +79,29 @@ - (void)testDelegates { OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); bannerAd.bannerView.paidEventHandler(adValue); - OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:bannerAd] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager + onPaidEvent:[OCMArg isEqual:bannerAd] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); NSString *domain = @"domain"; NSDictionary *userInfo = @{NSLocalizedDescriptionKey : @"description"}; NSError *error = [NSError errorWithDomain:domain code:1 userInfo:userInfo]; [bannerAd.bannerView.delegate bannerView:OCMClassMock([GADBannerView class]) didFailToReceiveAdWithError:error]; - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:bannerAd] error:[OCMArg isEqual:error]]); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:bannerAd] + error:[OCMArg isEqual:error]]); - [adView.appEventDelegate adView:adView didReceiveAppEvent:@"appEvent" withInfo:@"info"]; + [adView.appEventDelegate adView:adView + didReceiveAppEvent:@"appEvent" + withInfo:@"info"]; OCMVerify([mockManager onAppEvent:[OCMArg isEqual:bannerAd] name:[OCMArg isEqual:@"appEvent"] data:[OCMArg isEqual:@"info"]]); @@ -99,7 +110,8 @@ - (void)testDelegates { - (void)testLoad { FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init]; request.keywords = @[ @"apple" ]; - UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); + UIViewController *mockRootViewController = + OCMClassMock([UIViewController class]); FLTGAMBannerAd *ad = [[FLTGAMBannerAd alloc] initWithAdUnitId:@"testId" sizes:@[ [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)] ] @@ -117,7 +129,8 @@ - (void)testLoad { OCMVerify([mockView loadRequest:[OCMArg checkWithBlock:^BOOL(id obj) { GADRequest *requestArg = obj; - return [requestArg.keywords isEqualToArray:@[ @"apple" ]]; + return + [requestArg.keywords isEqualToArray:@[ @"apple" ]]; }]]); } diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m index 3cc61b069..c3d55f8d7 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m @@ -35,16 +35,19 @@ - (void)testLoadShowInterstitialAd { GAMRequest *gadRequest = OCMClassMock([GAMRequest class]); OCMStub([request asGAMRequest:[OCMArg any]]).andReturn(gadRequest); - UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); - FLTGAMInterstitialAd *ad = [[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + UIViewController *mockRootViewController = + OCMClassMock([UIViewController class]); + FLTGAMInterstitialAd *ad = + [[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id interstitialClassMock = OCMClassMock([GAMInterstitialAd class]); - OCMStub(ClassMethod([interstitialClassMock loadWithAdManagerAdUnitID:[OCMArg any] - request:[OCMArg any] - completionHandler:[OCMArg any]])) + OCMStub(ClassMethod([interstitialClassMock + loadWithAdManagerAdUnitID:[OCMArg any] + request:[OCMArg any] + completionHandler:[OCMArg any]])) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(GAMInterstitialAd *ad, NSError *error); [invocation getArgument:&completionHandler atIndex:4]; @@ -61,7 +64,8 @@ - (void)testLoadShowInterstitialAd { [delegate adDidDismissFullScreenContent:interstitialClassMock]; [delegate adWillPresentFullScreenContent:interstitialClassMock]; [delegate adWillDismissFullScreenContent:interstitialClassMock]; - [delegate ad:interstitialClassMock didFailToPresentFullScreenContentWithError:error]; + [delegate ad:interstitialClassMock + didFailToPresentFullScreenContentWithError:error]; }); OCMStub([interstitialClassMock setAppEventDelegate:[OCMArg any]]) @@ -82,31 +86,35 @@ - (void)testLoadShowInterstitialAd { OCMStub([adValue value]).andReturn(NSDecimalNumber.one); OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated); OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); - OCMStub([interstitialClassMock setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - GADPaidEventHandler handler = obj; - handler(adValue); - return YES; - }]]); + OCMStub([interstitialClassMock + setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + GADPaidEventHandler handler = obj; + handler(adValue); + return YES; + }]]); // Call load and verify interactions with mocks. [ad load]; - OCMVerify(ClassMethod([interstitialClassMock loadWithAdManagerAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadRequest] - completionHandler:[OCMArg any]])); + OCMVerify(ClassMethod([interstitialClassMock + loadWithAdManagerAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadRequest] + completionHandler:[OCMArg any]])); OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad] responseInfo:[OCMArg isEqual:responseInfo]]); - OCMVerify([interstitialClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); + OCMVerify( + [interstitialClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); XCTAssertEqual(ad.interstitial, interstitialClassMock); - OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager + onPaidEvent:[OCMArg isEqual:ad] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); // Show the ad [ad showFromRootViewController:mockRootViewController]; @@ -120,8 +128,9 @@ - (void)testLoadShowInterstitialAd { OCMVerify([mockManager adWillDismissFullScreenContent:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordImpression:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:ad]]); - OCMVerify([mockManager didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager + didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); // Verify app event OCMVerify([mockManager onAppEvent:ad @@ -135,16 +144,18 @@ - (void)testFailToLoad { GAMRequest *gadRequest = OCMClassMock([GAMRequest class]); OCMStub([request asGAMRequest:[OCMArg any]]).andReturn(gadRequest); - FLTGAMInterstitialAd *ad = [[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + FLTGAMInterstitialAd *ad = + [[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id interstitialClassMock = OCMClassMock([GAMInterstitialAd class]); NSError *error = OCMClassMock([NSError class]); - OCMStub(ClassMethod([interstitialClassMock loadWithAdManagerAdUnitID:[OCMArg any] - request:[OCMArg any] - completionHandler:[OCMArg any]])) + OCMStub(ClassMethod([interstitialClassMock + loadWithAdManagerAdUnitID:[OCMArg any] + request:[OCMArg any] + completionHandler:[OCMArg any]])) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(GAMInterstitialAd *ad, NSError *error); [invocation getArgument:&completionHandler atIndex:4]; @@ -153,10 +164,12 @@ - (void)testFailToLoad { [ad load]; - OCMVerify(ClassMethod([interstitialClassMock loadWithAdManagerAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadRequest] - completionHandler:[OCMArg any]])); - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]); + OCMVerify(ClassMethod([interstitialClassMock + loadWithAdManagerAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadRequest] + completionHandler:[OCMArg any]])); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsPluginMethodCallsTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsPluginMethodCallsTest.m index 6e3f7b486..a4164b0ce 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsPluginMethodCallsTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsPluginMethodCallsTest.m @@ -34,16 +34,20 @@ @implementation FLTGoogleMobileAdsPluginMethodCallsTest { } - (void)setUp { - id messenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger)); - FLTAdInstanceManager *manager = [[FLTAdInstanceManager alloc] initWithBinaryMessenger:messenger]; + id messenger = + OCMProtocolMock(@protocol(FlutterBinaryMessenger)); + FLTAdInstanceManager *manager = + [[FLTAdInstanceManager alloc] initWithBinaryMessenger:messenger]; _mockAdInstanceManager = OCMPartialMock(manager); _fltGoogleMobileAdsPlugin = [[FLTGoogleMobileAdsPlugin alloc] init]; - [_fltGoogleMobileAdsPlugin setValue:_mockAdInstanceManager forKey:@"_manager"]; + [_fltGoogleMobileAdsPlugin setValue:_mockAdInstanceManager + forKey:@"_manager"]; } - (void)testDisposeAd { - FlutterMethodCall *methodCall = [FlutterMethodCall methodCallWithMethodName:@"disposeAd" - arguments:@{@"adId" : @1}]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"disposeAd" + arguments:@{@"adId" : @1}]; __block bool resultInvoked = false; __block id _Nullable returnedResult; FlutterResult result = ^(id _Nullable result) { @@ -61,12 +65,13 @@ - (void)testDisposeAd { - (void)testLoadRewardedAd { FLTAdRequest *request = [[FLTAdRequest alloc] init]; request.keywords = @[ @"apple" ]; - FlutterMethodCall *methodCall = [FlutterMethodCall methodCallWithMethodName:@"loadRewardedAd" - arguments:@{ - @"adId" : @2, - @"adUnitId" : @"testId", - @"request" : request, - }]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"loadRewardedAd" + arguments:@{ + @"adId" : @2, + @"adUnitId" : @"testId", + @"request" : request, + }]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -86,12 +91,13 @@ - (void)testLoadRewardedAd { XCTAssertEqualObjects(adUnit, @"testId"); return YES; }; - OCMVerify([_mockAdInstanceManager loadAd:[OCMArg checkWithBlock:verificationBlock]]); + OCMVerify([_mockAdInstanceManager + loadAd:[OCMArg checkWithBlock:verificationBlock]]); } - (void)testInternalInit { - FlutterMethodCall *methodCall = [FlutterMethodCall methodCallWithMethodName:@"_init" - arguments:@{}]; + FlutterMethodCall *methodCall = + [FlutterMethodCall methodCallWithMethodName:@"_init" arguments:@{}]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -111,19 +117,22 @@ - (void)testMobileAdsInitialize { id gadMobileAdsClassMock = OCMClassMock([GADMobileAds class]); OCMStub(ClassMethod([gadMobileAdsClassMock sharedInstance])) .andReturn((GADMobileAds *)gadMobileAdsClassMock); - GADInitializationStatus *mockInitStatus = OCMClassMock([GADInitializationStatus class]); + GADInitializationStatus *mockInitStatus = + OCMClassMock([GADInitializationStatus class]); OCMStub([mockInitStatus adapterStatusesByClassName]).andReturn(@{}); OCMStub([gadMobileAdsClassMock startWithCompletionHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { // Invoke the init handler twice. - __unsafe_unretained GADInitializationCompletionHandler completionHandler; + __unsafe_unretained GADInitializationCompletionHandler + completionHandler; [invocation getArgument:&completionHandler atIndex:2]; completionHandler(mockInitStatus); completionHandler(mockInitStatus); }); FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"MobileAds#initialize" arguments:@{}]; + [FlutterMethodCall methodCallWithMethodName:@"MobileAds#initialize" + arguments:@{}]; __block int resultInvokedCount = 0; __block id _Nullable returnedResult; FlutterResult result = ^(id _Nullable result) { @@ -133,7 +142,8 @@ - (void)testMobileAdsInitialize { [_fltGoogleMobileAdsPlugin handleMethodCall:methodCall result:result]; XCTAssertEqual(resultInvokedCount, 1); - XCTAssertEqual([((FLTInitializationStatus *)returnedResult) adapterStatuses].count, 0); + XCTAssertEqual( + [((FLTInitializationStatus *)returnedResult) adapterStatuses].count, 0); } - (void)testSetSameAppKeyEnabledYes { @@ -142,11 +152,12 @@ - (void)testSetSameAppKeyEnabledYes { .andReturn((GADMobileAds *)gadMobileAdsClassMock); GADRequestConfiguration *gadRequestConfigurationMock = OCMClassMock([GADRequestConfiguration class]); - OCMStub([gadMobileAdsClassMock requestConfiguration]).andReturn(gadRequestConfigurationMock); + OCMStub([gadMobileAdsClassMock requestConfiguration]) + .andReturn(gadRequestConfigurationMock); - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"MobileAds#setSameAppKeyEnabled" - arguments:@{@"isEnabled" : @(YES)}]; + FlutterMethodCall *methodCall = [FlutterMethodCall + methodCallWithMethodName:@"MobileAds#setSameAppKeyEnabled" + arguments:@{@"isEnabled" : @(YES)}]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -159,7 +170,8 @@ - (void)testSetSameAppKeyEnabledYes { XCTAssertTrue(resultInvoked); XCTAssertNil(returnedResult); - OCMVerify([gadRequestConfigurationMock setPublisherFirstPartyIDEnabled:[OCMArg isEqual:@(YES)]]); + OCMVerify([gadRequestConfigurationMock + setPublisherFirstPartyIDEnabled:[OCMArg isEqual:@(YES)]]); } - (void)testRegisterWebView { @@ -169,7 +181,8 @@ - (void)testRegisterWebView { WKWebView *mockWebView = OCMClassMock([WKWebView class]); id fltAdUtilMock = OCMClassMock([FLTAdUtil class]); - OCMStub(ClassMethod([fltAdUtilMock getWebView:[OCMArg any] flutterPluginRegistry:[OCMArg any]])) + OCMStub(ClassMethod([fltAdUtilMock getWebView:[OCMArg any] + flutterPluginRegistry:[OCMArg any]])) .andReturn(mockWebView); FlutterMethodCall *methodCall = @@ -195,11 +208,12 @@ - (void)testSetSameAppKeyEnabledNo { .andReturn((GADMobileAds *)gadMobileAdsClassMock); GADRequestConfiguration *gadRequestConfigurationMock = OCMClassMock([GADRequestConfiguration class]); - OCMStub([gadMobileAdsClassMock requestConfiguration]).andReturn(gadRequestConfigurationMock); + OCMStub([gadMobileAdsClassMock requestConfiguration]) + .andReturn(gadRequestConfigurationMock); - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"MobileAds#setSameAppKeyEnabled" - arguments:@{@"isEnabled" : @0}]; + FlutterMethodCall *methodCall = [FlutterMethodCall + methodCallWithMethodName:@"MobileAds#setSameAppKeyEnabled" + arguments:@{@"isEnabled" : @0}]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -214,9 +228,9 @@ - (void)testSetSameAppKeyEnabledNo { XCTAssertNil(returnedResult); OCMVerify([gadRequestConfigurationMock setPublisherFirstPartyIDEnabled:NO]); - FlutterMethodCall *methodCallWithBool = - [FlutterMethodCall methodCallWithMethodName:@"MobileAds#setSameAppKeyEnabled" - arguments:@{@"isEnabled" : @NO}]; + FlutterMethodCall *methodCallWithBool = [FlutterMethodCall + methodCallWithMethodName:@"MobileAds#setSameAppKeyEnabled" + arguments:@{@"isEnabled" : @NO}]; __block bool resultInvokedWithBool = false; __block id _Nullable returnedResultWithBool; @@ -225,7 +239,8 @@ - (void)testSetSameAppKeyEnabledNo { returnedResultWithBool = result; }; - [_fltGoogleMobileAdsPlugin handleMethodCall:methodCallWithBool result:resultWithBool]; + [_fltGoogleMobileAdsPlugin handleMethodCall:methodCallWithBool + result:resultWithBool]; XCTAssertTrue(resultInvokedWithBool); XCTAssertNil(returnedResultWithBool); @@ -250,8 +265,9 @@ - (void)testSetAppMuted { XCTAssertNil(returnedResult); XCTAssertTrue(GADMobileAds.sharedInstance.applicationMuted); - methodCall = [FlutterMethodCall methodCallWithMethodName:@"MobileAds#setAppMuted" - arguments:@{@"muted" : @(NO)}]; + methodCall = + [FlutterMethodCall methodCallWithMethodName:@"MobileAds#setAppMuted" + arguments:@{@"muted" : @(NO)}]; resultInvoked = false; result = ^(id _Nullable result) { @@ -289,9 +305,9 @@ - (void)testDisableSDKCrashReporting { id gadMobileAdsClassMock = OCMClassMock([GADMobileAds class]); OCMStub(ClassMethod([gadMobileAdsClassMock sharedInstance])) .andReturn((GADMobileAds *)gadMobileAdsClassMock); - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"MobileAds#disableSDKCrashReporting" - arguments:@{}]; + FlutterMethodCall *methodCall = [FlutterMethodCall + methodCallWithMethodName:@"MobileAds#disableSDKCrashReporting" + arguments:@{}]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -312,9 +328,9 @@ - (void)testDisableMediationInitialization { OCMStub(ClassMethod([gadMobileAdsClassMock sharedInstance])) .andReturn((GADMobileAds *)gadMobileAdsClassMock); - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"MobileAds#disableMediationInitialization" - arguments:@{}]; + FlutterMethodCall *methodCall = [FlutterMethodCall + methodCallWithMethodName:@"MobileAds#disableMediationInitialization" + arguments:@{}]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -332,7 +348,8 @@ - (void)testDisableMediationInitialization { - (void)testGetVersionString { FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"MobileAds#getVersionString" arguments:@{}]; + [FlutterMethodCall methodCallWithMethodName:@"MobileAds#getVersionString" + arguments:@{}]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -344,14 +361,15 @@ - (void)testGetVersionString { [_fltGoogleMobileAdsPlugin handleMethodCall:methodCall result:result]; XCTAssertTrue(resultInvoked); - XCTAssertEqual(returnedResult, - GADGetStringFromVersionNumber(GADMobileAds.sharedInstance.versionNumber)); + XCTAssertEqual( + returnedResult, + GADGetStringFromVersionNumber(GADMobileAds.sharedInstance.versionNumber)); } - (void)testOpenDebugMenu { - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"MobileAds#openDebugMenu" - arguments:@{@"adUnitId" : @"test-ad-unit"}]; + FlutterMethodCall *methodCall = [FlutterMethodCall + methodCallWithMethodName:@"MobileAds#openDebugMenu" + arguments:@{@"adUnitId" : @"test-ad-unit"}]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -360,14 +378,16 @@ - (void)testOpenDebugMenu { returnedResult = result; }; - FLTGoogleMobileAdsPlugin *mockPlugin = OCMPartialMock(_fltGoogleMobileAdsPlugin); + FLTGoogleMobileAdsPlugin *mockPlugin = + OCMPartialMock(_fltGoogleMobileAdsPlugin); UIViewController *mockUIViewController = OCMClassMock(UIViewController.class); OCMStub([mockPlugin rootController]).andReturn(mockUIViewController); [_fltGoogleMobileAdsPlugin handleMethodCall:methodCall result:result]; OCMVerify([mockUIViewController - presentViewController:[OCMArg isKindOfClass:[GADDebugOptionsViewController class]] + presentViewController:[OCMArg isKindOfClass:[GADDebugOptionsViewController + class]] animated:[OCMArg any] completion:[OCMArg isNil]]); XCTAssertTrue(resultInvoked); @@ -376,7 +396,8 @@ - (void)testOpenDebugMenu { - (void)testOpenAdInspectorSuccess { FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"MobileAds#openAdInspector" arguments:@{}]; + [FlutterMethodCall methodCallWithMethodName:@"MobileAds#openAdInspector" + arguments:@{}]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -389,8 +410,9 @@ - (void)testOpenAdInspectorSuccess { OCMStub(ClassMethod([gadMobileAdsClassMock sharedInstance])) .andReturn((GADMobileAds *)gadMobileAdsClassMock); - OCMStub([gadMobileAdsClassMock presentAdInspectorFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]) + OCMStub([gadMobileAdsClassMock + presentAdInspectorFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { __unsafe_unretained GADAdInspectorCompletionHandler completionHandler; [invocation getArgument:&completionHandler atIndex:3]; @@ -399,15 +421,17 @@ - (void)testOpenAdInspectorSuccess { [_fltGoogleMobileAdsPlugin handleMethodCall:methodCall result:result]; - OCMVerify([gadMobileAdsClassMock presentAdInspectorFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]); + OCMVerify([gadMobileAdsClassMock + presentAdInspectorFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]); XCTAssertTrue(resultInvoked); XCTAssertEqual(returnedResult, nil); } - (void)testOpenAdInspectorError { FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"MobileAds#openAdInspector" arguments:@{}]; + [FlutterMethodCall methodCallWithMethodName:@"MobileAds#openAdInspector" + arguments:@{}]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -424,8 +448,9 @@ - (void)testOpenAdInspectorError { }; NSError *error = [NSError errorWithDomain:@"domain" code:1 userInfo:userInfo]; - OCMStub([gadMobileAdsClassMock presentAdInspectorFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]) + OCMStub([gadMobileAdsClassMock + presentAdInspectorFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { __unsafe_unretained GADAdInspectorCompletionHandler completionHandler; [invocation getArgument:&completionHandler atIndex:3]; @@ -434,8 +459,9 @@ - (void)testOpenAdInspectorError { [_fltGoogleMobileAdsPlugin handleMethodCall:methodCall result:result]; - OCMVerify([gadMobileAdsClassMock presentAdInspectorFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]); + OCMVerify([gadMobileAdsClassMock + presentAdInspectorFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]); XCTAssertTrue(resultInvoked); FlutterError *resultError = (FlutterError *)returnedResult; @@ -445,9 +471,9 @@ - (void)testOpenAdInspectorError { } - (void)testGetRequestConfiguration { - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"MobileAds#getRequestConfiguration" - arguments:@{}]; + FlutterMethodCall *methodCall = [FlutterMethodCall + methodCallWithMethodName:@"MobileAds#getRequestConfiguration" + arguments:@{}]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -459,16 +485,17 @@ - (void)testGetRequestConfiguration { [_fltGoogleMobileAdsPlugin handleMethodCall:methodCall result:result]; XCTAssertTrue(resultInvoked); - XCTAssertEqual(returnedResult, [GADMobileAds.sharedInstance requestConfiguration]); + XCTAssertEqual(returnedResult, + [GADMobileAds.sharedInstance requestConfiguration]); } - (void)testGetAnchoredAdaptiveBannerAdSize { - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"AdSize#getAnchoredAdaptiveBannerAdSize" - arguments:@{ - @"orientation" : @"portrait", - @"width" : @23, - }]; + FlutterMethodCall *methodCall = [FlutterMethodCall + methodCallWithMethodName:@"AdSize#getAnchoredAdaptiveBannerAdSize" + arguments:@{ + @"orientation" : @"portrait", + @"width" : @23, + }]; __block bool resultInvoked = false; __block id _Nullable returnedResult; @@ -480,14 +507,16 @@ - (void)testGetAnchoredAdaptiveBannerAdSize { [_fltGoogleMobileAdsPlugin handleMethodCall:methodCall result:result]; XCTAssertTrue(resultInvoked); - XCTAssertEqual([returnedResult doubleValue], - GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth(23).size.height); + XCTAssertEqual( + [returnedResult doubleValue], + GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth(23).size.height); - methodCall = [FlutterMethodCall methodCallWithMethodName:@"AdSize#getAnchoredAdaptiveBannerAdSize" - arguments:@{ - @"orientation" : @"landscape", - @"width" : @34, - }]; + methodCall = [FlutterMethodCall + methodCallWithMethodName:@"AdSize#getAnchoredAdaptiveBannerAdSize" + arguments:@{ + @"orientation" : @"landscape", + @"width" : @34, + }]; resultInvoked = false; result = ^(id _Nullable result) { @@ -498,13 +527,15 @@ - (void)testGetAnchoredAdaptiveBannerAdSize { [_fltGoogleMobileAdsPlugin handleMethodCall:methodCall result:result]; XCTAssertTrue(resultInvoked); - XCTAssertEqual([returnedResult doubleValue], - GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth(34).size.height); + XCTAssertEqual( + [returnedResult doubleValue], + GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth(34).size.height); - methodCall = [FlutterMethodCall methodCallWithMethodName:@"AdSize#getAnchoredAdaptiveBannerAdSize" - arguments:@{ - @"width" : @45, - }]; + methodCall = [FlutterMethodCall + methodCallWithMethodName:@"AdSize#getAnchoredAdaptiveBannerAdSize" + arguments:@{ + @"width" : @45, + }]; resultInvoked = false; result = ^(id _Nullable result) { @@ -516,19 +547,20 @@ - (void)testGetAnchoredAdaptiveBannerAdSize { XCTAssertTrue(resultInvoked); XCTAssertEqual([returnedResult doubleValue], - GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(45).size.height); + GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(45) + .size.height); } - (void)testGetAdSize_bannerAd { // Method calls to load a banner ad. - FlutterMethodCall *loadAdMethodCall = - [FlutterMethodCall methodCallWithMethodName:@"loadBannerAd" - arguments:@{ - @"adId" : @(1), - @"adUnitId" : @"ad-unit-id", - @"size" : [[FLTAdSize alloc] initWithWidth:@1 height:@2], - @"request" : [[FLTAdRequest alloc] init], - }]; + FlutterMethodCall *loadAdMethodCall = [FlutterMethodCall + methodCallWithMethodName:@"loadBannerAd" + arguments:@{ + @"adId" : @(1), + @"adUnitId" : @"ad-unit-id", + @"size" : [[FLTAdSize alloc] initWithWidth:@1 height:@2], + @"request" : [[FLTAdRequest alloc] init], + }]; __block bool loadAdResultInvoked = false; __block id _Nullable returnedLoadAdResult; @@ -537,7 +569,8 @@ - (void)testGetAdSize_bannerAd { returnedLoadAdResult = result; }; - [_fltGoogleMobileAdsPlugin handleMethodCall:loadAdMethodCall result:loadAdResult]; + [_fltGoogleMobileAdsPlugin handleMethodCall:loadAdMethodCall + result:loadAdResult]; XCTAssertTrue(loadAdResultInvoked); XCTAssertNil(returnedLoadAdResult); @@ -551,8 +584,10 @@ - (void)testGetAdSize_bannerAd { }; FlutterMethodCall *getAdSizeMethodCall = - [FlutterMethodCall methodCallWithMethodName:@"getAdSize" arguments:@{@"adId" : @(1)}]; - [_fltGoogleMobileAdsPlugin handleMethodCall:getAdSizeMethodCall result:getAdSizeResult]; + [FlutterMethodCall methodCallWithMethodName:@"getAdSize" + arguments:@{@"adId" : @(1)}]; + [_fltGoogleMobileAdsPlugin handleMethodCall:getAdSizeMethodCall + result:getAdSizeResult]; XCTAssertTrue(getAdSizeResultInvoked); XCTAssertEqualObjects(returnedGetAdSizeResult.width, @1); @@ -567,13 +602,13 @@ - (void)testServerSideVerificationOptions_rewardedAd { // Method calls to set ssv FLTServerSideVerificationOptions *mockSSV = OCMClassMock([FLTServerSideVerificationOptions class]); - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"setServerSideVerificationOptions" - arguments:@{ - @"adId" : @(1), - @"adUnitId" : @"ad-unit-id", - @"serverSideVerificationOptions" : mockSSV, - }]; + FlutterMethodCall *methodCall = [FlutterMethodCall + methodCallWithMethodName:@"setServerSideVerificationOptions" + arguments:@{ + @"adId" : @(1), + @"adUnitId" : @"ad-unit-id", + @"serverSideVerificationOptions" : mockSSV, + }]; __block bool resultInvoked = false; FlutterResult result = ^(id _Nullable result) { @@ -588,19 +623,20 @@ - (void)testServerSideVerificationOptions_rewardedAd { - (void)testServerSideVerificationOptions_rewardedInterstitialAd { // Mock having already loaded an ad - FLTRewardedInterstitialAd *mockAd = OCMClassMock([FLTRewardedInterstitialAd class]); + FLTRewardedInterstitialAd *mockAd = + OCMClassMock([FLTRewardedInterstitialAd class]); OCMStub([_mockAdInstanceManager adFor:[OCMArg isEqual:@1]]).andReturn(mockAd); // Method calls to set ssv FLTServerSideVerificationOptions *mockSSV = OCMClassMock([FLTServerSideVerificationOptions class]); - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"setServerSideVerificationOptions" - arguments:@{ - @"adId" : @(1), - @"adUnitId" : @"ad-unit-id", - @"serverSideVerificationOptions" : mockSSV, - }]; + FlutterMethodCall *methodCall = [FlutterMethodCall + methodCallWithMethodName:@"setServerSideVerificationOptions" + arguments:@{ + @"adId" : @(1), + @"adUnitId" : @"ad-unit-id", + @"serverSideVerificationOptions" : mockSSV, + }]; __block bool resultInvoked = false; FlutterResult result = ^(id _Nullable result) { @@ -617,13 +653,13 @@ - (void)testServerSideVerificationOptions_nullAd { // Try to set ssv without any ads being loaded FLTServerSideVerificationOptions *mockSSV = OCMClassMock([FLTServerSideVerificationOptions class]); - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"setServerSideVerificationOptions" - arguments:@{ - @"adId" : @(1), - @"adUnitId" : @"ad-unit-id", - @"serverSideVerificationOptions" : mockSSV, - }]; + FlutterMethodCall *methodCall = [FlutterMethodCall + methodCallWithMethodName:@"setServerSideVerificationOptions" + arguments:@{ + @"adId" : @(1), + @"adUnitId" : @"ad-unit-id", + @"serverSideVerificationOptions" : mockSSV, + }]; __block bool resultInvoked = false; FlutterResult result = ^(id _Nullable result) { @@ -645,13 +681,13 @@ - (void)testServerSideVerificationOptions_invalidAdType { // Try to set ssv without any ads being loaded FLTServerSideVerificationOptions *mockSSV = OCMClassMock([FLTServerSideVerificationOptions class]); - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"setServerSideVerificationOptions" - arguments:@{ - @"adId" : @(1), - @"adUnitId" : @"ad-unit-id", - @"serverSideVerificationOptions" : mockSSV, - }]; + FlutterMethodCall *methodCall = [FlutterMethodCall + methodCallWithMethodName:@"setServerSideVerificationOptions" + arguments:@{ + @"adId" : @(1), + @"adUnitId" : @"ad-unit-id", + @"serverSideVerificationOptions" : mockSSV, + }]; __block bool resultInvoked = false; FlutterResult result = ^(id _Nullable result) { diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsReaderWriterTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsReaderWriterTest.m index f409335dd..e60d75356 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsReaderWriterTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsReaderWriterTest.m @@ -46,10 +46,12 @@ @implementation FLTGoogleMobileAdsReaderWriterTest { - (void)setUp { id fltAdUtilMock = OCMClassMock([FLTAdUtil class]); - OCMStub(ClassMethod([fltAdUtilMock requestAgent])).andReturn(@"request-agent"); - _readerWriter = - [[FLTGoogleMobileAdsReaderWriter alloc] initWithFactory:[[FLTTestAdSizeFactory alloc] init]]; - _messageCodec = [FlutterStandardMessageCodec codecWithReaderWriter:_readerWriter]; + OCMStub(ClassMethod([fltAdUtilMock requestAgent])) + .andReturn(@"request-agent"); + _readerWriter = [[FLTGoogleMobileAdsReaderWriter alloc] + initWithFactory:[[FLTTestAdSizeFactory alloc] init]]; + _messageCodec = + [FlutterStandardMessageCodec codecWithReaderWriter:_readerWriter]; } - (void)testEncodeDecodeAdSize { @@ -64,14 +66,20 @@ - (void)testEncodeDecodeAdSize { - (void)testEncodeDecodeRequestConfiguration { GADMobileAds.sharedInstance.requestConfiguration.maxAdContentRating = GADMaxAdContentRatingMatureAudience; - GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment = @YES; - GADMobileAds.sharedInstance.requestConfiguration.tagForUnderAgeOfConsent = @NO; - NSArray *testDeviceIds = [[NSArray alloc] initWithObjects:@"test-device-id", nil]; - GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = testDeviceIds; - NSData *encodedMessage = [_messageCodec encode:GADMobileAds.sharedInstance.requestConfiguration]; + GADMobileAds.sharedInstance.requestConfiguration + .tagForChildDirectedTreatment = @YES; + GADMobileAds.sharedInstance.requestConfiguration.tagForUnderAgeOfConsent = + @NO; + NSArray *testDeviceIds = + [[NSArray alloc] initWithObjects:@"test-device-id", nil]; + GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = + testDeviceIds; + NSData *encodedMessage = + [_messageCodec encode:GADMobileAds.sharedInstance.requestConfiguration]; GADRequestConfiguration *decodedSize = [_messageCodec decode:encodedMessage]; - XCTAssertEqualObjects(decodedSize.maxAdContentRating, GADMaxAdContentRatingMatureAudience); + XCTAssertEqualObjects(decodedSize.maxAdContentRating, + GADMaxAdContentRatingMatureAudience); XCTAssertEqualObjects(decodedSize.testDeviceIdentifiers, testDeviceIds); } @@ -90,10 +98,13 @@ - (void)testEncodeDecodeInlineAdaptiveBannerAdSize_currentOrientation { NSData *encodedMessage = [_messageCodec encode:inlineAdaptiveBannerSize]; - FLTInlineAdaptiveBannerSize *decodedSize = [_messageCodec decode:encodedMessage]; + FLTInlineAdaptiveBannerSize *decodedSize = + [_messageCodec decode:encodedMessage]; XCTAssertEqual(decodedSize.size.size.width, testAdSize.size.width); - XCTAssertEqualObjects(decodedSize.maxHeight, inlineAdaptiveBannerSize.maxHeight); - XCTAssertEqualObjects(decodedSize.orientation, inlineAdaptiveBannerSize.orientation); + XCTAssertEqualObjects(decodedSize.maxHeight, + inlineAdaptiveBannerSize.maxHeight); + XCTAssertEqualObjects(decodedSize.orientation, + inlineAdaptiveBannerSize.orientation); } - (void)testEncodeDecodeInlineAdaptiveBannerAdSize_portraitOrientation { @@ -111,17 +122,21 @@ - (void)testEncodeDecodeInlineAdaptiveBannerAdSize_portraitOrientation { NSData *encodedMessage = [_messageCodec encode:inlineAdaptiveBannerSize]; - FLTInlineAdaptiveBannerSize *decodedSize = [_messageCodec decode:encodedMessage]; + FLTInlineAdaptiveBannerSize *decodedSize = + [_messageCodec decode:encodedMessage]; XCTAssertEqual(decodedSize.size.size.width, testAdSize.size.width); - XCTAssertEqualObjects(decodedSize.maxHeight, inlineAdaptiveBannerSize.maxHeight); - XCTAssertEqualObjects(decodedSize.orientation, inlineAdaptiveBannerSize.orientation); + XCTAssertEqualObjects(decodedSize.maxHeight, + inlineAdaptiveBannerSize.maxHeight); + XCTAssertEqualObjects(decodedSize.orientation, + inlineAdaptiveBannerSize.orientation); } - (void)testEncodeDecodeInlineAdaptiveBannerAdSize_landscapeOrientation { GADAdSize testAdSize = GADAdSizeFromCGSize(CGSizeMake(25, 10)); FLTAdSizeFactory *factory = OCMClassMock([FLTAdSizeFactory class]); - OCMStub([factory landscapeInlineAdaptiveBannerAdSizeWithWidth:@(23)]).andReturn(testAdSize); + OCMStub([factory landscapeInlineAdaptiveBannerAdSizeWithWidth:@(23)]) + .andReturn(testAdSize); FLTInlineAdaptiveBannerSize *inlineAdaptiveBannerSize = [[FLTInlineAdaptiveBannerSize alloc] initWithFactory:factory @@ -131,17 +146,21 @@ - (void)testEncodeDecodeInlineAdaptiveBannerAdSize_landscapeOrientation { NSData *encodedMessage = [_messageCodec encode:inlineAdaptiveBannerSize]; - FLTInlineAdaptiveBannerSize *decodedSize = [_messageCodec decode:encodedMessage]; + FLTInlineAdaptiveBannerSize *decodedSize = + [_messageCodec decode:encodedMessage]; XCTAssertEqual(decodedSize.size.size.width, testAdSize.size.width); - XCTAssertEqualObjects(decodedSize.maxHeight, inlineAdaptiveBannerSize.maxHeight); - XCTAssertEqualObjects(decodedSize.orientation, inlineAdaptiveBannerSize.orientation); + XCTAssertEqualObjects(decodedSize.maxHeight, + inlineAdaptiveBannerSize.maxHeight); + XCTAssertEqualObjects(decodedSize.orientation, + inlineAdaptiveBannerSize.orientation); } - (void)testEncodeDecodeInlineAdaptiveBannerAdSize_withMaxHeight { GADAdSize testAdSize = GADAdSizeFromCGSize(CGSizeMake(25, 10)); FLTAdSizeFactory *factory = OCMClassMock([FLTAdSizeFactory class]); - OCMStub([factory inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:@(23) maxHeight:@50]) + OCMStub([factory inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:@(23) + maxHeight:@50]) .andReturn(testAdSize); FLTInlineAdaptiveBannerSize *inlineAdaptiveBannerSize = @@ -152,17 +171,21 @@ - (void)testEncodeDecodeInlineAdaptiveBannerAdSize_withMaxHeight { NSData *encodedMessage = [_messageCodec encode:inlineAdaptiveBannerSize]; - FLTInlineAdaptiveBannerSize *decodedSize = [_messageCodec decode:encodedMessage]; + FLTInlineAdaptiveBannerSize *decodedSize = + [_messageCodec decode:encodedMessage]; XCTAssertEqual(decodedSize.size.size.width, testAdSize.size.width); - XCTAssertEqualObjects(decodedSize.maxHeight, inlineAdaptiveBannerSize.maxHeight); - XCTAssertEqualObjects(decodedSize.orientation, inlineAdaptiveBannerSize.orientation); + XCTAssertEqualObjects(decodedSize.maxHeight, + inlineAdaptiveBannerSize.maxHeight); + XCTAssertEqualObjects(decodedSize.orientation, + inlineAdaptiveBannerSize.orientation); } - (void)testEncodeDecodeAnchoredAdaptiveBannerAdSize_portraitOrientation { GADAdSize testAdSize = GADAdSizeFromCGSize(CGSizeMake(23, 34)); FLTAdSizeFactory *factory = OCMClassMock([FLTAdSizeFactory class]); - OCMStub([factory portraitAnchoredAdaptiveBannerAdSizeWithWidth:@(23)]).andReturn(testAdSize); + OCMStub([factory portraitAnchoredAdaptiveBannerAdSizeWithWidth:@(23)]) + .andReturn(testAdSize); FLTAnchoredAdaptiveBannerSize *size = [[FLTAnchoredAdaptiveBannerSize alloc] initWithFactory:factory @@ -170,7 +193,8 @@ - (void)testEncodeDecodeAnchoredAdaptiveBannerAdSize_portraitOrientation { width:@(23)]; NSData *encodedMessage = [_messageCodec encode:size]; - FLTAnchoredAdaptiveBannerSize *decodedSize = [_messageCodec decode:encodedMessage]; + FLTAnchoredAdaptiveBannerSize *decodedSize = + [_messageCodec decode:encodedMessage]; XCTAssertEqual(decodedSize.size.size.width, testAdSize.size.width); } @@ -178,7 +202,8 @@ - (void)testEncodeDecodeAnchoredAdaptiveBannerAdSize_landscapeOrientation { GADAdSize testAdSize = GADAdSizeFromCGSize(CGSizeMake(34, 45)); FLTAdSizeFactory *factory = OCMClassMock([FLTAdSizeFactory class]); - OCMStub([factory landscapeAnchoredAdaptiveBannerAdSizeWithWidth:@(34)]).andReturn(testAdSize); + OCMStub([factory landscapeAnchoredAdaptiveBannerAdSizeWithWidth:@(34)]) + .andReturn(testAdSize); FLTAnchoredAdaptiveBannerSize *size = [[FLTAnchoredAdaptiveBannerSize alloc] initWithFactory:factory @@ -186,7 +211,8 @@ - (void)testEncodeDecodeAnchoredAdaptiveBannerAdSize_landscapeOrientation { width:@(34)]; NSData *encodedMessage = [_messageCodec encode:size]; - FLTAnchoredAdaptiveBannerSize *decodedSize = [_messageCodec decode:encodedMessage]; + FLTAnchoredAdaptiveBannerSize *decodedSize = + [_messageCodec decode:encodedMessage]; XCTAssertEqual(decodedSize.size.size.width, testAdSize.size.width); } @@ -194,19 +220,24 @@ - (void)testEncodeDecodeAnchoredAdaptiveBannerAdSize_currentOrientation { GADAdSize testAdSize = GADAdSizeFromCGSize(CGSizeMake(45, 56)); FLTAdSizeFactory *factory = OCMClassMock([FLTAdSizeFactory class]); - OCMStub([factory currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:@(45)]) + OCMStub( + [factory currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:@(45)]) .andReturn(testAdSize); FLTAnchoredAdaptiveBannerSize *size = - [[FLTAnchoredAdaptiveBannerSize alloc] initWithFactory:factory orientation:NULL width:@(45)]; + [[FLTAnchoredAdaptiveBannerSize alloc] initWithFactory:factory + orientation:NULL + width:@(45)]; NSData *encodedMessage = [_messageCodec encode:size]; - FLTAnchoredAdaptiveBannerSize *decodedSize = [_messageCodec decode:encodedMessage]; + FLTAnchoredAdaptiveBannerSize *decodedSize = + [_messageCodec decode:encodedMessage]; XCTAssertEqual(decodedSize.size.size.width, testAdSize.size.width); } - (void)testEncodeDecodeSmartBannerAdSize { - FLTSmartBannerSize *size = [[FLTSmartBannerSize alloc] initWithOrientation:@"landscape"]; + FLTSmartBannerSize *size = + [[FLTSmartBannerSize alloc] initWithOrientation:@"landscape"]; NSData *encodedMessage = [_messageCodec encode:size]; FLTSmartBannerSize *decodedSize = [_messageCodec decode:encodedMessage]; @@ -214,8 +245,10 @@ - (void)testEncodeDecodeSmartBannerAdSize { XCTAssertTrue([decodedSize isKindOfClass:FLTSmartBannerSize.class]); #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - XCTAssertEqual(decodedSize.size.size.width, kGADAdSizeSmartBannerPortrait.size.width); - XCTAssertEqual(decodedSize.size.size.height, kGADAdSizeSmartBannerPortrait.size.height); + XCTAssertEqual(decodedSize.size.size.width, + kGADAdSizeSmartBannerPortrait.size.width); + XCTAssertEqual(decodedSize.size.size.height, + kGADAdSizeSmartBannerPortrait.size.height); #pragma clang diagnostic pop } @@ -231,7 +264,8 @@ - (void)testEncodeDecodeFluidAdSize { } - (void)testEncodeDecodeAdRequest { - id mediationExtras = [[_FlutterMediationExtras alloc] init]; + id mediationExtras = + [[_FlutterMediationExtras alloc] init]; mediationExtras.extras = @{@"test_key" : @"test_value"}; FLTAdRequest *request = [[FLTAdRequest alloc] init]; request.keywords = @[ @"apple" ]; @@ -241,7 +275,8 @@ - (void)testEncodeDecodeAdRequest { request.neighboringContentURLs = contentURLs; request.mediationExtrasIdentifier = @"identifier"; request.adMobExtras = @{@"key" : @"value"}; - NSArray> *mediationExtrasArray = @[ mediationExtras ]; + NSArray> *mediationExtrasArray = + @[ mediationExtras ]; request.mediationExtras = mediationExtrasArray; NSData *encodedMessage = [_messageCodec encode:request]; @@ -250,14 +285,17 @@ - (void)testEncodeDecodeAdRequest { XCTAssertEqualObjects(decodedRequest.contentURL, @"banana"); XCTAssertTrue(decodedRequest.nonPersonalizedAds); XCTAssertEqualObjects(decodedRequest.neighboringContentURLs, contentURLs); - XCTAssertEqualObjects(decodedRequest.mediationExtrasIdentifier, @"identifier"); + XCTAssertEqualObjects(decodedRequest.mediationExtrasIdentifier, + @"identifier"); XCTAssertEqualObjects(decodedRequest.adMobExtras, @{@"key" : @"value"}); XCTAssertEqualObjects(decodedRequest.requestAgent, @"request-agent"); - XCTAssertEqualObjects(decodedRequest.mediationExtras[0].extras, @{@"test_key" : @"test_value"}); + XCTAssertEqualObjects(decodedRequest.mediationExtras[0].extras, + @{@"test_key" : @"test_value"}); } - (void)testEncodeDecodeGAMAdRequest { - id mediationExtras = [[_FlutterMediationExtras alloc] init]; + id mediationExtras = + [[_FlutterMediationExtras alloc] init]; mediationExtras.extras = @{@"test_key" : @"test_value"}; FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init]; request.keywords = @[ @"apple" ]; @@ -270,27 +308,32 @@ - (void)testEncodeDecodeGAMAdRequest { request.pubProvidedID = @"pub-id"; request.mediationExtrasIdentifier = @"identifier"; request.adMobExtras = @{@"key" : @"value"}; - NSArray> *mediationExtrasArray = @[ mediationExtras ]; + NSArray> *mediationExtrasArray = + @[ mediationExtras ]; request.mediationExtras = mediationExtrasArray; NSData *encodedMessage = [_messageCodec encode:request]; FLTGAMAdRequest *decodedRequest = [_messageCodec decode:encodedMessage]; XCTAssertTrue([decodedRequest.keywords isEqualToArray:@[ @"apple" ]]); XCTAssertEqualObjects(decodedRequest.contentURL, @"banana"); - XCTAssertTrue([decodedRequest.customTargeting isEqualToDictionary:@{@"table" : @"linen"}]); - XCTAssertTrue( - [decodedRequest.customTargetingLists isEqualToDictionary:@{@"go" : @[ @"lakers" ]}]); + XCTAssertTrue([decodedRequest.customTargeting + isEqualToDictionary:@{@"table" : @"linen"}]); + XCTAssertTrue([decodedRequest.customTargetingLists + isEqualToDictionary:@{@"go" : @[ @"lakers" ]}]); XCTAssertTrue(decodedRequest.nonPersonalizedAds); XCTAssertEqualObjects(decodedRequest.neighboringContentURLs, contentURLs); XCTAssertEqualObjects(decodedRequest.pubProvidedID, @"pub-id"); - XCTAssertEqualObjects(decodedRequest.mediationExtrasIdentifier, @"identifier"); + XCTAssertEqualObjects(decodedRequest.mediationExtrasIdentifier, + @"identifier"); XCTAssertEqualObjects(decodedRequest.adMobExtras, @{@"key" : @"value"}); XCTAssertEqualObjects(decodedRequest.requestAgent, @"request-agent"); - XCTAssertEqualObjects(decodedRequest.mediationExtras[0].extras, @{@"test_key" : @"test_value"}); + XCTAssertEqualObjects(decodedRequest.mediationExtras[0].extras, + @{@"test_key" : @"test_value"}); } - (void)testEncodeDecodeRewardItem { - FLTRewardItem *item = [[FLTRewardItem alloc] initWithAmount:@(1) type:@"apple"]; + FLTRewardItem *item = [[FLTRewardItem alloc] initWithAmount:@(1) + type:@"apple"]; NSData *encodedMessage = [_messageCodec encode:item]; FLTRewardItem *decodedItem = [_messageCodec decode:encodedMessage]; @@ -305,36 +348,44 @@ - (void)testEncodeDecodeServerSideVerification { serverSideVerificationOptions.userIdentifier = @"user-id"; NSData *encodedMessage = [_messageCodec encode:serverSideVerificationOptions]; - FLTServerSideVerificationOptions *decoded = [_messageCodec decode:encodedMessage]; + FLTServerSideVerificationOptions *decoded = + [_messageCodec decode:encodedMessage]; XCTAssertEqualObjects(decoded.customRewardString, serverSideVerificationOptions.customRewardString); - XCTAssertEqualObjects(decoded.userIdentifier, serverSideVerificationOptions.userIdentifier); + XCTAssertEqualObjects(decoded.userIdentifier, + serverSideVerificationOptions.userIdentifier); // With customRewardString not defined. - serverSideVerificationOptions = [[FLTServerSideVerificationOptions alloc] init]; + serverSideVerificationOptions = + [[FLTServerSideVerificationOptions alloc] init]; serverSideVerificationOptions.userIdentifier = @"user-id"; encodedMessage = [_messageCodec encode:serverSideVerificationOptions]; decoded = [_messageCodec decode:encodedMessage]; XCTAssertEqualObjects(decoded.customRewardString, serverSideVerificationOptions.customRewardString); - XCTAssertEqualObjects(decoded.userIdentifier, serverSideVerificationOptions.userIdentifier); + XCTAssertEqualObjects(decoded.userIdentifier, + serverSideVerificationOptions.userIdentifier); // With userId not defined. - serverSideVerificationOptions = [[FLTServerSideVerificationOptions alloc] init]; + serverSideVerificationOptions = + [[FLTServerSideVerificationOptions alloc] init]; serverSideVerificationOptions.customRewardString = @"reward"; encodedMessage = [_messageCodec encode:serverSideVerificationOptions]; decoded = [_messageCodec decode:encodedMessage]; XCTAssertEqualObjects(decoded.customRewardString, serverSideVerificationOptions.customRewardString); - XCTAssertEqualObjects(decoded.userIdentifier, serverSideVerificationOptions.userIdentifier); + XCTAssertEqualObjects(decoded.userIdentifier, + serverSideVerificationOptions.userIdentifier); // Both undefined. - serverSideVerificationOptions = [[FLTServerSideVerificationOptions alloc] init]; + serverSideVerificationOptions = + [[FLTServerSideVerificationOptions alloc] init]; encodedMessage = [_messageCodec encode:serverSideVerificationOptions]; decoded = [_messageCodec decode:encodedMessage]; XCTAssertEqualObjects(decoded.customRewardString, serverSideVerificationOptions.customRewardString); - XCTAssertEqualObjects(decoded.userIdentifier, serverSideVerificationOptions.userIdentifier); + XCTAssertEqualObjects(decoded.userIdentifier, + serverSideVerificationOptions.userIdentifier); } - (void)testEncodeDecodeNSError { @@ -356,10 +407,13 @@ - (void)testEncodeDecodeFLTGADLoadError { NSString *identifier = @"test-identifier"; NSString *className = @"test-class-name"; OCMStub([mockResponseInfo responseIdentifier]).andReturn(identifier); - OCMStub(mockResponseInfo.loadedAdNetworkResponseInfo).andReturn(mockAdNetworkResponseInfo); + OCMStub(mockResponseInfo.loadedAdNetworkResponseInfo) + .andReturn(mockAdNetworkResponseInfo); OCMStub(mockAdNetworkResponseInfo.adNetworkClassName).andReturn(className); - NSDictionary *userInfo = - @{NSLocalizedDescriptionKey : @"message", GADErrorUserInfoKeyResponseInfo : mockResponseInfo}; + NSDictionary *userInfo = @{ + NSLocalizedDescriptionKey : @"message", + GADErrorUserInfoKeyResponseInfo : mockResponseInfo + }; NSError *error = [NSError errorWithDomain:@"domain" code:1 userInfo:userInfo]; FLTLoadAdError *loadAdError = [[FLTLoadAdError alloc] initWithError:error]; @@ -369,13 +423,16 @@ - (void)testEncodeDecodeFLTGADLoadError { XCTAssertEqual(decodedError.code, 1); XCTAssertEqualObjects(decodedError.domain, @"domain"); XCTAssertEqualObjects(decodedError.message, @"message"); - XCTAssertEqualObjects(decodedError.responseInfo.adNetworkClassName, className); - XCTAssertEqualObjects(decodedError.responseInfo.responseIdentifier, identifier); + XCTAssertEqualObjects(decodedError.responseInfo.adNetworkClassName, + className); + XCTAssertEqualObjects(decodedError.responseInfo.responseIdentifier, + identifier); XCTAssertTrue(decodedError.responseInfo.adNetworkInfoArray.count == 0); } - (void)testEncodeDecodeFLTGADLoadErrorWithResponseInfo { - GADAdNetworkResponseInfo *mockNetworkResponse = OCMClassMock([GADAdNetworkResponseInfo class]); + GADAdNetworkResponseInfo *mockNetworkResponse = + OCMClassMock([GADAdNetworkResponseInfo class]); OCMStub([mockNetworkResponse adNetworkClassName]).andReturn(@"adapter-class"); GADResponseInfo *mockResponseInfo = OCMClassMock([GADResponseInfo class]); @@ -384,11 +441,16 @@ - (void)testEncodeDecodeFLTGADLoadErrorWithResponseInfo { NSString *identifier = @"test-identifier"; NSString *className = @"test-class-name"; OCMStub([mockResponseInfo responseIdentifier]).andReturn(identifier); - OCMStub(mockResponseInfo.loadedAdNetworkResponseInfo).andReturn(mockAdNetworkResponseInfo); + OCMStub(mockResponseInfo.loadedAdNetworkResponseInfo) + .andReturn(mockAdNetworkResponseInfo); OCMStub(mockAdNetworkResponseInfo.adNetworkClassName).andReturn(className); - OCMStub([mockResponseInfo adNetworkInfoArray]).andReturn(@[ mockNetworkResponse ]); - NSDictionary *userInfo = - @{NSLocalizedDescriptionKey : @"message", GADErrorUserInfoKeyResponseInfo : mockResponseInfo}; + OCMStub([mockResponseInfo adNetworkInfoArray]).andReturn(@[ + mockNetworkResponse + ]); + NSDictionary *userInfo = @{ + NSLocalizedDescriptionKey : @"message", + GADErrorUserInfoKeyResponseInfo : mockResponseInfo + }; NSError *error = [NSError errorWithDomain:@"domain" code:1 userInfo:userInfo]; FLTLoadAdError *loadAdError = [[FLTLoadAdError alloc] initWithError:error]; @@ -398,10 +460,13 @@ - (void)testEncodeDecodeFLTGADLoadErrorWithResponseInfo { XCTAssertEqual(decodedError.code, 1); XCTAssertEqualObjects(decodedError.domain, @"domain"); XCTAssertEqualObjects(decodedError.message, @"message"); - XCTAssertEqualObjects(decodedError.responseInfo.adNetworkClassName, className); - XCTAssertEqualObjects(decodedError.responseInfo.responseIdentifier, identifier); + XCTAssertEqualObjects(decodedError.responseInfo.adNetworkClassName, + className); + XCTAssertEqualObjects(decodedError.responseInfo.responseIdentifier, + identifier); XCTAssertTrue(decodedError.responseInfo.adNetworkInfoArray.count == 1); - XCTAssertEqualObjects(decodedError.responseInfo.adNetworkInfoArray.firstObject.adNetworkClassName, + XCTAssertEqualObjects(decodedError.responseInfo.adNetworkInfoArray.firstObject + .adNetworkClassName, @"adapter-class"); } @@ -414,29 +479,38 @@ - (void)testEncodeDecodeFLTGADResponseInfo { OCMStub([error code]).andReturn(1); OCMStub([error localizedDescription]).andReturn(@"error"); - GADAdNetworkResponseInfo *mockGADResponseInfo = OCMClassMock([GADAdNetworkResponseInfo class]); + GADAdNetworkResponseInfo *mockGADResponseInfo = + OCMClassMock([GADAdNetworkResponseInfo class]); OCMStub([mockGADResponseInfo adNetworkClassName]).andReturn(@"adapter-class"); OCMStub([mockGADResponseInfo latency]).andReturn(123.1234); - OCMStub([mockGADResponseInfo dictionaryRepresentation]).andReturn(descriptionsDict); + OCMStub([mockGADResponseInfo dictionaryRepresentation]) + .andReturn(descriptionsDict); OCMStub([mockGADResponseInfo adUnitMapping]).andReturn(adUnitMappingsDict); OCMStub([mockGADResponseInfo error]).andReturn(error); GADAdNetworkResponseInfo *mockLoadedGADResponseInfo = OCMClassMock([GADAdNetworkResponseInfo class]); - OCMStub([mockLoadedGADResponseInfo adNetworkClassName]).andReturn(@"loaded-adapter"); + OCMStub([mockLoadedGADResponseInfo adNetworkClassName]) + .andReturn(@"loaded-adapter"); OCMStub([mockLoadedGADResponseInfo latency]).andReturn(123.1234); - OCMStub([mockLoadedGADResponseInfo dictionaryRepresentation]).andReturn(descriptionsDict); - OCMStub([mockLoadedGADResponseInfo adUnitMapping]).andReturn(adUnitMappingsDict); + OCMStub([mockLoadedGADResponseInfo dictionaryRepresentation]) + .andReturn(descriptionsDict); + OCMStub([mockLoadedGADResponseInfo adUnitMapping]) + .andReturn(adUnitMappingsDict); OCMStub([mockLoadedGADResponseInfo error]).andReturn(error); OCMStub([mockLoadedGADResponseInfo adSourceName]).andReturn(@"adSourceName"); OCMStub([mockLoadedGADResponseInfo adSourceID]).andReturn(@"adSourceID"); - OCMStub([mockLoadedGADResponseInfo adSourceInstanceName]).andReturn(@"adSourceInstanceName"); - OCMStub([mockLoadedGADResponseInfo adSourceInstanceID]).andReturn(@"adSourceInstanceID"); + OCMStub([mockLoadedGADResponseInfo adSourceInstanceName]) + .andReturn(@"adSourceInstanceName"); + OCMStub([mockLoadedGADResponseInfo adSourceInstanceID]) + .andReturn(@"adSourceInstanceID"); FLTGADAdNetworkResponseInfo *adNetworkResponseInfo = - [[FLTGADAdNetworkResponseInfo alloc] initWithResponseInfo:mockGADResponseInfo]; + [[FLTGADAdNetworkResponseInfo alloc] + initWithResponseInfo:mockGADResponseInfo]; FLTGADAdNetworkResponseInfo *loadedNetworkResponseInfo = - [[FLTGADAdNetworkResponseInfo alloc] initWithResponseInfo:mockLoadedGADResponseInfo]; + [[FLTGADAdNetworkResponseInfo alloc] + initWithResponseInfo:mockLoadedGADResponseInfo]; FLTGADResponseInfo *responseInfo = [[FLTGADResponseInfo alloc] init]; responseInfo.adNetworkClassName = @"class-name"; @@ -446,43 +520,55 @@ - (void)testEncodeDecodeFLTGADResponseInfo { responseInfo.extrasDictionary = @{@"key" : @"value"}; NSData *encodedMessage = [_messageCodec encode:responseInfo]; - FLTGADResponseInfo *decodedResponseInfo = [_messageCodec decode:encodedMessage]; + FLTGADResponseInfo *decodedResponseInfo = + [_messageCodec decode:encodedMessage]; XCTAssertEqualObjects(decodedResponseInfo.adNetworkClassName, @"class-name"); XCTAssertEqualObjects(decodedResponseInfo.responseIdentifier, @"identifier"); - XCTAssertEqualObjects(decodedResponseInfo.extrasDictionary, @{@"key" : @"value"}); + XCTAssertEqualObjects(decodedResponseInfo.extrasDictionary, + @{@"key" : @"value"}); XCTAssertEqual(decodedResponseInfo.adNetworkInfoArray.count, 1); - FLTGADAdNetworkResponseInfo *decodedInfo = decodedResponseInfo.adNetworkInfoArray.firstObject; + FLTGADAdNetworkResponseInfo *decodedInfo = + decodedResponseInfo.adNetworkInfoArray.firstObject; XCTAssertEqualObjects(decodedInfo.adNetworkClassName, @"adapter-class"); XCTAssertEqualObjects(decodedInfo.latency, @(123123)); - XCTAssertEqualObjects(decodedInfo.dictionaryDescription, @"{\n descriptions = dict;\n}"); + XCTAssertEqualObjects(decodedInfo.dictionaryDescription, + @"{\n descriptions = dict;\n}"); XCTAssertEqualObjects(decodedInfo.adUnitMapping, adUnitMappingsDict); XCTAssertEqual(decodedInfo.error.code, 1); XCTAssertEqualObjects(decodedInfo.error.domain, @"domain"); XCTAssertEqualObjects(decodedInfo.error.localizedDescription, @"error"); - FLTGADAdNetworkResponseInfo *decodedLoadedInfo = decodedResponseInfo.loadedAdNetworkResponseInfo; - XCTAssertEqualObjects(decodedLoadedInfo.adNetworkClassName, @"loaded-adapter"); + FLTGADAdNetworkResponseInfo *decodedLoadedInfo = + decodedResponseInfo.loadedAdNetworkResponseInfo; + XCTAssertEqualObjects(decodedLoadedInfo.adNetworkClassName, + @"loaded-adapter"); XCTAssertEqualObjects(decodedLoadedInfo.latency, @(123123)); - XCTAssertEqualObjects(decodedLoadedInfo.dictionaryDescription, @"{\n descriptions = dict;\n}"); + XCTAssertEqualObjects(decodedLoadedInfo.dictionaryDescription, + @"{\n descriptions = dict;\n}"); XCTAssertEqualObjects(decodedLoadedInfo.adUnitMapping, adUnitMappingsDict); XCTAssertEqual(decodedLoadedInfo.error.code, 1); XCTAssertEqualObjects(decodedLoadedInfo.error.domain, @"domain"); XCTAssertEqualObjects(decodedLoadedInfo.error.localizedDescription, @"error"); XCTAssertEqualObjects(decodedLoadedInfo.adSourceName, @"adSourceName"); XCTAssertEqualObjects(decodedLoadedInfo.adSourceID, @"adSourceID"); - XCTAssertEqualObjects(decodedLoadedInfo.adSourceInstanceName, @"adSourceInstanceName"); - XCTAssertEqualObjects(decodedLoadedInfo.adSourceInstanceID, @"adSourceInstanceID"); + XCTAssertEqualObjects(decodedLoadedInfo.adSourceInstanceName, + @"adSourceInstanceName"); + XCTAssertEqualObjects(decodedLoadedInfo.adSourceInstanceID, + @"adSourceInstanceID"); } - (void)testEncodeDecodeFLTGADLoadErrorWithEmptyValues { GADResponseInfo *mockResponseInfo = OCMClassMock([GADResponseInfo class]); OCMStub([mockResponseInfo responseIdentifier]).andReturn(nil); - OCMStub([mockResponseInfo.loadedAdNetworkResponseInfo adNetworkClassName]).andReturn(nil); - NSDictionary *userInfo = - @{NSLocalizedDescriptionKey : @"message", GADErrorUserInfoKeyResponseInfo : mockResponseInfo}; + OCMStub([mockResponseInfo.loadedAdNetworkResponseInfo adNetworkClassName]) + .andReturn(nil); + NSDictionary *userInfo = @{ + NSLocalizedDescriptionKey : @"message", + GADErrorUserInfoKeyResponseInfo : mockResponseInfo + }; NSError *error = [NSError errorWithDomain:@"domain" code:1 userInfo:userInfo]; FLTLoadAdError *loadAdError = [[FLTLoadAdError alloc] initWithError:error]; @@ -516,7 +602,8 @@ - (void)testEncodeDecodeInitializationStatus { NSData *encodedMessage = [_messageCodec encode:status]; - FLTInitializationStatus *decodedStatus = [_messageCodec decode:encodedMessage]; + FLTInitializationStatus *decodedStatus = + [_messageCodec decode:encodedMessage]; XCTAssertEqual(decodedStatus.adapterStatuses.count, 1); XCTAssertEqualObjects(decodedStatus.adapterStatuses.allKeys[0], @"name"); XCTAssertNil(decodedStatus.adapterStatuses.allValues[0].state); @@ -525,10 +612,12 @@ - (void)testEncodeDecodeInitializationStatus { } - (void)testEncodeDecodeNativeTemplateType { - FLTNativeTemplateType *templateType = [[FLTNativeTemplateType alloc] initWithInt:1]; + FLTNativeTemplateType *templateType = + [[FLTNativeTemplateType alloc] initWithInt:1]; NSData *encodedMessage = [_messageCodec encode:templateType]; - FLTNativeTemplateType *decodedTemplateType = [_messageCodec decode:encodedMessage]; + FLTNativeTemplateType *decodedTemplateType = + [_messageCodec decode:encodedMessage]; [self assertEqualTemplateTypes:templateType second:decodedTemplateType]; } @@ -537,15 +626,17 @@ - (void)testEncodeDecodeNativeTemplateFontStyle { [[FLTNativeTemplateFontStyleWrapper alloc] initWithInt:2]; NSData *encodedMessage = [_messageCodec encode:fontStyle]; - FLTNativeTemplateFontStyleWrapper *decoded = [_messageCodec decode:encodedMessage]; + FLTNativeTemplateFontStyleWrapper *decoded = + [_messageCodec decode:encodedMessage]; [self assertEqualTemplateFontStyles:fontStyle second:decoded]; } - (void)testEncodeDecodeNativeTemplateColor { - FLTNativeTemplateColor *color = [[FLTNativeTemplateColor alloc] initWithAlpha:@2.0f - red:@3.0f - green:@4.0f - blue:@5.0f]; + FLTNativeTemplateColor *color = + [[FLTNativeTemplateColor alloc] initWithAlpha:@2.0f + red:@3.0f + green:@4.0f + blue:@5.0f]; NSData *encodedMessage = [_messageCodec encode:color]; FLTNativeTemplateColor *decoded = [_messageCodec decode:encodedMessage]; @@ -553,14 +644,16 @@ - (void)testEncodeDecodeNativeTemplateColor { } - (void)testEncodeDecodeNativeTemplateTextStyle { - FLTNativeTemplateColor *textColor = [[FLTNativeTemplateColor alloc] initWithAlpha:@2.0f - red:@3.0f - green:@4.0f - blue:@5.0f]; - FLTNativeTemplateColor *backgroundColor = [[FLTNativeTemplateColor alloc] initWithAlpha:@6.0f - red:@7.0f - green:@8.0f - blue:@9.0f]; + FLTNativeTemplateColor *textColor = + [[FLTNativeTemplateColor alloc] initWithAlpha:@2.0f + red:@3.0f + green:@4.0f + blue:@5.0f]; + FLTNativeTemplateColor *backgroundColor = + [[FLTNativeTemplateColor alloc] initWithAlpha:@6.0f + red:@7.0f + green:@8.0f + blue:@9.0f]; FLTNativeTemplateFontStyleWrapper *fontStyle = [[FLTNativeTemplateFontStyleWrapper alloc] initWithInt:1]; @@ -576,18 +669,24 @@ - (void)testEncodeDecodeNativeTemplateTextStyle { } - (void)testEncodeDecodeNativeTemplateStyle { - FLTNativeTemplateType *templateType = [[FLTNativeTemplateType alloc] initWithInt:0]; + FLTNativeTemplateType *templateType = + [[FLTNativeTemplateType alloc] initWithInt:0]; FLTNativeTemplateColor *mainBackgroundColor = - [[FLTNativeTemplateColor alloc] initWithAlpha:@2.0f red:@3.0f green:@4.0f blue:@5.0f]; - - FLTNativeTemplateColor *ctaTextColor = [[FLTNativeTemplateColor alloc] initWithAlpha:@2.0f - red:@3.0f - green:@4.0f - blue:@5.0f]; - FLTNativeTemplateColor *ctaBackgroundColor = [[FLTNativeTemplateColor alloc] initWithAlpha:@6.0f - red:@7.0f - green:@8.0f - blue:@9.0f]; + [[FLTNativeTemplateColor alloc] initWithAlpha:@2.0f + red:@3.0f + green:@4.0f + blue:@5.0f]; + + FLTNativeTemplateColor *ctaTextColor = + [[FLTNativeTemplateColor alloc] initWithAlpha:@2.0f + red:@3.0f + green:@4.0f + blue:@5.0f]; + FLTNativeTemplateColor *ctaBackgroundColor = + [[FLTNativeTemplateColor alloc] initWithAlpha:@6.0f + red:@7.0f + green:@8.0f + blue:@9.0f]; FLTNativeTemplateFontStyleWrapper *ctaFontStyle = [[FLTNativeTemplateFontStyleWrapper alloc] initWithInt:1]; @@ -608,10 +707,11 @@ - (void)testEncodeDecodeNativeTemplateStyle { fontStyle:nil size:@30.0f]; - FLTNativeTemplateColor *tertiaryTextColor = [[FLTNativeTemplateColor alloc] initWithAlpha:@12.0f - red:@13.0f - green:@14.0f - blue:@15.0f]; + FLTNativeTemplateColor *tertiaryTextColor = + [[FLTNativeTemplateColor alloc] initWithAlpha:@12.0f + red:@13.0f + green:@14.0f + blue:@15.0f]; FLTNativeTemplateTextStyle *tertiaryTextStyle = [[FLTNativeTemplateTextStyle alloc] initWithTextColor:tertiaryTextColor backgroundColor:nil @@ -630,13 +730,20 @@ - (void)testEncodeDecodeNativeTemplateStyle { NSData *encodedMessage = [_messageCodec encode:style]; FLTNativeTemplateStyle *decoded = [_messageCodec decode:encodedMessage]; - [self assertEqualTemplateTypes:style.templateType second:decoded.templateType]; - [self assertEqualTemplateColors:style.mainBackgroundColor second:decoded.mainBackgroundColor]; - [self assertEqualTextStyles:style.callToActionStyle second:decoded.callToActionStyle]; - [self assertEqualTextStyles:style.primaryTextStyle second:decoded.primaryTextStyle]; - [self assertEqualTextStyles:style.secondaryTextStyle second:decoded.secondaryTextStyle]; - [self assertEqualTextStyles:style.tertiaryTextStyle second:decoded.tertiaryTextStyle]; - XCTAssertEqual(style.cornerRadius.floatValue, decoded.cornerRadius.floatValue); + [self assertEqualTemplateTypes:style.templateType + second:decoded.templateType]; + [self assertEqualTemplateColors:style.mainBackgroundColor + second:decoded.mainBackgroundColor]; + [self assertEqualTextStyles:style.callToActionStyle + second:decoded.callToActionStyle]; + [self assertEqualTextStyles:style.primaryTextStyle + second:decoded.primaryTextStyle]; + [self assertEqualTextStyles:style.secondaryTextStyle + second:decoded.secondaryTextStyle]; + [self assertEqualTextStyles:style.tertiaryTextStyle + second:decoded.tertiaryTextStyle]; + XCTAssertEqual(style.cornerRadius.floatValue, + decoded.cornerRadius.floatValue); } #pragma mark - Helper methods to compare native templates types @@ -644,14 +751,16 @@ - (void)testEncodeDecodeNativeTemplateStyle { - (void)assertEqualTextStyles:(FLTNativeTemplateTextStyle *)first second:(FLTNativeTemplateTextStyle *)second { [self assertEqualTemplateColors:first.textColor second:second.textColor]; - [self assertEqualTemplateColors:first.backgroundColor second:second.backgroundColor]; + [self assertEqualTemplateColors:first.backgroundColor + second:second.backgroundColor]; XCTAssertEqual(first.fontStyle.intValue, second.fontStyle.intValue); XCTAssertEqual(first.size.floatValue, second.size.floatValue); } - (void)assertEqualTemplateFontStyles:(FLTNativeTemplateFontStyleWrapper *)first - second:(FLTNativeTemplateFontStyleWrapper *)second { + second: + (FLTNativeTemplateFontStyleWrapper *)second { XCTAssertEqual(first.intValue, second.intValue); } @@ -687,7 +796,8 @@ - (GADAdSize)landscapeAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *)width { return GADAdSizeFromCGSize(CGSizeMake(width.doubleValue, 0)); } -- (GADAdSize)currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *)width { +- (GADAdSize)currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth: + (NSNumber *)width { return GADAdSizeFromCGSize(CGSizeMake(width.doubleValue, 0)); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m index fbebd24e7..5cccc781f 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m @@ -35,19 +35,20 @@ @implementation FLTGoogleMobileAdsTest { - (void)setUp { _mockMessenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger)); - _manager = [[FLTAdInstanceManager alloc] initWithBinaryMessenger:_mockMessenger]; + _manager = + [[FLTAdInstanceManager alloc] initWithBinaryMessenger:_mockMessenger]; _methodCodec = [FlutterStandardMethodCodec codecWithReaderWriter:[[FLTGoogleMobileAdsReaderWriter alloc] init]]; } - (void)testAdInstanceManagerLoadAd { FLTAdSize *size = [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)]; - FLTBannerAd *bannerAd = - [[FLTBannerAd alloc] initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@1]; + FLTBannerAd *bannerAd = [[FLTBannerAd alloc] + initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@1]; FLTBannerAd *mockBannerAd = OCMPartialMock(bannerAd); OCMStub([mockBannerAd load]); @@ -61,12 +62,12 @@ - (void)testAdInstanceManagerLoadAd { - (void)testAdInstanceManagerDisposeAd { FLTAdSize *size = [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)]; - FLTBannerAd *bannerAd = - [[FLTBannerAd alloc] initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@1]; + FLTBannerAd *bannerAd = [[FLTBannerAd alloc] + initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@1]; FLTBannerAd *mockBannerAd = OCMPartialMock(bannerAd); OCMStub([mockBannerAd load]); @@ -79,21 +80,21 @@ - (void)testAdInstanceManagerDisposeAd { - (void)testAdInstanceManagerDisposeAllAds { FLTAdSize *size = [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)]; - FLTBannerAd *bannerAd1 = - [[FLTBannerAd alloc] initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@1]; + FLTBannerAd *bannerAd1 = [[FLTBannerAd alloc] + initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@1]; FLTBannerAd *mockBannerAd1 = OCMPartialMock(bannerAd1); OCMStub([mockBannerAd1 load]); - FLTBannerAd *bannerAd2 = - [[FLTBannerAd alloc] initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@2]; + FLTBannerAd *bannerAd2 = [[FLTBannerAd alloc] + initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@2]; FLTBannerAd *mockBannerAd2 = OCMPartialMock(bannerAd2); OCMStub([mockBannerAd2 load]); @@ -108,15 +109,15 @@ - (void)testAdInstanceManagerDisposeAllAds { } - (void)testAdInstanceManagerOnAdLoaded { - FLTNativeAd *ad = - [[FLTNativeAd alloc] initWithAdUnitId:@"testAdUnitId" - request:[[FLTAdRequest alloc] init] - nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) - customOptions:nil - rootViewController:OCMClassMock([UIViewController class]) - adId:@1 - nativeAdOptions:nil - nativeTemplateStyle:nil]; + FLTNativeAd *ad = [[FLTNativeAd alloc] + initWithAdUnitId:@"testAdUnitId" + request:[[FLTAdRequest alloc] init] + nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) + customOptions:nil + rootViewController:OCMClassMock([UIViewController class]) + adId:@1 + nativeAdOptions:nil + nativeTemplateStyle:nil]; [_manager loadAd:ad]; GADResponseInfo *responseInfo = OCMClassMock([GADResponseInfo class]); @@ -124,25 +125,26 @@ - (void)testAdInstanceManagerOnAdLoaded { [[FLTGADResponseInfo alloc] initWithResponseInfo:responseInfo]; [_manager onAdLoaded:ad responseInfo:responseInfo]; NSData *data = [_methodCodec - encodeMethodCall:[FlutterMethodCall methodCallWithMethodName:@"onAdEvent" - arguments:@{ - @"adId" : @1, - @"eventName" : @"onAdLoaded", - @"responseInfo" : fltResponseInfo, - }]]; + encodeMethodCall:[FlutterMethodCall + methodCallWithMethodName:@"onAdEvent" + arguments:@{ + @"adId" : @1, + @"eventName" : @"onAdLoaded", + @"responseInfo" : fltResponseInfo, + }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); } - (void)testAdInstanceManagerOnAdFailedToLoad { - FLTNativeAd *ad = - [[FLTNativeAd alloc] initWithAdUnitId:@"testAdUnitId" - request:[[FLTAdRequest alloc] init] - nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) - customOptions:nil - rootViewController:OCMClassMock([UIViewController class]) - adId:@1 - nativeAdOptions:nil - nativeTemplateStyle:nil]; + FLTNativeAd *ad = [[FLTNativeAd alloc] + initWithAdUnitId:@"testAdUnitId" + request:[[FLTAdRequest alloc] init] + nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) + customOptions:nil + rootViewController:OCMClassMock([UIViewController class]) + adId:@1 + nativeAdOptions:nil + nativeTemplateStyle:nil]; [_manager loadAd:ad]; NSDictionary *userInfo = @{NSLocalizedDescriptionKey : @"message"}; @@ -151,12 +153,13 @@ - (void)testAdInstanceManagerOnAdFailedToLoad { FLTLoadAdError *loadAdError = [[FLTLoadAdError alloc] initWithError:error]; [_manager onAdFailedToLoad:ad error:error]; NSData *data = [_methodCodec - encodeMethodCall:[FlutterMethodCall methodCallWithMethodName:@"onAdEvent" - arguments:@{ - @"adId" : @1, - @"eventName" : @"onAdFailedToLoad", - @"loadAdError" : loadAdError, - }]]; + encodeMethodCall:[FlutterMethodCall + methodCallWithMethodName:@"onAdEvent" + arguments:@{ + @"adId" : @1, + @"eventName" : @"onAdFailedToLoad", + @"loadAdError" : loadAdError, + }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); } @@ -174,44 +177,50 @@ - (void)testAdInstanceManagerOnAdFailedToShow { methodCallWithMethodName:@"onAdEvent" arguments:@{ @"adId" : @1, - @"eventName" : @"didFailToPresentFullScreenCon" - @"tentWithError", + @"eventName" : + @"didFailToPresentFullScreenCon" + @"tentWithError", @"error" : error, }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); } - (void)testAdInstanceManagerOnAppEvent { - FLTNativeAd *ad = - [[FLTNativeAd alloc] initWithAdUnitId:@"testAdUnitId" - request:[[FLTAdRequest alloc] init] - nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) - customOptions:nil - rootViewController:OCMClassMock([UIViewController class]) - adId:@1 - nativeAdOptions:nil - nativeTemplateStyle:nil]; - FlutterMethodChannel *mockMethodChannel = OCMClassMock([FlutterMethodChannel class]); + FLTNativeAd *ad = [[FLTNativeAd alloc] + initWithAdUnitId:@"testAdUnitId" + request:[[FLTAdRequest alloc] init] + nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) + customOptions:nil + rootViewController:OCMClassMock([UIViewController class]) + adId:@1 + nativeAdOptions:nil + nativeTemplateStyle:nil]; + FlutterMethodChannel *mockMethodChannel = + OCMClassMock([FlutterMethodChannel class]); [_manager setValue:mockMethodChannel forKey:@"_channel"]; [_manager loadAd:ad]; [_manager onAppEvent:ad name:@"color" data:@"red"]; - NSDictionary *arguments = - @{@"adId" : @1, @"eventName" : @"onAppEvent", @"name" : @"color", @"data" : @"red"}; + NSDictionary *arguments = @{ + @"adId" : @1, + @"eventName" : @"onAppEvent", + @"name" : @"color", + @"data" : @"red" + }; OCMVerify([mockMethodChannel invokeMethod:@"onAdEvent" arguments:arguments]); } - (void)testAdInstanceManagerOnNativeAdEvents { - FLTNativeAd *ad = - [[FLTNativeAd alloc] initWithAdUnitId:@"testAdUnitId" - request:[[FLTAdRequest alloc] init] - nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) - customOptions:nil - rootViewController:OCMClassMock([UIViewController class]) - adId:@1 - nativeAdOptions:nil - nativeTemplateStyle:nil]; + FLTNativeAd *ad = [[FLTNativeAd alloc] + initWithAdUnitId:@"testAdUnitId" + request:[[FLTAdRequest alloc] init] + nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) + customOptions:nil + rootViewController:OCMClassMock([UIViewController class]) + adId:@1 + nativeAdOptions:nil + nativeTemplateStyle:nil]; [_manager loadAd:ad]; [_manager adDidRecordClick:ad]; @@ -219,78 +228,89 @@ - (void)testAdInstanceManagerOnNativeAdEvents { OCMVerify([_mockMessenger sendOnChannel:channel message:clickData]); [_manager onNativeAdImpression:ad]; - NSData *impressionData = [self getDataForEvent:@"onNativeAdImpression" adId:@1]; + NSData *impressionData = [self getDataForEvent:@"onNativeAdImpression" + adId:@1]; OCMVerify([_mockMessenger sendOnChannel:channel message:impressionData]); [_manager onNativeAdWillPresentScreen:ad]; - NSData *presentScreenData = [self getDataForEvent:@"onNativeAdWillPresentScreen" adId:@1]; + NSData *presentScreenData = + [self getDataForEvent:@"onNativeAdWillPresentScreen" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:presentScreenData])); [_manager onNativeAdDidDismissScreen:ad]; - NSData *didDismissData = [self getDataForEvent:@"onNativeAdDidDismissScreen" adId:@1]; + NSData *didDismissData = [self getDataForEvent:@"onNativeAdDidDismissScreen" + adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didDismissData])); [_manager onNativeAdWillDismissScreen:ad]; - NSData *willDismissData = [self getDataForEvent:@"onNativeAdWillDismissScreen" adId:@1]; + NSData *willDismissData = [self getDataForEvent:@"onNativeAdWillDismissScreen" + adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:willDismissData])); } - (void)testAdInstanceManagerOnRewardedAdUserEarnedReward { - FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + FLTRewardedAd *ad = [[FLTRewardedAd alloc] + initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager loadAd:ad]; [_manager onRewardedAdUserEarnedReward:ad - reward:[[FLTRewardItem alloc] initWithAmount:@(1) type:@"type"]]; + reward:[[FLTRewardItem alloc] + initWithAmount:@(1) + type:@"type"]]; NSData *data = [_methodCodec encodeMethodCall:[FlutterMethodCall methodCallWithMethodName:@"onAdEvent" arguments:@{ @"adId" : @1, - @"eventName" : @"onRewardedAdUserEarnedReward", + @"eventName" : + @"onRewardedAdUserEarnedReward", @"rewardItem" : - [[FLTRewardItem alloc] initWithAmount:@(1) - type:@"type"] + [[FLTRewardItem alloc] + initWithAmount:@(1) + type:@"type"] }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); } - (void)testAdInstanceManagerOnRewardedInterstitialAdUserEarnedReward { - FLTRewardedInterstitialAd *ad = - [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] + initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager loadAd:ad]; [_manager onRewardedInterstitialAdUserEarnedReward:ad - reward:[[FLTRewardItem alloc] initWithAmount:@(1) - type:@"type"]]; + reward:[[FLTRewardItem alloc] + initWithAmount:@(1) + type:@"type"]]; NSData *data = [_methodCodec - encodeMethodCall:[FlutterMethodCall - methodCallWithMethodName:@"onAdEvent" - arguments:@{ - @"adId" : @1, - @"eventName" : - @"onRewardedInterstitialAdUserEarnedReward", - @"rewardItem" : - [[FLTRewardItem alloc] initWithAmount:@(1) - type:@"type"] - }]]; + encodeMethodCall: + [FlutterMethodCall + methodCallWithMethodName:@"onAdEvent" + arguments:@{ + @"adId" : @1, + @"eventName" : + @"onRewardedInterstitialAdUserEarnedReward", + @"rewardItem" : [[FLTRewardItem alloc] + initWithAmount:@(1) + type:@"type"] + }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); } - (void)testAdInstanceManagerOnPaidEvent { - FLTNativeAd *ad = - [[FLTNativeAd alloc] initWithAdUnitId:@"testAdUnitId" - request:[[FLTAdRequest alloc] init] - nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) - customOptions:nil - rootViewController:OCMClassMock([UIViewController class]) - adId:@1 - nativeAdOptions:nil - nativeTemplateStyle:nil]; + FLTNativeAd *ad = [[FLTNativeAd alloc] + initWithAdUnitId:@"testAdUnitId" + request:[[FLTAdRequest alloc] init] + nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) + customOptions:nil + rootViewController:OCMClassMock([UIViewController class]) + adId:@1 + nativeAdOptions:nil + nativeTemplateStyle:nil]; [_manager loadAd:ad]; NSDecimalNumber *valueDecimal = [[NSDecimalNumber alloc] initWithInt:1]; @@ -306,7 +326,8 @@ - (void)testAdInstanceManagerOnPaidEvent { @"adId" : @1, @"eventName" : @"onPaidEvent", @"valueMicros" : value.valueMicros, - @"precision" : [NSNumber numberWithInteger:12], + @"precision" : + [NSNumber numberWithInteger:12], @"currencyCode" : @"code" }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); @@ -314,11 +335,12 @@ - (void)testAdInstanceManagerOnPaidEvent { - (void)testBannerEvents { FLTAdSize *size = [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)]; - FLTBannerAd *ad = [[FLTBannerAd alloc] initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@1]; + FLTBannerAd *ad = [[FLTBannerAd alloc] + initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@1]; FLTBannerAd *mockBannerAd = OCMPartialMock(ad); OCMStub([mockBannerAd load]); @@ -329,73 +351,86 @@ - (void)testBannerEvents { OCMVerify(([_mockMessenger sendOnChannel:channel message:impressionData])); [_manager onBannerWillDismissScreen:ad]; - NSData *willDismissData = [self getDataForEvent:@"onBannerWillDismissScreen" adId:@1]; + NSData *willDismissData = [self getDataForEvent:@"onBannerWillDismissScreen" + adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:willDismissData])); [_manager onBannerDidDismissScreen:ad]; - NSData *didDismissData = [self getDataForEvent:@"onBannerDidDismissScreen" adId:@1]; + NSData *didDismissData = [self getDataForEvent:@"onBannerDidDismissScreen" + adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didDismissData])); [_manager onBannerWillPresentScreen:ad]; - NSData *willPresentData = [self getDataForEvent:@"onBannerWillPresentScreen" adId:@1]; + NSData *willPresentData = [self getDataForEvent:@"onBannerWillPresentScreen" + adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:willPresentData])); } - (void)testFullScreenEventsRewardedAd { - FLTRewardedAd *rewardedAd = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + FLTRewardedAd *rewardedAd = [[FLTRewardedAd alloc] + initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager loadAd:rewardedAd]; [_manager adWillPresentFullScreenContent:rewardedAd]; - NSData *didPresentData = [self getDataForEvent:@"adWillPresentFullScreenContent" adId:@1]; + NSData *didPresentData = + [self getDataForEvent:@"adWillPresentFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didPresentData])); [_manager adDidDismissFullScreenContent:rewardedAd]; - NSData *didDismissData = [self getDataForEvent:@"adDidDismissFullScreenContent" adId:@1]; + NSData *didDismissData = + [self getDataForEvent:@"adDidDismissFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didDismissData])); [_manager adWillDismissFullScreenContent:rewardedAd]; - NSData *willDismissData = [self getDataForEvent:@"adWillDismissFullScreenContent" adId:@1]; + NSData *willDismissData = + [self getDataForEvent:@"adWillDismissFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:willDismissData])); [_manager adDidRecordImpression:rewardedAd]; - NSData *impressionData = [self getDataForEvent:@"adDidRecordImpression" adId:@1]; + NSData *impressionData = [self getDataForEvent:@"adDidRecordImpression" + adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:impressionData])); } - (void)testFullScreenEventsRewardedInterstitialAd { FLTRewardedInterstitialAd *rewardedInterstitialAd = - [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + [[FLTRewardedInterstitialAd alloc] + initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager loadAd:rewardedInterstitialAd]; [_manager adWillPresentFullScreenContent:rewardedInterstitialAd]; - NSData *didPresentData = [self getDataForEvent:@"adWillPresentFullScreenContent" adId:@1]; + NSData *didPresentData = + [self getDataForEvent:@"adWillPresentFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didPresentData])); [_manager adDidDismissFullScreenContent:rewardedInterstitialAd]; - NSData *didDismissData = [self getDataForEvent:@"adDidDismissFullScreenContent" adId:@1]; + NSData *didDismissData = + [self getDataForEvent:@"adDidDismissFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didDismissData])); [_manager adWillDismissFullScreenContent:rewardedInterstitialAd]; - NSData *willDismissData = [self getDataForEvent:@"adWillDismissFullScreenContent" adId:@1]; + NSData *willDismissData = + [self getDataForEvent:@"adWillDismissFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:willDismissData])); [_manager adDidRecordImpression:rewardedInterstitialAd]; - NSData *impressionData = [self getDataForEvent:@"adDidRecordImpression" adId:@1]; + NSData *impressionData = [self getDataForEvent:@"adDidRecordImpression" + adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:impressionData])); } - (void)testEventSentForDisposedAd { FLTAdSize *size = [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)]; - FLTBannerAd *bannerAd = - [[FLTBannerAd alloc] initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@1]; + FLTBannerAd *bannerAd = [[FLTBannerAd alloc] + initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@1]; FLTBannerAd *mockBannerAd = OCMPartialMock(bannerAd); OCMStub([mockBannerAd load]); @@ -415,16 +450,19 @@ - (void)testEventSentForDisposedAd { // Helper method to create encoded data for an event and ad id. - (NSData *)getDataForEvent:(NSString *)name adId:(NSNumber *)adId { return [_methodCodec - encodeMethodCall:[FlutterMethodCall - methodCallWithMethodName:@"onAdEvent" - arguments:@{@"adId" : @1, @"eventName" : name}]]; + encodeMethodCall:[FlutterMethodCall methodCallWithMethodName:@"onAdEvent" + arguments:@{ + @"adId" : @1, + @"eventName" : name + }]]; } - (void)testAdClick { FLTRewardedInterstitialAd *rewardedInterstitialAd = - [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + [[FLTRewardedInterstitialAd alloc] + initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager adDidRecordClick:rewardedInterstitialAd]; NSData *impressionData = [self getDataForEvent:@"adDidRecordClick" adId:@1]; diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m index 6b4bf4654..02819d7f3 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m @@ -35,10 +35,12 @@ - (void)testLoadShowInterstitialAd { GADRequest *gadRequest = OCMClassMock([GADRequest class]); OCMStub([request asGADRequest:[OCMArg any]]).andReturn(gadRequest); - UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); - FLTInterstitialAd *ad = [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + UIViewController *mockRootViewController = + OCMClassMock([UIViewController class]); + FLTInterstitialAd *ad = + [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id interstitialClassMock = OCMClassMock([GADInterstitialAd class]); @@ -61,7 +63,8 @@ - (void)testLoadShowInterstitialAd { [delegate adDidDismissFullScreenContent:interstitialClassMock]; [delegate adWillPresentFullScreenContent:interstitialClassMock]; [delegate adWillDismissFullScreenContent:interstitialClassMock]; - [delegate ad:interstitialClassMock didFailToPresentFullScreenContentWithError:error]; + [delegate ad:interstitialClassMock + didFailToPresentFullScreenContentWithError:error]; }); GADResponseInfo *mockResponseInfo = OCMClassMock([GADResponseInfo class]); @@ -72,31 +75,35 @@ - (void)testLoadShowInterstitialAd { OCMStub([adValue value]).andReturn(NSDecimalNumber.one); OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated); OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); - OCMStub([interstitialClassMock setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - GADPaidEventHandler handler = obj; - handler(adValue); - return YES; - }]]); + OCMStub([interstitialClassMock + setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + GADPaidEventHandler handler = obj; + handler(adValue); + return YES; + }]]); // Call load and verify interactions with mocks. [ad load]; - OCMVerify(ClassMethod([interstitialClassMock loadWithAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadRequest] - completionHandler:[OCMArg any]])); + OCMVerify(ClassMethod([interstitialClassMock + loadWithAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadRequest] + completionHandler:[OCMArg any]])); OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad] responseInfo:[OCMArg isEqual:mockResponseInfo]]); - OCMVerify([interstitialClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); + OCMVerify( + [interstitialClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); XCTAssertEqual(ad.interstitial, interstitialClassMock); - OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager + onPaidEvent:[OCMArg isEqual:ad] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); // Show the ad [ad showFromRootViewController:mockRootViewController]; @@ -110,8 +117,9 @@ - (void)testLoadShowInterstitialAd { OCMVerify([mockManager adWillDismissFullScreenContent:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordImpression:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:ad]]); - OCMVerify([mockManager didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager + didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); } - (void)testFailedToLoad { @@ -120,9 +128,10 @@ - (void)testFailedToLoad { GADRequest *gadRequest = OCMClassMock([GADRequest class]); OCMStub([request asGADRequest:[OCMArg any]]).andReturn(gadRequest); - FLTInterstitialAd *ad = [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + FLTInterstitialAd *ad = + [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id interstitialClassMock = OCMClassMock([GADInterstitialAd class]); @@ -138,10 +147,12 @@ - (void)testFailedToLoad { [ad load]; - OCMVerify(ClassMethod([interstitialClassMock loadWithAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadRequest] - completionHandler:[OCMArg any]])); - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]); + OCMVerify(ClassMethod([interstitialClassMock + loadWithAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadRequest] + completionHandler:[OCMArg any]])); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTNativeAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTNativeAdTest.m index b9b4371c0..4c3b8cb29 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTNativeAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTNativeAdTest.m @@ -39,14 +39,18 @@ - (void)testLoadNativeAd { - (void)testLoadNativeAdWithGAMRequest { FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init]; request.keywords = @[ @"apple" ]; - [self testLoadNativeAd:request customOptions:OCMClassMock([NSDictionary class])]; + [self testLoadNativeAd:request + customOptions:OCMClassMock([NSDictionary class])]; } - (void)testLoadNativeAd:(FLTAdRequest *)gadOrGAMRequest - customOptions:(NSDictionary *_Nullable)customOptions { + customOptions: + (NSDictionary *_Nullable)customOptions { id mockNativeAdFactory = OCMProtocolMock(@protocol(FLTNativeAdFactory)); - FLTNativeAdOptions *mockNativeAdOptions = OCMClassMock([FLTNativeAdOptions class]); - GADAdLoaderOptions *mockGADAdLoaderOptions = OCMClassMock([GADAdLoaderOptions class]); + FLTNativeAdOptions *mockNativeAdOptions = + OCMClassMock([FLTNativeAdOptions class]); + GADAdLoaderOptions *mockGADAdLoaderOptions = + OCMClassMock([GADAdLoaderOptions class]); OCMStub([mockNativeAdOptions asGADAdLoaderOptions]) .andReturn([NSArray arrayWithObject:mockGADAdLoaderOptions]); UIViewController *mockViewController = OCMClassMock([UIViewController class]); @@ -72,7 +76,8 @@ - (void)testLoadNativeAd:(FLTAdRequest *)gadOrGAMRequest OCMVerify([mockLoader loadRequest:[OCMArg checkWithBlock:^BOOL(id obj) { GADRequest *requestArg = obj; - return [requestArg.keywords isEqualToArray:@[ @"apple" ]]; + return [requestArg.keywords + isEqualToArray:@[ @"apple" ]]; }]]); // Check that nil is used instead of null when customOptions is Null @@ -81,36 +86,41 @@ - (void)testLoadNativeAd:(FLTAdRequest *)gadOrGAMRequest OCMStub([mockGADNativeAd responseInfo]).andReturn(mockResponseInfo); [ad adLoader:mockLoader didReceiveNativeAd:mockGADNativeAd]; if ([NSNull.null isEqual:customOptions] || customOptions == nil) { - OCMVerify([mockNativeAdFactory createNativeAd:mockGADNativeAd customOptions:[OCMArg isNil]]); - } else { OCMVerify([mockNativeAdFactory createNativeAd:mockGADNativeAd - customOptions:[OCMArg isEqual:customOptions]]); + customOptions:[OCMArg isNil]]); + } else { + OCMVerify([mockNativeAdFactory + createNativeAd:mockGADNativeAd + customOptions:[OCMArg isEqual:customOptions]]); } - OCMStub([mockGADNativeAd setDelegate:[OCMArg checkWithBlock:^BOOL(id obj) { - id delegate = obj; - [delegate nativeAdDidRecordClick:mockGADNativeAd]; - [delegate nativeAdDidRecordImpression:mockGADNativeAd]; - [delegate nativeAdWillPresentScreen:mockGADNativeAd]; - [delegate nativeAdDidDismissScreen:mockGADNativeAd]; - [delegate nativeAdWillDismissScreen:mockGADNativeAd]; - return YES; - }]]); + OCMStub( + [mockGADNativeAd setDelegate:[OCMArg checkWithBlock:^BOOL(id obj) { + id delegate = obj; + [delegate nativeAdDidRecordClick:mockGADNativeAd]; + [delegate nativeAdDidRecordImpression:mockGADNativeAd]; + [delegate nativeAdWillPresentScreen:mockGADNativeAd]; + [delegate nativeAdDidDismissScreen:mockGADNativeAd]; + [delegate nativeAdWillDismissScreen:mockGADNativeAd]; + return YES; + }]]); // Mock callback of paid event handler. GADAdValue *adValue = OCMClassMock([GADAdValue class]); OCMStub([adValue value]).andReturn(NSDecimalNumber.one); OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated); OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); - OCMStub([mockGADNativeAd setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - GADPaidEventHandler handler = obj; - handler(adValue); - return YES; - }]]); + OCMStub([mockGADNativeAd + setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + GADPaidEventHandler handler = obj; + handler(adValue); + return YES; + }]]); // Check ad loader delegate methods forward to ad instance manager. - [(id)ad.adLoader.delegate adLoader:mockLoader - didReceiveNativeAd:mockGADNativeAd]; + [(id)ad.adLoader.delegate + adLoader:mockLoader + didReceiveNativeAd:mockGADNativeAd]; OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad] responseInfo:[OCMArg isEqual:mockResponseInfo]]); @@ -118,7 +128,8 @@ - (void)testLoadNativeAd:(FLTAdRequest *)gadOrGAMRequest NSError *error = OCMClassMock([NSError class]); [(id)ad.adLoader.delegate adLoader:mockLoader didFailToReceiveAdWithError:error]; - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); OCMVerify([mockGADNativeAd setPaidEventHandler:[OCMArg any]]); @@ -129,30 +140,35 @@ - (void)testLoadNativeAd:(FLTAdRequest *)gadOrGAMRequest OCMVerify([mockManager onNativeAdWillPresentScreen:[OCMArg isEqual:ad]]); OCMVerify([mockManager onNativeAdDidDismissScreen:[OCMArg isEqual:ad]]); OCMVerify([mockManager onNativeAdWillDismissScreen:[OCMArg isEqual:ad]]); - OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager + onPaidEvent:[OCMArg isEqual:ad] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); } // Check that native templates are used when template style is provided. - (void)testLoadNativeAdNativeTemplateStyle { FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init]; id mockNativeAdFactory = OCMProtocolMock(@protocol(FLTNativeAdFactory)); - FLTNativeAdOptions *mockNativeAdOptions = OCMClassMock([FLTNativeAdOptions class]); - GADAdLoaderOptions *mockGADAdLoaderOptions = OCMClassMock([GADAdLoaderOptions class]); + FLTNativeAdOptions *mockNativeAdOptions = + OCMClassMock([FLTNativeAdOptions class]); + GADAdLoaderOptions *mockGADAdLoaderOptions = + OCMClassMock([GADAdLoaderOptions class]); OCMStub([mockNativeAdOptions asGADAdLoaderOptions]) .andReturn([NSArray arrayWithObject:mockGADAdLoaderOptions]); UIViewController *mockViewController = OCMClassMock([UIViewController class]); - FLTNativeTemplateStyle *templateStyle = OCMClassMock([FLTNativeTemplateStyle class]); + FLTNativeTemplateStyle *templateStyle = + OCMClassMock([FLTNativeTemplateStyle class]); UIView *mockTemplateView = OCMClassMock([UIView class]); - OCMStub([templateStyle getDisplayedView:[OCMArg any]]).andReturn(mockTemplateView); + OCMStub([templateStyle getDisplayedView:[OCMArg any]]) + .andReturn(mockTemplateView); FLTNativeAd *ad = [[FLTNativeAd alloc] initWithAdUnitId:@"testAdUnitId" request:request diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m index d7c36cfc4..a64936b57 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m @@ -50,8 +50,12 @@ - (void)testLoadShowRewardedAdGAMRequest { // Helper method for testing with FLTAdRequest and FLTGAMAdRequest. - (void)testLoadShowRewardedAd:(FLTAdRequest *)request gadOrGAMRequest:(GADRequest *)gadOrGAMRequest { - UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); - FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" request:request adId:@1]; + UIViewController *mockRootViewController = + OCMClassMock([UIViewController class]); + FLTRewardedAd *ad = + [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; // Stub the load call to invoke successful load callback. @@ -92,11 +96,12 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request OCMStub([adValue value]).andReturn(NSDecimalNumber.one); OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated); OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); - OCMStub([rewardedClassMock setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - GADPaidEventHandler handler = obj; - handler(adValue); - return YES; - }]]); + OCMStub([rewardedClassMock + setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + GADPaidEventHandler handler = obj; + handler(adValue); + return YES; + }]]); // Setup mock for UIApplication.sharedInstance id uiApplicationClassMock = OCMClassMock([UIApplication class]); @@ -106,40 +111,46 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request // Call load and check expected interactions with mocks. [ad load]; - OCMVerify(ClassMethod([rewardedClassMock loadWithAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadOrGAMRequest] - completionHandler:[OCMArg any]])); + OCMVerify(ClassMethod([rewardedClassMock + loadWithAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadOrGAMRequest] + completionHandler:[OCMArg any]])); OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad] responseInfo:[OCMArg isEqual:responseInfo]]); - OCMVerify([rewardedClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); + OCMVerify( + [rewardedClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); XCTAssertEqual(ad.rewardedAd, rewardedClassMock); - OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager + onPaidEvent:[OCMArg isEqual:ad] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); // Set SSV and verify interactions with mocks FLTServerSideVerificationOptions *serverSideVerificationOptions = OCMClassMock([FLTServerSideVerificationOptions class]); GADServerSideVerificationOptions *gadOptions = OCMClassMock([GADServerSideVerificationOptions class]); - OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]).andReturn(gadOptions); + OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]) + .andReturn(gadOptions); [ad setServerSideVerificationOptions:serverSideVerificationOptions]; - OCMVerify([rewardedClassMock setServerSideVerificationOptions:[OCMArg isEqual:gadOptions]]); + OCMVerify([rewardedClassMock + setServerSideVerificationOptions:[OCMArg isEqual:gadOptions]]); // Show the ad and verify callbacks invoked [ad showFromRootViewController:mockRootViewController]; - OCMVerify([rewardedClassMock presentFromRootViewController:[OCMArg isEqual:mockRootViewController] - userDidEarnRewardHandler:[OCMArg any]]); + OCMVerify([rewardedClassMock + presentFromRootViewController:[OCMArg isEqual:mockRootViewController] + userDidEarnRewardHandler:[OCMArg any]]); [fullScreenContentDelegate adWillPresentFullScreenContent:rewardedClassMock]; OCMVerify([mockManager adWillPresentFullScreenContent:[OCMArg isEqual:ad]]); @@ -166,17 +177,19 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request #pragma clang diagnostic pop [ad ad:rewardedClassMock didFailToPresentFullScreenContentWithError:error]; - OCMVerify([mockManager didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager + didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); // Verify reward callback. - OCMVerify([mockManager onRewardedAdUserEarnedReward:[OCMArg isEqual:ad] - reward:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTRewardItem *reward = (FLTRewardItem *)obj; - XCTAssertEqual(reward.amount, @1.0); - XCTAssertEqual(reward.type, @"type"); - return true; - }]]); + OCMVerify([mockManager + onRewardedAdUserEarnedReward:[OCMArg isEqual:ad] + reward:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTRewardItem *reward = (FLTRewardItem *)obj; + XCTAssertEqual(reward.amount, @1.0); + XCTAssertEqual(reward.type, @"type"); + return true; + }]]); // Explicitly stop mocking. There is an issue when running tests on Github // actions where the mock does not get deallocated properly, so without this @@ -202,7 +215,10 @@ - (void)testFailedToLoadGAMRequest { // Helper for testing failed to load. - (void)testFailedToLoad:(FLTAdRequest *)request { - FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" request:request adId:@1]; + FLTRewardedAd *ad = + [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id rewardedClassMock = OCMClassMock([GADRewardedAd class]); @@ -221,7 +237,8 @@ - (void)testFailedToLoad:(FLTAdRequest *)request { OCMVerify(ClassMethod([rewardedClassMock loadWithAdUnitID:[OCMArg any] request:[OCMArg any] completionHandler:[OCMArg any]])); - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m index a732ef9b8..261a9e049 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m @@ -50,25 +50,31 @@ - (void)testLoadShowRewardedInterstitialAdGAMRequest { // Helper method for testing with FLTAdRequest and FLTGAMAdRequest. - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request gadOrGAMRequest:(GADRequest *)gadOrGAMRequest { - UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); - FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + UIViewController *mockRootViewController = + OCMClassMock([UIViewController class]); + FLTRewardedInterstitialAd *ad = + [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; // Stub the load call to invoke successful load callback. - id rewardedInterstitialClassMock = OCMClassMock([GADRewardedInterstitialAd class]); - OCMStub(ClassMethod([rewardedInterstitialClassMock loadWithAdUnitID:[OCMArg any] - request:[OCMArg any] - completionHandler:[OCMArg any]])) + id rewardedInterstitialClassMock = + OCMClassMock([GADRewardedInterstitialAd class]); + OCMStub(ClassMethod([rewardedInterstitialClassMock + loadWithAdUnitID:[OCMArg any] + request:[OCMArg any] + completionHandler:[OCMArg any]])) .andDo(^(NSInvocation *invocation) { - void (^completionHandler)(GADRewardedInterstitialAd *ad, NSError *error); + void (^completionHandler)(GADRewardedInterstitialAd *ad, + NSError *error); [invocation getArgument:&completionHandler atIndex:4]; completionHandler(rewardedInterstitialClassMock, nil); }); // Stub setting of FullScreenContentDelegate to invoke delegate callbacks. NSError *error = OCMClassMock([NSError class]); - OCMStub([rewardedInterstitialClassMock setFullScreenContentDelegate:[OCMArg any]]) + OCMStub( + [rewardedInterstitialClassMock setFullScreenContentDelegate:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { id delegate; [invocation getArgument:&delegate atIndex:2]; @@ -88,8 +94,9 @@ - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request OCMStub([mockReward amount]).andReturn(@1.0); OCMStub([mockReward type]).andReturn(@"type"); OCMStub([rewardedInterstitialClassMock adReward]).andReturn(mockReward); - OCMStub([rewardedInterstitialClassMock presentFromRootViewController:[OCMArg any] - userDidEarnRewardHandler:[OCMArg any]]) + OCMStub([rewardedInterstitialClassMock + presentFromRootViewController:[OCMArg any] + userDidEarnRewardHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { GADUserDidEarnRewardHandler rewardHandler; [invocation getArgument:&rewardHandler atIndex:3]; @@ -101,43 +108,47 @@ - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request OCMStub([adValue value]).andReturn(NSDecimalNumber.one); OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated); OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); - OCMStub([rewardedInterstitialClassMock setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - GADPaidEventHandler handler = obj; - handler(adValue); - return YES; - }]]); + OCMStub([rewardedInterstitialClassMock + setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + GADPaidEventHandler handler = obj; + handler(adValue); + return YES; + }]]); // Call load and check expected interactions with mocks. [ad load]; - OCMVerify( - ClassMethod([rewardedInterstitialClassMock loadWithAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadOrGAMRequest] - completionHandler:[OCMArg any]])); + OCMVerify(ClassMethod([rewardedInterstitialClassMock + loadWithAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadOrGAMRequest] + completionHandler:[OCMArg any]])); OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad] responseInfo:[OCMArg isEqual:responseInfo]]); - OCMVerify([rewardedInterstitialClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); - OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([rewardedInterstitialClassMock + setFullScreenContentDelegate:[OCMArg isEqual:ad]]); + OCMVerify([mockManager + onPaidEvent:[OCMArg isEqual:ad] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); // Set SSV and verify interactions with mocks FLTServerSideVerificationOptions *serverSideVerificationOptions = OCMClassMock([FLTServerSideVerificationOptions class]); GADServerSideVerificationOptions *gadOptions = OCMClassMock([GADServerSideVerificationOptions class]); - OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]).andReturn(gadOptions); + OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]) + .andReturn(gadOptions); [ad setServerSideVerificationOptions:serverSideVerificationOptions]; - OCMVerify( - [rewardedInterstitialClassMock setServerSideVerificationOptions:[OCMArg isEqual:gadOptions]]); + OCMVerify([rewardedInterstitialClassMock + setServerSideVerificationOptions:[OCMArg isEqual:gadOptions]]); // Show the ad and verify callbacks are invoked [ad showFromRootViewController:mockRootViewController]; @@ -152,14 +163,17 @@ - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request OCMVerify([mockManager adWillDismissFullScreenContent:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordImpression:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:ad]]); - OCMVerify([mockManager didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager + didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); // Verify reward callback. OCMVerify([mockManager onRewardedInterstitialAdUserEarnedReward:[OCMArg isEqual:ad] - reward:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTRewardItem *reward = (FLTRewardItem *)obj; + reward:[OCMArg checkWithBlock:^BOOL( + id obj) { + FLTRewardItem *reward = + (FLTRewardItem *)obj; XCTAssertEqual(reward.amount, @1.0); XCTAssertEqual(reward.type, @"type"); return true; @@ -187,28 +201,34 @@ - (void)testFailedToLoadGAMRequest { // Helper for testing failed to load. - (void)testFailedToLoad:(FLTAdRequest *)request { - FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + FLTRewardedInterstitialAd *ad = + [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; - id rewardedInterstitialClassMock = OCMClassMock([GADRewardedInterstitialAd class]); + id rewardedInterstitialClassMock = + OCMClassMock([GADRewardedInterstitialAd class]); NSError *error = OCMClassMock([NSError class]); - OCMStub(ClassMethod([rewardedInterstitialClassMock loadWithAdUnitID:[OCMArg any] - request:[OCMArg any] - completionHandler:[OCMArg any]])) + OCMStub(ClassMethod([rewardedInterstitialClassMock + loadWithAdUnitID:[OCMArg any] + request:[OCMArg any] + completionHandler:[OCMArg any]])) .andDo(^(NSInvocation *invocation) { - void (^completionHandler)(GADRewardedInterstitialAd *ad, NSError *error); + void (^completionHandler)(GADRewardedInterstitialAd *ad, + NSError *error); [invocation getArgument:&completionHandler atIndex:4]; completionHandler(nil, error); }); [ad load]; - OCMVerify(ClassMethod([rewardedInterstitialClassMock loadWithAdUnitID:[OCMArg any] - request:[OCMArg any] - completionHandler:[OCMArg any]])); - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]); + OCMVerify(ClassMethod([rewardedInterstitialClassMock + loadWithAdUnitID:[OCMArg any] + request:[OCMArg any] + completionHandler:[OCMArg any]])); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTUserMessagingPlatformManagerTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTUserMessagingPlatformManagerTest.m index 45b551076..d05146a23 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTUserMessagingPlatformManagerTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTUserMessagingPlatformManagerTest.m @@ -37,9 +37,11 @@ @implementation FLTUserMessagingPlatformManagerTest { - (void)setUp { binaryMessenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger)); - umpManager = [[FLTUserMessagingPlatformManager alloc] initWithBinaryMessenger:binaryMessenger]; + umpManager = [[FLTUserMessagingPlatformManager alloc] + initWithBinaryMessenger:binaryMessenger]; id umpInfoClassMock = OCMClassMock([UMPConsentInformation class]); - OCMStub(ClassMethod([umpInfoClassMock sharedInstance])).andReturn(umpInfoClassMock); + OCMStub(ClassMethod([umpInfoClassMock sharedInstance])) + .andReturn(umpInfoClassMock); mockUmpConsentInformation = umpInfoClassMock; resultInvoked = false; @@ -52,7 +54,8 @@ - (void)setUp { - (void)testReset { FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"ConsentInformation#reset" arguments:@{}]; + [FlutterMethodCall methodCallWithMethodName:@"ConsentInformation#reset" + arguments:@{}]; [umpManager handleMethodCall:methodCall result:flutterResult]; @@ -62,24 +65,26 @@ - (void)testReset { } - (void)testGetConsentStatus { - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"ConsentInformation#getConsentStatus" - arguments:@{}]; + FlutterMethodCall *methodCall = [FlutterMethodCall + methodCallWithMethodName:@"ConsentInformation#getConsentStatus" + arguments:@{}]; - OCMStub([mockUmpConsentInformation consentStatus]).andReturn(UMPConsentStatusRequired); + OCMStub([mockUmpConsentInformation consentStatus]) + .andReturn(UMPConsentStatusRequired); [umpManager handleMethodCall:methodCall result:flutterResult]; XCTAssertTrue(resultInvoked); - NSNumber *expected = [[NSNumber alloc] initWithInteger:UMPConsentStatusRequired]; + NSNumber *expected = + [[NSNumber alloc] initWithInteger:UMPConsentStatusRequired]; XCTAssertEqual(returnedResult, expected); OCMVerify([mockUmpConsentInformation consentStatus]); } - (void)testCanRequestAds_yes { - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"ConsentInformation#canRequestAds" - arguments:@{}]; + FlutterMethodCall *methodCall = [FlutterMethodCall + methodCallWithMethodName:@"ConsentInformation#canRequestAds" + arguments:@{}]; OCMStub([mockUmpConsentInformation canRequestAds]).andReturn(YES); [umpManager handleMethodCall:methodCall result:flutterResult]; @@ -89,9 +94,9 @@ - (void)testCanRequestAds_yes { } - (void)testCanRequestAds_no { - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"ConsentInformation#canRequestAds" - arguments:@{}]; + FlutterMethodCall *methodCall = [FlutterMethodCall + methodCallWithMethodName:@"ConsentInformation#canRequestAds" + arguments:@{}]; OCMStub([mockUmpConsentInformation canRequestAds]).andReturn(NO); [umpManager handleMethodCall:methodCall result:flutterResult]; @@ -102,7 +107,8 @@ - (void)testCanRequestAds_no { - (void)testGetPrivacyOptionsRequirementStatus_notRequiredReturns0 { FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"ConsentInformation#getPrivacyOptionsRequirementStatus" + methodCallWithMethodName: + @"ConsentInformation#getPrivacyOptionsRequirementStatus" arguments:@{}]; OCMStub([mockUmpConsentInformation privacyOptionsRequirementStatus]) .andReturn(UMPPrivacyOptionsRequirementStatusNotRequired); @@ -116,7 +122,8 @@ - (void)testGetPrivacyOptionsRequirementStatus_notRequiredReturns0 { - (void)testGetPrivacyOptionsRequirementStatus_requiredReturns1 { FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"ConsentInformation#getPrivacyOptionsRequirementStatus" + methodCallWithMethodName: + @"ConsentInformation#getPrivacyOptionsRequirementStatus" arguments:@{}]; OCMStub([mockUmpConsentInformation privacyOptionsRequirementStatus]) .andReturn(UMPPrivacyOptionsRequirementStatusRequired); @@ -130,7 +137,8 @@ - (void)testGetPrivacyOptionsRequirementStatus_requiredReturns1 { - (void)testGetPrivacyOptionsRequirementStatus_unknownReturns2 { FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"ConsentInformation#getPrivacyOptionsRequirementStatus" + methodCallWithMethodName: + @"ConsentInformation#getPrivacyOptionsRequirementStatus" arguments:@{}]; OCMStub([mockUmpConsentInformation privacyOptionsRequirementStatus]) .andReturn(UMPPrivacyOptionsRequirementStatusUnknown); @@ -145,12 +153,13 @@ - (void)testGetPrivacyOptionsRequirementStatus_unknownReturns2 { - (void)testRequestConsentInfoUpdate_success { UMPRequestParameters *params = OCMClassMock([UMPRequestParameters class]); - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"ConsentInformation#requestConsentInfoUpdate" - arguments:@{@"params" : params}]; + FlutterMethodCall *methodCall = [FlutterMethodCall + methodCallWithMethodName:@"ConsentInformation#requestConsentInfoUpdate" + arguments:@{@"params" : params}]; - OCMStub([mockUmpConsentInformation requestConsentInfoUpdateWithParameters:[OCMArg isEqual:params] - completionHandler:[OCMArg any]]) + OCMStub([mockUmpConsentInformation + requestConsentInfoUpdateWithParameters:[OCMArg isEqual:params] + completionHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(NSError *error); [invocation getArgument:&completionHandler atIndex:3]; @@ -161,20 +170,22 @@ - (void)testRequestConsentInfoUpdate_success { XCTAssertTrue(resultInvoked); XCTAssertNil(returnedResult); - OCMVerify([mockUmpConsentInformation requestConsentInfoUpdateWithParameters:[OCMArg any] - completionHandler:[OCMArg any]]); + OCMVerify([mockUmpConsentInformation + requestConsentInfoUpdateWithParameters:[OCMArg any] + completionHandler:[OCMArg any]]); } - (void)testRequestConsentInfoUpdate_error { UMPRequestParameters *params = OCMClassMock([UMPRequestParameters class]); - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"ConsentInformation#requestConsentInfoUpdate" - arguments:@{@"params" : params}]; + FlutterMethodCall *methodCall = [FlutterMethodCall + methodCallWithMethodName:@"ConsentInformation#requestConsentInfoUpdate" + arguments:@{@"params" : params}]; NSDictionary *userInfo = @{NSLocalizedDescriptionKey : @"description"}; NSError *error = [NSError errorWithDomain:@"domain" code:1 userInfo:userInfo]; - OCMStub([mockUmpConsentInformation requestConsentInfoUpdateWithParameters:[OCMArg isEqual:params] - completionHandler:[OCMArg any]]) + OCMStub([mockUmpConsentInformation + requestConsentInfoUpdateWithParameters:[OCMArg isEqual:params] + completionHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(NSError *error); [invocation getArgument:&completionHandler atIndex:3]; @@ -185,8 +196,9 @@ - (void)testRequestConsentInfoUpdate_error { XCTAssertTrue(resultInvoked); - OCMVerify([mockUmpConsentInformation requestConsentInfoUpdateWithParameters:[OCMArg any] - completionHandler:[OCMArg any]]); + OCMVerify([mockUmpConsentInformation + requestConsentInfoUpdateWithParameters:[OCMArg any] + completionHandler:[OCMArg any]]); FlutterError *resultError = (FlutterError *)returnedResult; XCTAssertEqualObjects(resultError.code, @"1"); XCTAssertEqualObjects(resultError.details, @"domain"); @@ -196,11 +208,13 @@ - (void)testRequestConsentInfoUpdate_error { - (void)testLoadAndShowConsentFormIfRequired_success { UMPRequestParameters *params = OCMClassMock([UMPRequestParameters class]); FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"UserMessagingPlatform#loadAndShowConsentFormIfRequired" + methodCallWithMethodName: + @"UserMessagingPlatform#loadAndShowConsentFormIfRequired" arguments:@{@"params" : params}]; id mockUmpConsentForm = OCMClassMock([UMPConsentForm class]); - OCMStub([mockUmpConsentForm loadAndPresentIfRequiredFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]) + OCMStub([mockUmpConsentForm + loadAndPresentIfRequiredFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(NSError *loadError); [invocation getArgument:&completionHandler atIndex:3]; @@ -211,8 +225,9 @@ - (void)testLoadAndShowConsentFormIfRequired_success { XCTAssertTrue(resultInvoked); XCTAssertNil(returnedResult); - OCMVerify([mockUmpConsentForm loadAndPresentIfRequiredFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]); + OCMVerify([mockUmpConsentForm + loadAndPresentIfRequiredFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]); } - (void)testLoadAndShowConsentFormIfRequired_error { @@ -220,11 +235,13 @@ - (void)testLoadAndShowConsentFormIfRequired_error { NSError *error = [NSError errorWithDomain:@"domain" code:1 userInfo:userInfo]; UMPRequestParameters *params = OCMClassMock([UMPRequestParameters class]); FlutterMethodCall *methodCall = [FlutterMethodCall - methodCallWithMethodName:@"UserMessagingPlatform#loadAndShowConsentFormIfRequired" + methodCallWithMethodName: + @"UserMessagingPlatform#loadAndShowConsentFormIfRequired" arguments:@{@"params" : params}]; id mockUmpConsentForm = OCMClassMock([UMPConsentForm class]); - OCMStub([mockUmpConsentForm loadAndPresentIfRequiredFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]) + OCMStub([mockUmpConsentForm + loadAndPresentIfRequiredFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(NSError *loadError); [invocation getArgument:&completionHandler atIndex:3]; @@ -238,14 +255,15 @@ - (void)testLoadAndShowConsentFormIfRequired_error { XCTAssertEqualObjects(resultError.code, @"1"); XCTAssertEqualObjects(resultError.details, @"domain"); XCTAssertEqualObjects(resultError.message, @"description"); - OCMVerify([mockUmpConsentForm loadAndPresentIfRequiredFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]); + OCMVerify([mockUmpConsentForm + loadAndPresentIfRequiredFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]); } - (void)testLoadConsentForm_successAndDispose { - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"UserMessagingPlatform#loadConsentForm" - arguments:@{}]; + FlutterMethodCall *methodCall = [FlutterMethodCall + methodCallWithMethodName:@"UserMessagingPlatform#loadConsentForm" + arguments:@{}]; id mockUmpConsentForm = OCMClassMock([UMPConsentForm class]); OCMStub([mockUmpConsentForm loadWithCompletionHandler:[OCMArg any]]) @@ -269,9 +287,9 @@ - (void)testLoadConsentForm_successAndDispose { } - (void)testLoadConsentForm_error { - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"UserMessagingPlatform#loadConsentForm" - arguments:@{}]; + FlutterMethodCall *methodCall = [FlutterMethodCall + methodCallWithMethodName:@"UserMessagingPlatform#loadConsentForm" + arguments:@{}]; NSDictionary *userInfo = @{NSLocalizedDescriptionKey : @"description"}; NSError *error = [NSError errorWithDomain:@"domain" code:1 userInfo:userInfo]; @@ -295,12 +313,13 @@ - (void)testLoadConsentForm_error { - (void)testShowPrivacyOptionsForm_success { UMPRequestParameters *params = OCMClassMock([UMPRequestParameters class]); - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"UserMessagingPlatform#showPrivacyOptionsForm" - arguments:@{@"params" : params}]; + FlutterMethodCall *methodCall = [FlutterMethodCall + methodCallWithMethodName:@"UserMessagingPlatform#showPrivacyOptionsForm" + arguments:@{@"params" : params}]; id mockUmpConsentForm = OCMClassMock([UMPConsentForm class]); - OCMStub([mockUmpConsentForm presentPrivacyOptionsFormFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]) + OCMStub([mockUmpConsentForm + presentPrivacyOptionsFormFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(NSError *loadError); [invocation getArgument:&completionHandler atIndex:3]; @@ -311,20 +330,22 @@ - (void)testShowPrivacyOptionsForm_success { XCTAssertTrue(resultInvoked); XCTAssertNil(returnedResult); - OCMVerify([mockUmpConsentForm presentPrivacyOptionsFormFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]); + OCMVerify([mockUmpConsentForm + presentPrivacyOptionsFormFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]); } - (void)testShowPrivacyOptionsForm_error { NSDictionary *userInfo = @{NSLocalizedDescriptionKey : @"description"}; NSError *error = [NSError errorWithDomain:@"domain" code:1 userInfo:userInfo]; UMPRequestParameters *params = OCMClassMock([UMPRequestParameters class]); - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"UserMessagingPlatform#showPrivacyOptionsForm" - arguments:@{@"params" : params}]; + FlutterMethodCall *methodCall = [FlutterMethodCall + methodCallWithMethodName:@"UserMessagingPlatform#showPrivacyOptionsForm" + arguments:@{@"params" : params}]; id mockUmpConsentForm = OCMClassMock([UMPConsentForm class]); - OCMStub([mockUmpConsentForm presentPrivacyOptionsFormFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]) + OCMStub([mockUmpConsentForm + presentPrivacyOptionsFormFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(NSError *loadError); [invocation getArgument:&completionHandler atIndex:3]; @@ -338,16 +359,18 @@ - (void)testShowPrivacyOptionsForm_error { XCTAssertEqualObjects(resultError.code, @"1"); XCTAssertEqualObjects(resultError.details, @"domain"); XCTAssertEqualObjects(resultError.message, @"description"); - OCMVerify([mockUmpConsentForm presentPrivacyOptionsFormFromViewController:[OCMArg any] - completionHandler:[OCMArg any]]); + OCMVerify([mockUmpConsentForm + presentPrivacyOptionsFormFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]); } - (void)testIsConsentFormAvailable_available { - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"ConsentInformation#isConsentFormAvailable" - arguments:@{}]; + FlutterMethodCall *methodCall = [FlutterMethodCall + methodCallWithMethodName:@"ConsentInformation#isConsentFormAvailable" + arguments:@{}]; - OCMStub([mockUmpConsentInformation formStatus]).andReturn(UMPFormStatusAvailable); + OCMStub([mockUmpConsentInformation formStatus]) + .andReturn(UMPFormStatusAvailable); [umpManager handleMethodCall:methodCall result:flutterResult]; @@ -356,11 +379,12 @@ - (void)testIsConsentFormAvailable_available { } - (void)testIsConsentFormAvailable_notAvailable { - FlutterMethodCall *methodCall = - [FlutterMethodCall methodCallWithMethodName:@"ConsentInformation#isConsentFormAvailable" - arguments:@{}]; + FlutterMethodCall *methodCall = [FlutterMethodCall + methodCallWithMethodName:@"ConsentInformation#isConsentFormAvailable" + arguments:@{}]; - OCMStub([mockUmpConsentInformation formStatus]).andReturn(UMPFormStatusUnavailable); + OCMStub([mockUmpConsentInformation formStatus]) + .andReturn(UMPFormStatusUnavailable); [umpManager handleMethodCall:methodCall result:flutterResult]; @@ -378,7 +402,8 @@ - (void)testShowConsentForm_success { [FlutterMethodCall methodCallWithMethodName:@"ConsentForm#show" arguments:@{@"consentForm" : mockForm}]; - OCMStub([mockForm presentFromViewController:[OCMArg any] completionHandler:[OCMArg any]]) + OCMStub([mockForm presentFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(NSError *error); [invocation getArgument:&completionHandler atIndex:3]; @@ -390,7 +415,8 @@ - (void)testShowConsentForm_success { XCTAssertTrue(resultInvoked); XCTAssertNil(returnedResult); - OCMVerify([mockForm presentFromViewController:[OCMArg any] completionHandler:[OCMArg any]]); + OCMVerify([mockForm presentFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]); } - (void)testShowConsentForm_error { @@ -405,7 +431,8 @@ - (void)testShowConsentForm_error { NSDictionary *userInfo = @{NSLocalizedDescriptionKey : @"description"}; NSError *error = [NSError errorWithDomain:@"domain" code:1 userInfo:userInfo]; - OCMStub([mockForm presentFromViewController:[OCMArg any] completionHandler:[OCMArg any]]) + OCMStub([mockForm presentFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(NSError *error); [invocation getArgument:&completionHandler atIndex:3]; @@ -416,7 +443,8 @@ - (void)testShowConsentForm_error { [partialMock handleMethodCall:methodCall result:flutterResult]; XCTAssertTrue(resultInvoked); - OCMVerify([mockForm presentFromViewController:[OCMArg any] completionHandler:[OCMArg any]]); + OCMVerify([mockForm presentFromViewController:[OCMArg any] + completionHandler:[OCMArg any]]); FlutterError *resultError = (FlutterError *)returnedResult; XCTAssertEqualObjects(resultError.code, @"1"); XCTAssertEqualObjects(resultError.details, @"domain"); diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTUserMessagingPlatformReaderWriterTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTUserMessagingPlatformReaderWriterTest.m index 660dfe8de..721acf207 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTUserMessagingPlatformReaderWriterTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTUserMessagingPlatformReaderWriterTest.m @@ -28,7 +28,8 @@ @implementation FLTUserMessagingPlatformReaderWriterTest { - (void)setUp { readerWriter = [[FLTUserMessagingPlatformReaderWriter alloc] init]; - messageCodec = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; + messageCodec = + [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; } - (void)testRequestParams_default { @@ -36,7 +37,8 @@ - (void)testRequestParams_default { NSData *encodedMessage = [messageCodec encode:requestParameters]; UMPRequestParameters *decoded = [messageCodec decode:encodedMessage]; - XCTAssertEqual(decoded.tagForUnderAgeOfConsent, requestParameters.tagForUnderAgeOfConsent); + XCTAssertEqual(decoded.tagForUnderAgeOfConsent, + requestParameters.tagForUnderAgeOfConsent); XCTAssertEqual(decoded.debugSettings, requestParameters.debugSettings); } @@ -47,8 +49,10 @@ - (void)testRequestParams_withDebugSettingsTfuac { NSData *encodedMessage = [messageCodec encode:requestParameters]; UMPRequestParameters *decoded = [messageCodec decode:encodedMessage]; - XCTAssertEqual(decoded.tagForUnderAgeOfConsent, requestParameters.tagForUnderAgeOfConsent); - XCTAssertEqual(decoded.debugSettings.geography, requestParameters.debugSettings.geography); + XCTAssertEqual(decoded.tagForUnderAgeOfConsent, + requestParameters.tagForUnderAgeOfConsent); + XCTAssertEqual(decoded.debugSettings.geography, + requestParameters.debugSettings.geography); XCTAssertEqual(decoded.debugSettings.testDeviceIdentifiers, requestParameters.debugSettings.testDeviceIdentifiers); } @@ -59,7 +63,8 @@ - (void)testConsentDebugSettings_default { UMPDebugSettings *decoded = [messageCodec decode:encodedMessage]; XCTAssertEqual(decoded.geography, debugSettings.geography); - XCTAssertEqual(decoded.testDeviceIdentifiers, debugSettings.testDeviceIdentifiers); + XCTAssertEqual(decoded.testDeviceIdentifiers, + debugSettings.testDeviceIdentifiers); } - (void)testConsentDebugSettings_geographyTestDeviceIdentifiers { @@ -70,7 +75,8 @@ - (void)testConsentDebugSettings_geographyTestDeviceIdentifiers { UMPDebugSettings *decoded = [messageCodec decode:encodedMessage]; XCTAssertEqual(decoded.geography, debugSettings.geography); - XCTAssertEqualObjects(decoded.testDeviceIdentifiers, debugSettings.testDeviceIdentifiers); + XCTAssertEqualObjects(decoded.testDeviceIdentifiers, + debugSettings.testDeviceIdentifiers); } - (void)testConsentFormTrackAndDispose { diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateColorTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateColorTest.m index 1c9dbd9c4..24ad94e7d 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateColorTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateColorTest.m @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +#import "FLTNativeTemplateColor.h" #import #import -#import "FLTNativeTemplateColor.h" @interface FLTNativeTemplateColorTest : XCTestCase @end @@ -22,11 +22,11 @@ @interface FLTNativeTemplateColorTest : XCTestCase @implementation FLTNativeTemplateColorTest - (void)testConvertToUiColor { - FLTNativeTemplateColor *color = - [[FLTNativeTemplateColor alloc] initWithAlpha:[[NSNumber alloc] initWithFloat:5.0f] - red:@10.0f - green:[[NSNumber alloc] initWithFloat:15.0f] - blue:[[NSNumber alloc] initWithFloat:20.0f]]; + FLTNativeTemplateColor *color = [[FLTNativeTemplateColor alloc] + initWithAlpha:[[NSNumber alloc] initWithFloat:5.0f] + red:@10.0f + green:[[NSNumber alloc] initWithFloat:15.0f] + blue:[[NSNumber alloc] initWithFloat:20.0f]]; CGFloat alpha; CGFloat red; CGFloat green; diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateFontStyleTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateFontStyleTest.m index 92953ba0d..8657b4dee 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateFontStyleTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateFontStyleTest.m @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import #import "FLTNativeTemplateFontStyle.h" +#import @interface FLTNativeTemplateFontStyleTest : XCTestCase @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateStyleTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateStyleTest.m index 6562e8dc5..208a21f37 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateStyleTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateStyleTest.m @@ -26,15 +26,17 @@ @interface FLTNativeTemplateStyleTest : XCTestCase @implementation FLTNativeTemplateStyleTest - (void)testInitNilParameters { - FLTNativeTemplateType *templateType = [[FLTNativeTemplateType alloc] initWithInt:0]; - - FLTNativeTemplateStyle *style = [[FLTNativeTemplateStyle alloc] initWithTemplateType:templateType - mainBackgroundColor:nil - callToActionStyle:nil - primaryTextStyle:nil - secondaryTextStyle:nil - tertiaryTextStyle:nil - cornerRadius:nil]; + FLTNativeTemplateType *templateType = + [[FLTNativeTemplateType alloc] initWithInt:0]; + + FLTNativeTemplateStyle *style = + [[FLTNativeTemplateStyle alloc] initWithTemplateType:templateType + mainBackgroundColor:nil + callToActionStyle:nil + primaryTextStyle:nil + secondaryTextStyle:nil + tertiaryTextStyle:nil + cornerRadius:nil]; XCTAssertEqual(style.templateType, templateType); XCTAssertNil(style.mainBackgroundColor); XCTAssertNil(style.callToActionStyle); @@ -45,14 +47,20 @@ - (void)testInitNilParameters { } - (void)testInit { - FLTNativeTemplateType *templateType = [[FLTNativeTemplateType alloc] initWithInt:0]; - FLTNativeTemplateColor *bgColor = OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateType *templateType = + [[FLTNativeTemplateType alloc] initWithInt:0]; + FLTNativeTemplateColor *bgColor = + OCMClassMock([FLTNativeTemplateColor class]); UIColor *bgUIColor = OCMClassMock([UIColor class]); OCMStub([bgColor uiColor]).andReturn(bgUIColor); - FLTNativeTemplateTextStyle *ctaStyle = OCMClassMock([FLTNativeTemplateTextStyle class]); - FLTNativeTemplateTextStyle *primaryStyle = OCMClassMock([FLTNativeTemplateTextStyle class]); - FLTNativeTemplateTextStyle *secondaryStyle = OCMClassMock([FLTNativeTemplateTextStyle class]); - FLTNativeTemplateTextStyle *tertiaryStyle = OCMClassMock([FLTNativeTemplateTextStyle class]); + FLTNativeTemplateTextStyle *ctaStyle = + OCMClassMock([FLTNativeTemplateTextStyle class]); + FLTNativeTemplateTextStyle *primaryStyle = + OCMClassMock([FLTNativeTemplateTextStyle class]); + FLTNativeTemplateTextStyle *secondaryStyle = + OCMClassMock([FLTNativeTemplateTextStyle class]); + FLTNativeTemplateTextStyle *tertiaryStyle = + OCMClassMock([FLTNativeTemplateTextStyle class]); FLTNativeTemplateStyle *style = [[FLTNativeTemplateStyle alloc] initWithTemplateType:templateType @@ -73,23 +81,28 @@ - (void)testInit { } - (void)testGetDisplayedView { - FLTNativeTemplateType *templateType = OCMClassMock([FLTNativeTemplateType class]); + FLTNativeTemplateType *templateType = + OCMClassMock([FLTNativeTemplateType class]); GADTTemplateView *templateView = OCMClassMock([GADTTemplateView class]); OCMStub([templateType templateView]).andReturn(templateView); - FLTNativeTemplateColor *bgColor = OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *bgColor = + OCMClassMock([FLTNativeTemplateColor class]); UIColor *bgUIColor = OCMClassMock([UIColor class]); OCMStub([bgColor uiColor]).andReturn(bgUIColor); // Setup mocks for cta - FLTNativeTemplateTextStyle *ctaStyle = OCMClassMock([FLTNativeTemplateTextStyle class]); + FLTNativeTemplateTextStyle *ctaStyle = + OCMClassMock([FLTNativeTemplateTextStyle class]); UIColor *ctaBackgroundUIColor = OCMClassMock([UIColor class]); - FLTNativeTemplateColor *ctaBackgroundColor = OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *ctaBackgroundColor = + OCMClassMock([FLTNativeTemplateColor class]); OCMStub([ctaBackgroundColor uiColor]).andReturn(ctaBackgroundUIColor); OCMStub([ctaStyle backgroundColor]).andReturn(ctaBackgroundColor); UIColor *ctaTextUIColor = OCMClassMock([UIColor class]); - FLTNativeTemplateColor *ctaTextcolor = OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *ctaTextcolor = + OCMClassMock([FLTNativeTemplateColor class]); OCMStub([ctaTextcolor uiColor]).andReturn(ctaTextUIColor); OCMStub([ctaStyle textColor]).andReturn(ctaTextcolor); @@ -97,14 +110,17 @@ - (void)testGetDisplayedView { OCMStub([ctaStyle uiFont]).andReturn(ctaFont); // Setup mocks for primary - FLTNativeTemplateTextStyle *primaryStyle = OCMClassMock([FLTNativeTemplateTextStyle class]); + FLTNativeTemplateTextStyle *primaryStyle = + OCMClassMock([FLTNativeTemplateTextStyle class]); UIColor *primaryBackgroundUIColor = OCMClassMock([UIColor class]); - FLTNativeTemplateColor *primaryBackgroundColor = OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *primaryBackgroundColor = + OCMClassMock([FLTNativeTemplateColor class]); OCMStub([primaryBackgroundColor uiColor]).andReturn(primaryBackgroundUIColor); OCMStub([primaryStyle backgroundColor]).andReturn(primaryBackgroundColor); UIColor *primaryTextUIColor = OCMClassMock([UIColor class]); - FLTNativeTemplateColor *primaryTextcolor = OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *primaryTextcolor = + OCMClassMock([FLTNativeTemplateColor class]); OCMStub([primaryTextcolor uiColor]).andReturn(primaryTextUIColor); OCMStub([primaryStyle textColor]).andReturn(primaryTextcolor); @@ -112,14 +128,18 @@ - (void)testGetDisplayedView { OCMStub([primaryStyle uiFont]).andReturn(primaryFont); // Setup mocks for secondary - FLTNativeTemplateTextStyle *secondaryStyle = OCMClassMock([FLTNativeTemplateTextStyle class]); + FLTNativeTemplateTextStyle *secondaryStyle = + OCMClassMock([FLTNativeTemplateTextStyle class]); UIColor *secondaryBackgroundUIColor = OCMClassMock([UIColor class]); - FLTNativeTemplateColor *secondaryBackgroundColor = OCMClassMock([FLTNativeTemplateColor class]); - OCMStub([secondaryBackgroundColor uiColor]).andReturn(secondaryBackgroundUIColor); + FLTNativeTemplateColor *secondaryBackgroundColor = + OCMClassMock([FLTNativeTemplateColor class]); + OCMStub([secondaryBackgroundColor uiColor]) + .andReturn(secondaryBackgroundUIColor); OCMStub([secondaryStyle backgroundColor]).andReturn(secondaryBackgroundColor); UIColor *secondaryTextUIColor = OCMClassMock([UIColor class]); - FLTNativeTemplateColor *secondaryTextcolor = OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *secondaryTextcolor = + OCMClassMock([FLTNativeTemplateColor class]); OCMStub([secondaryTextcolor uiColor]).andReturn(secondaryTextUIColor); OCMStub([secondaryStyle textColor]).andReturn(secondaryTextcolor); @@ -127,14 +147,18 @@ - (void)testGetDisplayedView { OCMStub([secondaryStyle uiFont]).andReturn(secondaryFont); // Setup mocks for tertiary - FLTNativeTemplateTextStyle *tertiaryStyle = OCMClassMock([FLTNativeTemplateTextStyle class]); + FLTNativeTemplateTextStyle *tertiaryStyle = + OCMClassMock([FLTNativeTemplateTextStyle class]); UIColor *tertiaryBackgroundUIColor = OCMClassMock([UIColor class]); - FLTNativeTemplateColor *tertiaryBackgroundColor = OCMClassMock([FLTNativeTemplateColor class]); - OCMStub([tertiaryBackgroundColor uiColor]).andReturn(tertiaryBackgroundUIColor); + FLTNativeTemplateColor *tertiaryBackgroundColor = + OCMClassMock([FLTNativeTemplateColor class]); + OCMStub([tertiaryBackgroundColor uiColor]) + .andReturn(tertiaryBackgroundUIColor); OCMStub([tertiaryStyle backgroundColor]).andReturn(tertiaryBackgroundColor); UIColor *tertiaryTextUIColor = OCMClassMock([UIColor class]); - FLTNativeTemplateColor *tertiaryTextcolor = OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *tertiaryTextcolor = + OCMClassMock([FLTNativeTemplateColor class]); OCMStub([tertiaryTextcolor uiColor]).andReturn(tertiaryTextUIColor); OCMStub([tertiaryStyle textColor]).andReturn(tertiaryTextcolor); @@ -152,7 +176,8 @@ - (void)testGetDisplayedView { GADNativeAd *gadNativeAd = OCMClassMock([GADNativeAd class]); - FLTNativeTemplateViewWrapper *templateViewWrapper = [style getDisplayedView:gadNativeAd]; + FLTNativeTemplateViewWrapper *templateViewWrapper = + [style getDisplayedView:gadNativeAd]; XCTAssertEqual(templateViewWrapper.templateView, templateView); OCMVerify([templateView setNativeAd:[OCMArg isEqual:gadNativeAd]]); OCMVerify([templateView @@ -160,25 +185,36 @@ - (void)testGetDisplayedView { NSDictionary *styles = obj; XCTAssertEqual(styles[GADTNativeTemplateStyleKeyCornerRadius], @14.0f); - XCTAssertEqual(styles[GADTNativeTemplateStyleKeyCallToActionBackgroundColor], - ctaBackgroundUIColor); - XCTAssertEqual(styles[GADTNativeTemplateStyleKeyCallToActionFontColor], ctaTextUIColor); - XCTAssertEqual(styles[GADTNativeTemplateStyleKeyCallToActionFont], ctaFont); + XCTAssertEqual( + styles[GADTNativeTemplateStyleKeyCallToActionBackgroundColor], + ctaBackgroundUIColor); + XCTAssertEqual(styles[GADTNativeTemplateStyleKeyCallToActionFontColor], + ctaTextUIColor); + XCTAssertEqual(styles[GADTNativeTemplateStyleKeyCallToActionFont], + ctaFont); XCTAssertEqual(styles[GADTNativeTemplateStyleKeyPrimaryBackgroundColor], primaryBackgroundUIColor); - XCTAssertEqual(styles[GADTNativeTemplateStyleKeyPrimaryFontColor], primaryTextUIColor); - XCTAssertEqual(styles[GADTNativeTemplateStyleKeyPrimaryFont], primaryFont); - - XCTAssertEqual(styles[GADTNativeTemplateStyleKeySecondaryBackgroundColor], - secondaryBackgroundUIColor); - XCTAssertEqual(styles[GADTNativeTemplateStyleKeySecondaryFontColor], secondaryTextUIColor); - XCTAssertEqual(styles[GADTNativeTemplateStyleKeySecondaryFont], secondaryFont); - - XCTAssertEqual(styles[GADTNativeTemplateStyleKeyTertiaryBackgroundColor], - tertiaryBackgroundUIColor); - XCTAssertEqual(styles[GADTNativeTemplateStyleKeyTertiaryFontColor], tertiaryTextUIColor); - XCTAssertEqual(styles[GADTNativeTemplateStyleKeyTertiaryFont], tertiaryFont); + XCTAssertEqual(styles[GADTNativeTemplateStyleKeyPrimaryFontColor], + primaryTextUIColor); + XCTAssertEqual(styles[GADTNativeTemplateStyleKeyPrimaryFont], + primaryFont); + + XCTAssertEqual( + styles[GADTNativeTemplateStyleKeySecondaryBackgroundColor], + secondaryBackgroundUIColor); + XCTAssertEqual(styles[GADTNativeTemplateStyleKeySecondaryFontColor], + secondaryTextUIColor); + XCTAssertEqual(styles[GADTNativeTemplateStyleKeySecondaryFont], + secondaryFont); + + XCTAssertEqual( + styles[GADTNativeTemplateStyleKeyTertiaryBackgroundColor], + tertiaryBackgroundUIColor); + XCTAssertEqual(styles[GADTNativeTemplateStyleKeyTertiaryFontColor], + tertiaryTextUIColor); + XCTAssertEqual(styles[GADTNativeTemplateStyleKeyTertiaryFont], + tertiaryFont); return YES; }]]); } diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateTextStyleTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateTextStyleTest.m index d887a6adc..1aff4db1e 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateTextStyleTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateTextStyleTest.m @@ -36,8 +36,10 @@ - (void)testInitWithNilParameters { } - (void)testInitWithDefinedParams { - FLTNativeTemplateColor *textColor = OCMClassMock([FLTNativeTemplateColor class]); - FLTNativeTemplateColor *backgroundColor = OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *textColor = + OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *backgroundColor = + OCMClassMock([FLTNativeTemplateColor class]); FLTNativeTemplateFontStyleWrapper *fontStyleWrapper = OCMClassMock([FLTNativeTemplateFontStyleWrapper class]); OCMStub([fontStyleWrapper fontStyle]).andReturn(FLTNativeTemplateFontBold); @@ -62,8 +64,10 @@ - (void)testInitWithDefinedParams { } - (void)testUiFontWithMissingSize { - FLTNativeTemplateColor *textColor = OCMClassMock([FLTNativeTemplateColor class]); - FLTNativeTemplateColor *backgroundColor = OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *textColor = + OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *backgroundColor = + OCMClassMock([FLTNativeTemplateColor class]); FLTNativeTemplateFontStyleWrapper *fontStyleWrapper = OCMClassMock([FLTNativeTemplateFontStyleWrapper class]); OCMStub([fontStyleWrapper fontStyle]).andReturn(FLTNativeTemplateFontItalic); @@ -88,8 +92,10 @@ - (void)testUiFontWithMissingSize { } - (void)testUiFontWithMissingFontStyle { - FLTNativeTemplateColor *textColor = OCMClassMock([FLTNativeTemplateColor class]); - FLTNativeTemplateColor *backgroundColor = OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *textColor = + OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *backgroundColor = + OCMClassMock([FLTNativeTemplateColor class]); NSNumber *size = [[NSNumber alloc] initWithFloat:14.0f]; FLTNativeTemplateTextStyle *textStyle = [[FLTNativeTemplateTextStyle alloc] initWithTextColor:textColor @@ -111,8 +117,10 @@ - (void)testUiFontWithMissingFontStyle { } - (void)testUiFontWithUnknownFontStyle { - FLTNativeTemplateColor *textColor = OCMClassMock([FLTNativeTemplateColor class]); - FLTNativeTemplateColor *backgroundColor = OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *textColor = + OCMClassMock([FLTNativeTemplateColor class]); + FLTNativeTemplateColor *backgroundColor = + OCMClassMock([FLTNativeTemplateColor class]); NSNumber *size = [[NSNumber alloc] initWithFloat:14.0f]; FLTNativeTemplateFontStyleWrapper *fontStyleWrapper = OCMClassMock([FLTNativeTemplateFontStyleWrapper class]); diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateTypeTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateTypeTest.m index 935ea5265..94b327717 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateTypeTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateTypeTest.m @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import #import "FLTNativeTemplateType.h" +#import @interface FLTNativeTemplateTypeTest : XCTestCase @end @@ -21,17 +21,21 @@ @interface FLTNativeTemplateTypeTest : XCTestCase @implementation FLTNativeTemplateTypeTest - (void)testXibName { - FLTNativeTemplateType *templateTypeSmall = [[FLTNativeTemplateType alloc] initWithInt:0]; + FLTNativeTemplateType *templateTypeSmall = + [[FLTNativeTemplateType alloc] initWithInt:0]; XCTAssertEqualObjects(templateTypeSmall.xibName, @"GADTSmallTemplateView"); - FLTNativeTemplateType *templateTypeMedium = [[FLTNativeTemplateType alloc] initWithInt:1]; + FLTNativeTemplateType *templateTypeMedium = + [[FLTNativeTemplateType alloc] initWithInt:1]; XCTAssertEqualObjects(templateTypeMedium.xibName, @"GADTMediumTemplateView"); // Unknown templates default to medium - FLTNativeTemplateType *templateTypeUnknown = [[FLTNativeTemplateType alloc] initWithInt:-1]; + FLTNativeTemplateType *templateTypeUnknown = + [[FLTNativeTemplateType alloc] initWithInt:-1]; XCTAssertEqualObjects(templateTypeUnknown.xibName, @"GADTMediumTemplateView"); - FLTNativeTemplateType *templateType = [[FLTNativeTemplateType alloc] initWithInt:2]; + FLTNativeTemplateType *templateType = + [[FLTNativeTemplateType alloc] initWithInt:2]; XCTAssertEqualObjects(templateType.xibName, @"GADTMediumTemplateView"); } From 612f8cb335fe4cd21b1f945f6f7bb5c2d593cdd5 Mon Sep 17 00:00:00 2001 From: Aldo Becerril Date: Fri, 9 Aug 2024 11:51:02 -0700 Subject: [PATCH 05/15] Revert "Format fix" This reverts commit d05e62c7e1a438c25475d8619dea17e35179ffb2. --- .../Classes/FLTAdInstanceManager_Internal.h | 19 +- .../Classes/FLTAdInstanceManager_Internal.m | 36 +- .../google_mobile_ads/ios/Classes/FLTAdUtil.h | 3 +- .../google_mobile_ads/ios/Classes/FLTAdUtil.m | 18 +- .../ios/Classes/FLTAd_Internal.h | 108 ++-- .../ios/Classes/FLTAd_Internal.m | 490 +++++++++++------- .../ios/Classes/FLTAppStateNotifier.m | 34 +- .../FLTGoogleMobileAdsCollection_Internal.h | 5 +- .../FLTGoogleMobileAdsCollection_Internal.m | 3 +- .../ios/Classes/FLTGoogleMobileAdsPlugin.h | 24 +- .../ios/Classes/FLTGoogleMobileAdsPlugin.m | 357 +++++++------ .../FLTGoogleMobileAdsReaderWriter_Internal.h | 14 +- .../FLTGoogleMobileAdsReaderWriter_Internal.m | 478 +++++++++-------- .../FLTMediationNetworkExtrasProvider.h | 6 +- .../ios/Classes/FLTMobileAds_Internal.h | 3 +- .../ios/Classes/FLTMobileAds_Internal.m | 22 +- .../FLTNativeTemplateFontStyle.m | 22 +- .../NativeTemplates/FLTNativeTemplateStyle.h | 18 +- .../NativeTemplates/FLTNativeTemplateStyle.m | 64 ++- .../FLTNativeTemplateTextStyle.h | 9 +- .../FLTNativeTemplateTextStyle.m | 44 +- .../NativeTemplates/FLTNativeTemplateType.h | 2 +- .../NativeTemplates/FLTNativeTemplateType.m | 17 +- .../GADTTemplateView.h | 33 +- .../GADTTemplateView.m | 159 +++--- .../FLTUserMessagingPlatformManager.h | 5 +- .../FLTUserMessagingPlatformManager.m | 142 ++--- .../FLTUserMessagingPlatformReaderWriter.m | 62 +-- 28 files changed, 1263 insertions(+), 934 deletions(-) diff --git a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h index 2f3662c9e..1ddf4096e 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h +++ b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import #import "FLTAd_Internal.h" #import "FLTGoogleMobileAdsCollection_Internal.h" #import "FLTGoogleMobileAdsReaderWriter_Internal.h" +#import @protocol FLTAd; @class FLTBannerAd; @@ -33,8 +33,9 @@ - (void)loadAd:(id _Nonnull)ad; - (void)dispose:(NSNumber *_Nonnull)adId; - (void)showAdWithID:(NSNumber *_Nonnull)adId - rootViewController:(UIViewController *_Nonnull)rootViewController; -- (void)onAdLoaded:(id _Nonnull)ad responseInfo:(GADResponseInfo *_Nonnull)responseInfo; + rootViewController:(UIViewController *_Nonnull)rootViewController; +- (void)onAdLoaded:(id _Nonnull)ad + responseInfo:(GADResponseInfo *_Nonnull)responseInfo; - (void)onAdFailedToLoad:(id _Nonnull)ad error:(NSError *_Nonnull)error; - (void)onAppEvent:(id _Nonnull)ad name:(NSString *_Nullable)name @@ -45,8 +46,10 @@ - (void)onNativeAdWillDismissScreen:(FLTNativeAd *_Nonnull)ad; - (void)onRewardedAdUserEarnedReward:(FLTRewardedAd *_Nonnull)ad reward:(FLTRewardItem *_Nonnull)reward; -- (void)onRewardedInterstitialAdUserEarnedReward:(FLTRewardedInterstitialAd *_Nonnull)ad - reward:(FLTRewardItem *_Nonnull)reward; +- (void)onRewardedInterstitialAdUserEarnedReward: + (FLTRewardedInterstitialAd *_Nonnull)ad + reward: + (FLTRewardItem *_Nonnull)reward; - (void)onPaidEvent:(id _Nonnull)ad value:(FLTAdValue *_Nonnull)value; - (void)onBannerImpression:(FLTBannerAd *_Nonnull)ad; - (void)onBannerWillDismissScreen:(FLTBannerAd *_Nonnull)ad; @@ -64,7 +67,9 @@ - (void)disposeAllAds; @end -@interface FLTNewGoogleMobileAdsViewFactory : NSObject +@interface FLTNewGoogleMobileAdsViewFactory + : NSObject @property(readonly) FLTAdInstanceManager *_Nonnull manager; -- (instancetype _Nonnull)initWithManager:(FLTAdInstanceManager *_Nonnull)manager; +- (instancetype _Nonnull)initWithManager: + (FLTAdInstanceManager *_Nonnull)manager; @end diff --git a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m index e384dc1dd..2ec069c95 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m @@ -26,9 +26,10 @@ - (instancetype _Nonnull)initWithBinaryMessenger: _ads = [[FLTGoogleMobileAdsCollection alloc] init]; NSObject *methodCodec = [FlutterStandardMethodCodec codecWithReaderWriter:[[FLTGoogleMobileAdsReaderWriter alloc] init]]; - _channel = [[FlutterMethodChannel alloc] initWithName:@"plugins.flutter.io/google_mobile_ads" - binaryMessenger:binaryMessenger - codec:methodCodec]; + _channel = [[FlutterMethodChannel alloc] + initWithName:@"plugins.flutter.io/google_mobile_ads" + binaryMessenger:binaryMessenger + codec:methodCodec]; } return self; } @@ -67,7 +68,7 @@ - (void)disposeAllAds { } - (void)showAdWithID:(NSNumber *_Nonnull)adId - rootViewController:(UIViewController *_Nonnull)rootViewController { + rootViewController:(UIViewController *_Nonnull)rootViewController{ id ad = (id)[self adFor:adId]; if (!ad) { @@ -78,12 +79,14 @@ - (void)showAdWithID:(NSNumber *_Nonnull)adId [ad showFromRootViewController:rootViewController]; } -- (void)onAdLoaded:(id _Nonnull)ad responseInfo:(GADResponseInfo *_Nonnull)responseInfo { +- (void)onAdLoaded:(id _Nonnull)ad + responseInfo:(GADResponseInfo *_Nonnull)responseInfo { [_channel invokeMethod:@"onAdEvent" arguments:@{ @"adId" : ad.adId, @"eventName" : @"onAdLoaded", - @"responseInfo" : [[FLTGADResponseInfo alloc] initWithResponseInfo:responseInfo] + @"responseInfo" : [[FLTGADResponseInfo alloc] + initWithResponseInfo:responseInfo] }]; } @@ -96,7 +99,9 @@ - (void)onAdFailedToLoad:(id _Nonnull)ad error:(NSError *_Nonnull)error { }]; } -- (void)onAppEvent:(id _Nonnull)ad name:(NSString *)name data:(NSString *)data { +- (void)onAppEvent:(id _Nonnull)ad + name:(NSString *)name + data:(NSString *)data { [_channel invokeMethod:@"onAdEvent" arguments:@{ @"adId" : ad.adId, @@ -132,8 +137,10 @@ - (void)onRewardedAdUserEarnedReward:(FLTRewardedAd *_Nonnull)ad }]; } -- (void)onRewardedInterstitialAdUserEarnedReward:(FLTRewardedInterstitialAd *_Nonnull)ad - reward:(FLTRewardItem *_Nonnull)reward { +- (void)onRewardedInterstitialAdUserEarnedReward: + (FLTRewardedInterstitialAd *_Nonnull)ad + reward: + (FLTRewardItem *_Nonnull)reward { [_channel invokeMethod:@"onAdEvent" arguments:@{ @"adId" : ad.adId, @@ -232,12 +239,17 @@ - (instancetype)initWithManager:(FLTAdInstanceManager *_Nonnull)manager { viewIdentifier:(int64_t)viewId arguments:(id _Nullable)args { NSNumber *adId = args; - NSObject *view = (NSObject *)[_manager adFor:adId]; + NSObject *view = + (NSObject *)[_manager adFor:adId]; if (!view) { NSString *reason = [NSString - stringWithFormat:@"Could not find an ad with id: %@. Was this ad already disposed?", adId]; - @throw [NSException exceptionWithName:NSInvalidArgumentException reason:reason userInfo:nil]; + stringWithFormat: + @"Could not find an ad with id: %@. Was this ad already disposed?", + adId]; + @throw [NSException exceptionWithName:NSInvalidArgumentException + reason:reason + userInfo:nil]; } return view; } diff --git a/packages/google_mobile_ads/ios/Classes/FLTAdUtil.h b/packages/google_mobile_ads/ios/Classes/FLTAdUtil.h index 92bd01d96..1a0c2f9ff 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAdUtil.h +++ b/packages/google_mobile_ads/ios/Classes/FLTAdUtil.h @@ -23,7 +23,8 @@ + (BOOL)isNotNull:(_Nullable id)object; + (WKWebView *_Nullable)getWebView:(NSNumber *_Nonnull)webViewId - flutterPluginRegistry:(id _Nonnull)flutterPluginRegistry; + flutterPluginRegistry: + (id _Nonnull)flutterPluginRegistry; @property(readonly, class) NSString *_Nonnull requestAgent; diff --git a/packages/google_mobile_ads/ios/Classes/FLTAdUtil.m b/packages/google_mobile_ads/ios/Classes/FLTAdUtil.m index 87d4c2282..8627b3415 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAdUtil.m +++ b/packages/google_mobile_ads/ios/Classes/FLTAdUtil.m @@ -30,20 +30,22 @@ + (BOOL)isNotNull:(id)object { + (NSString *)requestAgent { NSString *newsTemplateString = @""; - id newsTemplateVersion = - [NSBundle.mainBundle objectForInfoDictionaryKey:@"FLTNewsTemplateVersion"]; + id newsTemplateVersion = [NSBundle.mainBundle + objectForInfoDictionaryKey:@"FLTNewsTemplateVersion"]; if ([newsTemplateVersion isKindOfClass:[NSString class]]) { - newsTemplateString = [NSString stringWithFormat:@"_News-%@", newsTemplateVersion]; + newsTemplateString = + [NSString stringWithFormat:@"_News-%@", newsTemplateVersion]; } NSString *gameTemplateString = @""; - id gameTemplateVersion = - [NSBundle.mainBundle objectForInfoDictionaryKey:@"FLTGameTemplateVersion"]; + id gameTemplateVersion = [NSBundle.mainBundle + objectForInfoDictionaryKey:@"FLTGameTemplateVersion"]; if ([gameTemplateVersion isKindOfClass:[NSString class]]) { - gameTemplateString = [NSString stringWithFormat:@"_Game-%@", gameTemplateVersion]; + gameTemplateString = + [NSString stringWithFormat:@"_Game-%@", gameTemplateVersion]; } - return [NSString stringWithFormat:@"%@%@%@", FLT_REQUEST_AGENT_VERSIONED, newsTemplateString, - gameTemplateString]; + return [NSString stringWithFormat:@"%@%@%@", FLT_REQUEST_AGENT_VERSIONED, + newsTemplateString, gameTemplateString]; } + (WKWebView *)getWebView:(NSNumber *)webViewId diff --git a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h index 09e571ee3..2f3264a56 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h +++ b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import -#import #import "FLTAdInstanceManager_Internal.h" #import "FLTGoogleMobileAdsPlugin.h" #import "FLTMediationExtras.h" @@ -21,6 +19,8 @@ #import "FLTMobileAds_Internal.h" #import "FLTNativeTemplateStyle.h" #import "GADTTemplateView.h" +#import +#import @class FLTAdInstanceManager; @protocol FLTNativeAdFactory; @@ -29,7 +29,8 @@ @property(readonly) GADAdSize size; @property(readonly) NSNumber *_Nonnull width; @property(readonly) NSNumber *_Nonnull height; -- (instancetype _Nonnull)initWithWidth:(NSNumber *_Nonnull)width height:(NSNumber *_Nonnull)height; +- (instancetype _Nonnull)initWithWidth:(NSNumber *_Nonnull)width + height:(NSNumber *_Nonnull)height; - (instancetype _Nonnull)initWithAdSize:(GADAdSize)size; @end @@ -38,14 +39,22 @@ * Plugin. */ @interface FLTAdSizeFactory : NSObject -- (GADAdSize)portraitAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width; -- (GADAdSize)landscapeAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width; -- (GADAdSize)currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width; -- (GADAdSize)currentOrientationInlineAdaptiveBannerSizeWithWidth:(NSNumber *_Nonnull)width; -- (GADAdSize)portraitOrientationInlineAdaptiveBannerSizeWithWidth:(NSNumber *_Nonnull)width; -- (GADAdSize)landscapeInlineAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width; -- (GADAdSize)inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:(NSNumber *_Nonnull)width - maxHeight:(NSNumber *_Nonnull)maxHeight; +- (GADAdSize)portraitAnchoredAdaptiveBannerAdSizeWithWidth: + (NSNumber *_Nonnull)width; +- (GADAdSize)landscapeAnchoredAdaptiveBannerAdSizeWithWidth: + (NSNumber *_Nonnull)width; +- (GADAdSize)currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth: + (NSNumber *_Nonnull)width; +- (GADAdSize)currentOrientationInlineAdaptiveBannerSizeWithWidth: + (NSNumber *_Nonnull)width; +- (GADAdSize)portraitOrientationInlineAdaptiveBannerSizeWithWidth: + (NSNumber *_Nonnull)width; +- (GADAdSize)landscapeInlineAdaptiveBannerAdSizeWithWidth: + (NSNumber *_Nonnull)width; +- (GADAdSize) + inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:(NSNumber *_Nonnull)width + maxHeight: + (NSNumber *_Nonnull)maxHeight; @end @@ -78,9 +87,10 @@ @property NSString *_Nullable contentURL; @property BOOL nonPersonalizedAds; @property NSArray *_Nullable neighboringContentURLs; -@property NSString *_Nullable mediationExtrasIdentifier DEPRECATED_MSG_ATTRIBUTE( - "Use mediationExtras instead."); -@property id _Nullable mediationNetworkExtrasProvider +@property NSString *_Nullable mediationExtrasIdentifier + DEPRECATED_MSG_ATTRIBUTE("Use mediationExtras instead."); +@property id< + FLTMediationNetworkExtrasProvider> _Nullable mediationNetworkExtrasProvider DEPRECATED_MSG_ATTRIBUTE("Use mediationExtras instead."); @property NSDictionary *_Nullable adMobExtras; @property NSString *_Nonnull requestAgent; @@ -104,7 +114,8 @@ @property NSString *_Nullable adSourceName; @property NSString *_Nullable adSourceInstanceName; -- (instancetype _Nonnull)initWithResponseInfo:(GADAdNetworkResponseInfo *_Nonnull)responseInfo; +- (instancetype _Nonnull)initWithResponseInfo: + (GADAdNetworkResponseInfo *_Nonnull)responseInfo; @end /** @@ -117,7 +128,8 @@ @property FLTGADAdNetworkResponseInfo *_Nullable loadedAdNetworkResponseInfo; @property NSDictionary *_Nullable extrasDictionary; -- (instancetype _Nonnull)initWithResponseInfo:(GADResponseInfo *_Nonnull)responseInfo; +- (instancetype _Nonnull)initWithResponseInfo: + (GADResponseInfo *_Nonnull)responseInfo; @end /** @@ -138,7 +150,8 @@ */ @interface FLTGAMAdRequest : FLTAdRequest @property NSDictionary *_Nullable customTargeting; -@property NSDictionary *> *_Nullable customTargetingLists; +@property NSDictionary *> + *_Nullable customTargetingLists; @property NSString *_Nullable pubProvidedID; - (GAMRequest *_Nonnull)asGAMRequest:(NSString *_Nonnull)adUnitId; @@ -158,11 +171,13 @@ @property(readonly) NSNumber *_Nonnull adId; @end -@interface FLTBannerAd : FLTBaseAd +@interface FLTBannerAd + : FLTBaseAd - (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId size:(FLTAdSize *_Nonnull)size request:(FLTAdRequest *_Nonnull)request - rootViewController:(UIViewController *_Nonnull)rootViewController + rootViewController: + (UIViewController *_Nonnull)rootViewController adId:(NSNumber *_Nonnull)adId; - (FLTAdSize *_Nullable)getAdSize; - (GADBannerView *_Nonnull)bannerView; @@ -175,7 +190,8 @@ - (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId sizes:(NSArray *_Nonnull)sizes request:(FLTGAMAdRequest *_Nonnull)request - rootViewController:(UIViewController *_Nonnull)rootViewController + rootViewController: + (UIViewController *_Nonnull)rootViewController adId:(NSNumber *_Nonnull)adId; @end @@ -186,11 +202,13 @@ @interface FLTFluidGAMBannerAd : FLTGAMBannerAd - (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId request:(FLTGAMAdRequest *_Nonnull)request - rootViewController:(UIViewController *_Nonnull)rootViewController + rootViewController: + (UIViewController *_Nonnull)rootViewController adId:(NSNumber *_Nonnull)adId; @end -@interface FLTFullScreenAd : FLTBaseAd +@interface FLTFullScreenAd + : FLTBaseAd @end @interface FLTInterstitialAd : FLTFullScreenAd @@ -238,9 +256,10 @@ @property(readonly) NSNumber *_Nullable clickToExpandRequested; @property(readonly) NSNumber *_Nullable customControlsRequested; @property(readonly) NSNumber *_Nullable startMuted; -- (instancetype _Nonnull)initWithClickToExpandRequested:(NSNumber *_Nullable)clickToExpandRequested - customControlsRequested:(NSNumber *_Nullable)customControlsRequested - startMuted:(NSNumber *_Nullable)startMuted; +- (instancetype _Nonnull) + initWithClickToExpandRequested:(NSNumber *_Nullable)clickToExpandRequested + customControlsRequested:(NSNumber *_Nullable)customControlsRequested + startMuted:(NSNumber *_Nullable)startMuted; - (GADVideoOptions *_Nonnull)asGADVideoOptions; @end @@ -253,34 +272,39 @@ @property(readonly) NSNumber *_Nullable shouldRequestMultipleImages; @property(readonly) NSNumber *_Nullable shouldReturnUrlsForImageAssets; -- (instancetype _Nonnull)initWithAdChoicesPlacement:(NSNumber *_Nullable)adChoicesPlacement - mediaAspectRatio:(NSNumber *_Nullable)mediaAspectRatio - videoOptions:(FLTVideoOptions *_Nullable)videoOptions - requestCustomMuteThisAd:(NSNumber *_Nullable)requestCustomMuteThisAd - shouldRequestMultipleImages:(NSNumber *_Nullable)shouldRequestMultipleImages - shouldReturnUrlsForImageAssets: - (NSNumber *_Nullable)shouldReturnUrlsForImageAssets; +- (instancetype _Nonnull) + initWithAdChoicesPlacement:(NSNumber *_Nullable)adChoicesPlacement + mediaAspectRatio:(NSNumber *_Nullable)mediaAspectRatio + videoOptions:(FLTVideoOptions *_Nullable)videoOptions + requestCustomMuteThisAd:(NSNumber *_Nullable)requestCustomMuteThisAd + shouldRequestMultipleImages: + (NSNumber *_Nullable)shouldRequestMultipleImages + shouldReturnUrlsForImageAssets: + (NSNumber *_Nullable)shouldReturnUrlsForImageAssets; - (NSArray *_Nonnull)asGADAdLoaderOptions; @end @interface FLTNativeAd - : FLTBaseAd -- (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId - request:(FLTAdRequest *_Nonnull)request - nativeAdFactory:(NSObject *_Nonnull)nativeAdFactory - customOptions:(NSDictionary *_Nullable)customOptions - rootViewController:(UIViewController *_Nonnull)rootViewController - adId:(NSNumber *_Nonnull)adId - nativeAdOptions:(FLTNativeAdOptions *_Nullable)nativeAdOptions - nativeTemplateStyle:(FLTNativeTemplateStyle *_Nullable)nativeTemplateStyle; + : FLTBaseAd +- (instancetype _Nonnull) + initWithAdUnitId:(NSString *_Nonnull)adUnitId + request:(FLTAdRequest *_Nonnull)request + nativeAdFactory:(NSObject *_Nonnull)nativeAdFactory + customOptions:(NSDictionary *_Nullable)customOptions + rootViewController:(UIViewController *_Nonnull)rootViewController + adId:(NSNumber *_Nonnull)adId + nativeAdOptions:(FLTNativeAdOptions *_Nullable)nativeAdOptions + nativeTemplateStyle:(FLTNativeTemplateStyle *_Nullable)nativeTemplateStyle; - (GADAdLoader *_Nonnull)adLoader; @end @interface FLTRewardItem : NSObject @property(readonly) NSNumber *_Nonnull amount; @property(readonly) NSString *_Nonnull type; -- (instancetype _Nonnull)initWithAmount:(NSNumber *_Nonnull)amount type:(NSString *_Nonnull)type; +- (instancetype _Nonnull)initWithAmount:(NSNumber *_Nonnull)amount + type:(NSString *_Nonnull)type; @end @interface FLTAdValue : NSObject diff --git a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m index a2c2d36ea..12ae3348a 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m @@ -17,9 +17,10 @@ #import "FLTNativeTemplateStyle.h" @implementation FLTAdSize -- (instancetype _Nonnull)initWithWidth:(NSNumber *_Nonnull)width height:(NSNumber *_Nonnull)height { - return - [self initWithAdSize:GADAdSizeFromCGSize(CGSizeMake(width.doubleValue, height.doubleValue))]; +- (instancetype _Nonnull)initWithWidth:(NSNumber *_Nonnull)width + height:(NSNumber *_Nonnull)height { + return [self initWithAdSize:GADAdSizeFromCGSize(CGSizeMake( + width.doubleValue, height.doubleValue))]; } - (instancetype _Nonnull)initWithAdSize:(GADAdSize)size { @@ -34,31 +35,42 @@ - (instancetype _Nonnull)initWithAdSize:(GADAdSize)size { @end @implementation FLTAdSizeFactory -- (GADAdSize)portraitAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width { +- (GADAdSize)portraitAnchoredAdaptiveBannerAdSizeWithWidth: + (NSNumber *_Nonnull)width { return GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth(width.doubleValue); } -- (GADAdSize)landscapeAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width { +- (GADAdSize)landscapeAnchoredAdaptiveBannerAdSizeWithWidth: + (NSNumber *_Nonnull)width { return GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth(width.doubleValue); } -- (GADAdSize)currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width { - return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(width.doubleValue); +- (GADAdSize)currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth: + (NSNumber *_Nonnull)width { + return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth( + width.doubleValue); } -- (GADAdSize)currentOrientationInlineAdaptiveBannerSizeWithWidth:(NSNumber *_Nonnull)width { - return GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(width.floatValue); +- (GADAdSize)currentOrientationInlineAdaptiveBannerSizeWithWidth: + (NSNumber *_Nonnull)width { + return GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth( + width.floatValue); } -- (GADAdSize)portraitOrientationInlineAdaptiveBannerSizeWithWidth:(NSNumber *_Nonnull)width { +- (GADAdSize)portraitOrientationInlineAdaptiveBannerSizeWithWidth: + (NSNumber *_Nonnull)width { return GADPortraitInlineAdaptiveBannerAdSizeWithWidth(width.floatValue); } -- (GADAdSize)landscapeInlineAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width { +- (GADAdSize)landscapeInlineAdaptiveBannerAdSizeWithWidth: + (NSNumber *_Nonnull)width { return GADLandscapeInlineAdaptiveBannerAdSizeWithWidth(width.floatValue); } -- (GADAdSize)inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:(NSNumber *_Nonnull)width - maxHeight:(NSNumber *_Nonnull)maxHeight { - return GADInlineAdaptiveBannerAdSizeWithWidthAndMaxHeight(width.floatValue, maxHeight.floatValue); +- (GADAdSize) + inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:(NSNumber *_Nonnull)width + maxHeight: + (NSNumber *_Nonnull)maxHeight { + return GADInlineAdaptiveBannerAdSizeWithWidthAndMaxHeight( + width.floatValue, maxHeight.floatValue); } @end @@ -69,7 +81,8 @@ - (instancetype _Nonnull)initWithFactory:(FLTAdSizeFactory *_Nonnull)factory width:(NSNumber *_Nonnull)width { GADAdSize size; if ([FLTAdUtil isNull:orientation]) { - size = [factory currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:width]; + size = + [factory currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:width]; } else if ([orientation isEqualToString:@"portrait"]) { size = [factory portraitAnchoredAdaptiveBannerAdSizeWithWidth:width]; } else if ([orientation isEqualToString:@"landscape"]) { @@ -94,13 +107,18 @@ - (instancetype _Nonnull)initWithFactory:(FLTAdSizeFactory *_Nonnull)factory orientation:(NSNumber *_Nullable)orientation { GADAdSize gadAdSize; if ([FLTAdUtil isNotNull:orientation]) { - gadAdSize = orientation.intValue == 0 - ? [factory portraitOrientationInlineAdaptiveBannerSizeWithWidth:width] - : [factory landscapeInlineAdaptiveBannerAdSizeWithWidth:width]; + gadAdSize = + orientation.intValue == 0 + ? [factory + portraitOrientationInlineAdaptiveBannerSizeWithWidth:width] + : [factory landscapeInlineAdaptiveBannerAdSizeWithWidth:width]; } else if ([FLTAdUtil isNotNull:maxHeight]) { - gadAdSize = [factory inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:width maxHeight:maxHeight]; + gadAdSize = + [factory inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:width + maxHeight:maxHeight]; } else { - gadAdSize = [factory currentOrientationInlineAdaptiveBannerSizeWithWidth:width]; + gadAdSize = + [factory currentOrientationInlineAdaptiveBannerSizeWithWidth:width]; } self = [self initWithAdSize:gadAdSize]; if (self) { @@ -122,7 +140,8 @@ - (instancetype _Nonnull)initWithOrientation:(NSString *_Nonnull)orientation { size = kGADAdSizeSmartBannerLandscape; #pragma clang diagnostic pop } else { - NSLog(@"SmartBanner orientation should be 'portrait' or 'landscape': %@", orientation); + NSLog(@"SmartBanner orientation should be 'portrait' or 'landscape': %@", + orientation); return nil; } @@ -150,18 +169,21 @@ - (void)addNetworkExtrasToGADRequest:(GADRequest *_Nonnull)request @implementation FLTAdRequest -- (void)addNetworkExtrasToGADRequest:(GADRequest *)request adUnitId:(NSString *_Nonnull)adUnitId { +- (void)addNetworkExtrasToGADRequest:(GADRequest *)request + adUnitId:(NSString *_Nonnull)adUnitId { NSArray> *extras; if (_mediationExtras != NULL) { - NSMutableArray> *flutterExtras = [NSMutableArray array]; + NSMutableArray> *flutterExtras = + [NSMutableArray array]; for (id extra in _mediationExtras) { [flutterExtras addObject:[extra getMediationExtras]]; } extras = [NSArray arrayWithArray:flutterExtras]; } else { - extras = [_mediationNetworkExtrasProvider getMediationExtras:adUnitId - mediationExtrasIdentifier:_mediationExtrasIdentifier]; + extras = [_mediationNetworkExtrasProvider + getMediationExtras:adUnitId + mediationExtrasIdentifier:_mediationExtrasIdentifier]; } BOOL addedNpaToGADExtras = false; @@ -170,8 +192,8 @@ - (void)addNetworkExtrasToGADRequest:(GADRequest *)request adUnitId:(NSString *_ // If GADExtras are present and npa is true, add npa = 1 to the GADExtras if ([extra isKindOfClass:[GADExtras class]] && _nonPersonalizedAds) { GADExtras *gadExtras = (GADExtras *)extra; - NSMutableDictionary *newParams = - [[NSMutableDictionary alloc] initWithDictionary:gadExtras.additionalParameters]; + NSMutableDictionary *newParams = [[NSMutableDictionary alloc] + initWithDictionary:gadExtras.additionalParameters]; newParams[@"npa"] = @"1"; gadExtras.additionalParameters = newParams; [request registerAdNetworkExtras:gadExtras]; @@ -218,20 +240,25 @@ - (GADRequest *_Nonnull)asGADRequest:(NSString *_Nonnull)adUnitId { @implementation FLTGADResponseInfo -- (instancetype _Nonnull)initWithResponseInfo:(GADResponseInfo *_Nonnull)responseInfo { +- (instancetype _Nonnull)initWithResponseInfo: + (GADResponseInfo *_Nonnull)responseInfo { self = [super init]; if (self) { _responseIdentifier = responseInfo.responseIdentifier; - _adNetworkClassName = responseInfo.loadedAdNetworkResponseInfo.adNetworkClassName; - NSMutableArray *infoArray = [[NSMutableArray alloc] init]; - for (GADAdNetworkResponseInfo *adNetworkInfo in responseInfo.adNetworkInfoArray) { - [infoArray - addObject:[[FLTGADAdNetworkResponseInfo alloc] initWithResponseInfo:adNetworkInfo]]; + _adNetworkClassName = + responseInfo.loadedAdNetworkResponseInfo.adNetworkClassName; + NSMutableArray *infoArray = + [[NSMutableArray alloc] init]; + for (GADAdNetworkResponseInfo *adNetworkInfo in responseInfo + .adNetworkInfoArray) { + [infoArray addObject:[[FLTGADAdNetworkResponseInfo alloc] + initWithResponseInfo:adNetworkInfo]]; } _adNetworkInfoArray = infoArray; _loadedAdNetworkResponseInfo = [[FLTGADAdNetworkResponseInfo alloc] initWithResponseInfo:responseInfo.loadedAdNetworkResponseInfo]; - _extrasDictionary = responseInfo.extrasDictionary ? responseInfo.extrasDictionary : @{}; + _extrasDictionary = + responseInfo.extrasDictionary ? responseInfo.extrasDictionary : @{}; } return self; } @@ -239,11 +266,13 @@ - (instancetype _Nonnull)initWithResponseInfo:(GADResponseInfo *_Nonnull)respons @implementation FLTGADAdNetworkResponseInfo -- (instancetype _Nonnull)initWithResponseInfo:(GADAdNetworkResponseInfo *_Nonnull)responseInfo { +- (instancetype _Nonnull)initWithResponseInfo: + (GADAdNetworkResponseInfo *_Nonnull)responseInfo { self = [super init]; if (self) { _adNetworkClassName = responseInfo.adNetworkClassName; - NSNumber *timeInMillis = [[NSNumber alloc] initWithDouble:responseInfo.latency * 1000]; + NSNumber *timeInMillis = + [[NSNumber alloc] initWithDouble:responseInfo.latency * 1000]; _latency = @(timeInMillis.longValue); _dictionaryDescription = responseInfo.dictionaryRepresentation.description; _adUnitMapping = [[NSMutableDictionary alloc] init]; @@ -274,9 +303,11 @@ - (instancetype _Nonnull)initWithError:(NSError *_Nonnull)error { _code = error.code; _domain = error.domain; _message = error.localizedDescription; - GADResponseInfo *responseInfo = error.userInfo[GADErrorUserInfoKeyResponseInfo]; + GADResponseInfo *responseInfo = + error.userInfo[GADErrorUserInfoKeyResponseInfo]; if (responseInfo) { - _responseInfo = [[FLTGADResponseInfo alloc] initWithResponseInfo:responseInfo]; + _responseInfo = + [[FLTGADResponseInfo alloc] initWithResponseInfo:responseInfo]; } } return self; @@ -297,7 +328,8 @@ - (GADRequest *_Nonnull)asGAMRequest:(NSString *_Nonnull)adUnitId { NSMutableDictionary *targetingDictionary = [NSMutableDictionary dictionaryWithDictionary:self.customTargeting]; for (NSString *key in self.customTargetingLists) { - targetingDictionary[key] = [self.customTargetingLists[key] componentsJoinedByString:@","]; + targetingDictionary[key] = + [self.customTargetingLists[key] componentsJoinedByString:@","]; } request.customTargeting = targetingDictionary; [self addNetworkExtrasToGADRequest:request adUnitId:adUnitId]; @@ -342,9 +374,10 @@ - (instancetype)initWithAdUnitId:(NSString *_Nonnull)adUnitId return; } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] + initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; } return self; @@ -372,7 +405,8 @@ - (void)bannerViewDidReceiveAd:(GADBannerView *)bannerView { [manager onAdLoaded:self responseInfo:bannerView.responseInfo]; } -- (void)bannerView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(NSError *)error { +- (void)bannerView:(GADBannerView *)bannerView + didFailToReceiveAdWithError:(NSError *)error { [manager onAdFailedToLoad:self error:error]; } @@ -428,7 +462,8 @@ - (instancetype)initWithAdUnitId:(NSString *_Nonnull)adUnitId _bannerView.appEventDelegate = self; _bannerView.delegate = self; - NSMutableArray *validAdSizes = [NSMutableArray arrayWithCapacity:sizes.count]; + NSMutableArray *validAdSizes = + [NSMutableArray arrayWithCapacity:sizes.count]; for (FLTAdSize *size in sizes) { [validAdSizes addObject:NSValueFromGADAdSize(size.size)]; } @@ -440,9 +475,10 @@ - (instancetype)initWithAdUnitId:(NSString *_Nonnull)adUnitId return; } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] + initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; } return self; @@ -504,9 +540,10 @@ - (instancetype)initWithAdUnitId:(NSString *_Nonnull)adUnitId return; } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] + initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; } return self; @@ -533,23 +570,27 @@ - (nonnull UIView *)view { [scrollView addSubview:_bannerView]; _bannerView.translatesAutoresizingMaskIntoConstraints = false; - NSLayoutConstraint *width = [NSLayoutConstraint constraintWithItem:_bannerView - attribute:NSLayoutAttributeWidth - relatedBy:0 - toItem:scrollView - attribute:NSLayoutAttributeWidth - multiplier:1.0 - constant:0]; + NSLayoutConstraint *width = + [NSLayoutConstraint constraintWithItem:_bannerView + attribute:NSLayoutAttributeWidth + relatedBy:0 + toItem:scrollView + attribute:NSLayoutAttributeWidth + multiplier:1.0 + constant:0]; [scrollView addConstraint:width]; _containerView = scrollView; - [_bannerView.widthAnchor constraintEqualToAnchor:scrollView.widthAnchor].active = YES; - [_bannerView.topAnchor constraintEqualToAnchor:scrollView.topAnchor].active = YES; + [_bannerView.widthAnchor constraintEqualToAnchor:scrollView.widthAnchor] + .active = YES; + [_bannerView.topAnchor constraintEqualToAnchor:scrollView.topAnchor].active = + YES; return scrollView; } #pragma mark - GADAdSizeDelegate -- (void)adView:(GADBannerView *)bannerView willChangeAdSizeTo:(GADAdSize)adSize { +- (void)adView:(GADBannerView *)bannerView + willChangeAdSizeTo:(GADAdSize)adSize { CGFloat height = adSize.size.height; [self.manager onFluidAdHeightChanged:self height:height]; } @@ -573,14 +614,16 @@ @implementation FLTFullScreenAd { - (void)load { // Must be overridden by subclasses - [NSException raise:NSInternalInconsistencyException - format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; + [NSException + raise:NSInternalInconsistencyException + format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; } - (void)showFromRootViewController:(UIViewController *)rootViewController { // Must be overridden by subclasses - [NSException raise:NSInternalInconsistencyException - format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; + [NSException + raise:NSInternalInconsistencyException + format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; } - (void)ad:(nonnull id)ad @@ -588,25 +631,30 @@ - (void)ad:(nonnull id)ad [manager didFailToPresentFullScreenContentWithError:self error:error]; } -- (void)adWillPresentFullScreenContent:(nonnull id)ad { +- (void)adWillPresentFullScreenContent: + (nonnull id)ad { // Manually hide the status bar. This is a fix for // https://github.com/googleads/googleads-mobile-flutter/issues/191 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - _statusBarVisibilityBeforeAdShow = UIApplication.sharedApplication.statusBarHidden; + _statusBarVisibilityBeforeAdShow = + UIApplication.sharedApplication.statusBarHidden; [UIApplication.sharedApplication setStatusBarHidden:YES]; #pragma clang diagnostic pop [manager adWillPresentFullScreenContent:self]; } -- (void)adDidDismissFullScreenContent:(nonnull id)ad { +- (void)adDidDismissFullScreenContent: + (nonnull id)ad { [manager adDidDismissFullScreenContent:self]; } -- (void)adWillDismissFullScreenContent:(nonnull id)ad { +- (void)adWillDismissFullScreenContent: + (nonnull id)ad { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - [UIApplication.sharedApplication setStatusBarHidden:_statusBarVisibilityBeforeAdShow]; + [UIApplication.sharedApplication + setStatusBarHidden:_statusBarVisibilityBeforeAdShow]; #pragma clang diagnostic pop [manager adWillDismissFullScreenContent:self]; } @@ -650,30 +698,32 @@ - (NSString *_Nonnull)adUnitId { } - (void)load { - [GADInterstitialAd loadWithAdUnitID:_adUnitId - request:[_adRequest asGADRequest:_adUnitId] - completionHandler:^(GADInterstitialAd *ad, NSError *error) { - if (error) { - [self.manager onAdFailedToLoad:self error:error]; - return; - } - - ad.fullScreenContentDelegate = self; - self->_interstitialView = ad; - __weak FLTInterstitialAd *weakSelf = self; - ad.paidEventHandler = ^(GADAdValue *_Nonnull value) { - if (weakSelf.manager == nil) { - return; - } - [weakSelf.manager - onPaidEvent:weakSelf - value:[[FLTAdValue alloc] initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; - }; - - [self.manager onAdLoaded:self responseInfo:ad.responseInfo]; - }]; + [GADInterstitialAd + loadWithAdUnitID:_adUnitId + request:[_adRequest asGADRequest:_adUnitId] + completionHandler:^(GADInterstitialAd *ad, NSError *error) { + if (error) { + [self.manager onAdFailedToLoad:self error:error]; + return; + } + + ad.fullScreenContentDelegate = self; + self->_interstitialView = ad; + __weak FLTInterstitialAd *weakSelf = self; + ad.paidEventHandler = ^(GADAdValue *_Nonnull value) { + if (weakSelf.manager == nil) { + return; + } + [weakSelf.manager + onPaidEvent:weakSelf + value:[[FLTAdValue alloc] + initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; + }; + + [self.manager onAdLoaded:self responseInfo:ad.responseInfo]; + }]; } - (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewController { @@ -729,9 +779,10 @@ - (void)load { } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] + initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; self->_insterstitial = ad; @@ -793,7 +844,8 @@ - (void)load { [GADRewardedAd loadWithAdUnitID:_adUnitId request:request - completionHandler:^(GADRewardedAd *_Nullable rewardedAd, NSError *_Nullable error) { + completionHandler:^(GADRewardedAd *_Nullable rewardedAd, + NSError *_Nullable error) { if (error) { [self.manager onAdFailedToLoad:self error:error]; return; @@ -805,26 +857,30 @@ - (void)load { } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] + initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; rewardedAd.fullScreenContentDelegate = self; self->_rewardedView = rewardedAd; - [self.manager onAdLoaded:self responseInfo:rewardedAd.responseInfo]; + [self.manager onAdLoaded:self + responseInfo:rewardedAd.responseInfo]; }]; } - (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewController { if (self.rewardedAd) { - [self.rewardedAd presentFromRootViewController:rootViewController - userDidEarnRewardHandler:^{ - GADAdReward *reward = self.rewardedAd.adReward; - FLTRewardItem *fltReward = - [[FLTRewardItem alloc] initWithAmount:reward.amount - type:reward.type]; - [self.manager onRewardedAdUserEarnedReward:self reward:fltReward]; - }]; + [self.rewardedAd + presentFromRootViewController:rootViewController + userDidEarnRewardHandler:^{ + GADAdReward *reward = self.rewardedAd.adReward; + FLTRewardItem *fltReward = + [[FLTRewardItem alloc] initWithAmount:reward.amount + type:reward.type]; + [self.manager onRewardedAdUserEarnedReward:self + reward:fltReward]; + }]; } else { NSLog(@"RewardedAd failed to show because the ad was not ready."); } @@ -881,25 +937,30 @@ - (void)load { [GADRewardedInterstitialAd loadWithAdUnitID:_adUnitId request:request - completionHandler:^(GADRewardedInterstitialAd *_Nullable rewardedInterstitialAd, - NSError *_Nullable error) { + completionHandler:^( + GADRewardedInterstitialAd *_Nullable rewardedInterstitialAd, + NSError *_Nullable error) { if (error) { [self.manager onAdFailedToLoad:self error:error]; return; } __weak FLTRewardedInterstitialAd *weakSelf = self; - rewardedInterstitialAd.paidEventHandler = ^(GADAdValue *_Nonnull value) { - if (weakSelf.manager == nil) { - return; - } - [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; - }; + rewardedInterstitialAd.paidEventHandler = + ^(GADAdValue *_Nonnull value) { + if (weakSelf.manager == nil) { + return; + } + [weakSelf.manager + onPaidEvent:weakSelf + value:[[FLTAdValue alloc] + initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; + }; rewardedInterstitialAd.fullScreenContentDelegate = self; self->_rewardedInterstitialView = rewardedInterstitialAd; - [self.manager onAdLoaded:self responseInfo:rewardedInterstitialAd.responseInfo]; + [self.manager onAdLoaded:self + responseInfo:rewardedInterstitialAd.responseInfo]; }]; } @@ -909,12 +970,16 @@ - (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewControlle presentFromRootViewController:rootViewController userDidEarnRewardHandler:^{ GADAdReward *reward = self.rewardedInterstitialAd.adReward; - FLTRewardItem *fltReward = [[FLTRewardItem alloc] initWithAmount:reward.amount - type:reward.type]; - [self.manager onRewardedInterstitialAdUserEarnedReward:self reward:fltReward]; + FLTRewardItem *fltReward = + [[FLTRewardItem alloc] initWithAmount:reward.amount + type:reward.type]; + [self.manager + onRewardedInterstitialAdUserEarnedReward:self + reward:fltReward]; }]; } else { - NSLog(@"RewardedInterstitialAd failed to show because the ad was not ready."); + NSLog( + @"RewardedInterstitialAd failed to show because the ad was not ready."); } } @@ -968,7 +1033,8 @@ - (void)load { [GADAppOpenAd loadWithAdUnitID:_adUnitId request:request - completionHandler:^(GADAppOpenAd *_Nullable appOpenAd, NSError *_Nullable error) { + completionHandler:^(GADAppOpenAd *_Nullable appOpenAd, + NSError *_Nullable error) { if (error) { [self.manager onAdFailedToLoad:self error:error]; return; @@ -980,14 +1046,16 @@ - (void)load { } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] + initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; appOpenAd.fullScreenContentDelegate = self; self->_appOpenAd = appOpenAd; - [self.manager onAdLoaded:self responseInfo:appOpenAd.responseInfo]; + [self.manager onAdLoaded:self + responseInfo:appOpenAd.responseInfo]; }]; } @@ -1014,14 +1082,15 @@ @implementation FLTNativeAd { FLTNativeTemplateStyle *_nativeTemplateStyle; } -- (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId - request:(FLTAdRequest *_Nonnull)request - nativeAdFactory:(NSObject *_Nonnull)nativeAdFactory - customOptions:(NSDictionary *_Nullable)customOptions - rootViewController:(UIViewController *_Nonnull)rootViewController - adId:(NSNumber *_Nonnull)adId - nativeAdOptions:(FLTNativeAdOptions *_Nullable)nativeAdOptions - nativeTemplateStyle:(FLTNativeTemplateStyle *_Nullable)nativeTemplateStyle { +- (instancetype _Nonnull) + initWithAdUnitId:(NSString *_Nonnull)adUnitId + request:(FLTAdRequest *_Nonnull)request + nativeAdFactory:(NSObject *_Nonnull)nativeAdFactory + customOptions:(NSDictionary *_Nullable)customOptions + rootViewController:(UIViewController *_Nonnull)rootViewController + adId:(NSNumber *_Nonnull)adId + nativeAdOptions:(FLTNativeAdOptions *_Nullable)nativeAdOptions + nativeTemplateStyle:(FLTNativeTemplateStyle *_Nullable)nativeTemplateStyle { self = [super init]; if (self) { self.adId = adId; @@ -1034,10 +1103,11 @@ - (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId ? @[] : nativeAdOptions.asGADAdLoaderOptions; - _adLoader = [[GADAdLoader alloc] initWithAdUnitID:_adUnitId - rootViewController:rootViewController - adTypes:@[ GADAdLoaderAdTypeNative ] - options:adLoaderOptions]; + _adLoader = + [[GADAdLoader alloc] initWithAdUnitID:_adUnitId + rootViewController:rootViewController + adTypes:@[ GADAdLoaderAdTypeNative ] + options:adLoaderOptions]; _nativeAdOptions = nativeAdOptions; _nativeTemplateStyle = nativeTemplateStyle; self.adLoader.delegate = self; @@ -1063,14 +1133,16 @@ - (void)load { #pragma mark - GADNativeAdLoaderDelegate -- (void)adLoader:(GADAdLoader *)adLoader didReceiveNativeAd:(GADNativeAd *)nativeAd { +- (void)adLoader:(GADAdLoader *)adLoader + didReceiveNativeAd:(GADNativeAd *)nativeAd { // Use Nil instead of Null to fix crash with Swift integrations. NSDictionary *customOptions = [[NSNull null] isEqual:_customOptions] ? nil : _customOptions; if ([FLTAdUtil isNotNull:_nativeTemplateStyle]) { _view = [_nativeTemplateStyle getDisplayedView:nativeAd]; } else if ([FLTAdUtil isNotNull:_nativeAdFactory]) { - _view = [_nativeAdFactory createNativeAd:nativeAd customOptions:customOptions]; + _view = [_nativeAdFactory createNativeAd:nativeAd + customOptions:customOptions]; } nativeAd.delegate = self; @@ -1080,15 +1152,17 @@ - (void)adLoader:(GADAdLoader *)adLoader didReceiveNativeAd:(GADNativeAd *)nativ if (weakSelf.manager == nil) { return; } - [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + [weakSelf.manager + onPaidEvent:weakSelf + value:[[FLTAdValue alloc] initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; [manager onAdLoaded:self responseInfo:nativeAd.responseInfo]; } -- (void)adLoader:(GADAdLoader *)adLoader didFailToReceiveAdWithError:(NSError *)error { +- (void)adLoader:(GADAdLoader *)adLoader + didFailToReceiveAdWithError:(NSError *)error { [manager onAdFailedToLoad:self error:error]; } @@ -1124,7 +1198,8 @@ - (UIView *)view { @end @implementation FLTRewardItem -- (instancetype _Nonnull)initWithAmount:(NSNumber *_Nonnull)amount type:(NSString *_Nonnull)type { +- (instancetype _Nonnull)initWithAmount:(NSNumber *_Nonnull)amount + type:(NSString *_Nonnull)type { self = [super init]; if (self) { _amount = amount; @@ -1156,7 +1231,8 @@ - (instancetype _Nonnull)initWithValue:(NSDecimalNumber *_Nonnull)value self = [super init]; if (self) { _valueMicros = - [value decimalNumberByMultiplyingBy:[[NSDecimalNumber alloc] initWithInteger:1000000]]; + [value decimalNumberByMultiplyingBy:[[NSDecimalNumber alloc] + initWithInteger:1000000]]; _precision = precision; _currencyCode = currencyCode; } @@ -1165,9 +1241,10 @@ - (instancetype _Nonnull)initWithValue:(NSDecimalNumber *_Nonnull)value @end @implementation FLTVideoOptions -- (instancetype _Nonnull)initWithClickToExpandRequested:(NSNumber *_Nullable)clickToExpandRequested - customControlsRequested:(NSNumber *_Nullable)customControlsRequested - startMuted:(NSNumber *_Nullable)startMuted { +- (instancetype _Nonnull) + initWithClickToExpandRequested:(NSNumber *_Nullable)clickToExpandRequested + customControlsRequested:(NSNumber *_Nullable)customControlsRequested + startMuted:(NSNumber *_Nullable)startMuted { self = [super init]; if (self) { _clickToExpandRequested = clickToExpandRequested; @@ -1194,13 +1271,15 @@ - (GADVideoOptions *_Nonnull)asGADVideoOptions { @end @implementation FLTNativeAdOptions -- (instancetype _Nonnull)initWithAdChoicesPlacement:(NSNumber *_Nullable)adChoicesPlacement - mediaAspectRatio:(NSNumber *_Nullable)mediaAspectRatio - videoOptions:(FLTVideoOptions *_Nullable)videoOptions - requestCustomMuteThisAd:(NSNumber *_Nullable)requestCustomMuteThisAd - shouldRequestMultipleImages:(NSNumber *_Nullable)shouldRequestMultipleImages - shouldReturnUrlsForImageAssets: - (NSNumber *_Nullable)shouldReturnUrlsForImageAssets { +- (instancetype _Nonnull) + initWithAdChoicesPlacement:(NSNumber *_Nullable)adChoicesPlacement + mediaAspectRatio:(NSNumber *_Nullable)mediaAspectRatio + videoOptions:(FLTVideoOptions *_Nullable)videoOptions + requestCustomMuteThisAd:(NSNumber *_Nullable)requestCustomMuteThisAd + shouldRequestMultipleImages: + (NSNumber *_Nullable)shouldRequestMultipleImages + shouldReturnUrlsForImageAssets: + (NSNumber *_Nullable)shouldReturnUrlsForImageAssets { self = [super init]; if (self) { _adChoicesPlacement = adChoicesPlacement; @@ -1216,60 +1295,69 @@ - (instancetype _Nonnull)initWithAdChoicesPlacement:(NSNumber *_Nullable)adChoic - (NSArray *_Nonnull)asGADAdLoaderOptions { NSMutableArray *options = [NSMutableArray array]; - GADNativeAdImageAdLoaderOptions *imageOptions = [[GADNativeAdImageAdLoaderOptions alloc] init]; + GADNativeAdImageAdLoaderOptions *imageOptions = + [[GADNativeAdImageAdLoaderOptions alloc] init]; if ([FLTAdUtil isNotNull:_shouldReturnUrlsForImageAssets]) { - imageOptions.disableImageLoading = _shouldReturnUrlsForImageAssets.boolValue; + imageOptions.disableImageLoading = + _shouldReturnUrlsForImageAssets.boolValue; } if ([FLTAdUtil isNotNull:_shouldRequestMultipleImages]) { - imageOptions.shouldRequestMultipleImages = _shouldRequestMultipleImages.boolValue; + imageOptions.shouldRequestMultipleImages = + _shouldRequestMultipleImages.boolValue; } [options addObject:imageOptions]; if ([FLTAdUtil isNotNull:_adChoicesPlacement]) { - GADNativeAdViewAdOptions *adViewOptions = [[GADNativeAdViewAdOptions alloc] init]; + GADNativeAdViewAdOptions *adViewOptions = + [[GADNativeAdViewAdOptions alloc] init]; switch (_adChoicesPlacement.intValue) { - case 0: - adViewOptions.preferredAdChoicesPosition = GADAdChoicesPositionTopRightCorner; - break; - case 1: - adViewOptions.preferredAdChoicesPosition = GADAdChoicesPositionTopLeftCorner; - break; - case 2: - adViewOptions.preferredAdChoicesPosition = GADAdChoicesPositionBottomRightCorner; - break; - case 3: - adViewOptions.preferredAdChoicesPosition = GADAdChoicesPositionBottomLeftCorner; - break; - default: - NSLog(@"AdChoicesPlacement should be an int in the range [0, 3]: %d", - _adChoicesPlacement.intValue); - break; + case 0: + adViewOptions.preferredAdChoicesPosition = + GADAdChoicesPositionTopRightCorner; + break; + case 1: + adViewOptions.preferredAdChoicesPosition = + GADAdChoicesPositionTopLeftCorner; + break; + case 2: + adViewOptions.preferredAdChoicesPosition = + GADAdChoicesPositionBottomRightCorner; + break; + case 3: + adViewOptions.preferredAdChoicesPosition = + GADAdChoicesPositionBottomLeftCorner; + break; + default: + NSLog(@"AdChoicesPlacement should be an int in the range [0, 3]: %d", + _adChoicesPlacement.intValue); + break; } [options addObject:adViewOptions]; } if ([FLTAdUtil isNotNull:_mediaAspectRatio]) { - GADNativeAdMediaAdLoaderOptions *mediaOptions = [[GADNativeAdMediaAdLoaderOptions alloc] init]; + GADNativeAdMediaAdLoaderOptions *mediaOptions = + [[GADNativeAdMediaAdLoaderOptions alloc] init]; switch (_mediaAspectRatio.intValue) { - case 0: - mediaOptions.mediaAspectRatio = GADMediaAspectRatioUnknown; - break; - case 1: - mediaOptions.mediaAspectRatio = GADMediaAspectRatioAny; - break; - case 2: - mediaOptions.mediaAspectRatio = GADMediaAspectRatioLandscape; - break; - case 3: - mediaOptions.mediaAspectRatio = GADMediaAspectRatioPortrait; - break; - case 4: - mediaOptions.mediaAspectRatio = GADMediaAspectRatioSquare; - break; - default: - NSLog(@"MediaAspectRatio should be an int in the range [0, 4]: %d", - _mediaAspectRatio.intValue); - break; + case 0: + mediaOptions.mediaAspectRatio = GADMediaAspectRatioUnknown; + break; + case 1: + mediaOptions.mediaAspectRatio = GADMediaAspectRatioAny; + break; + case 2: + mediaOptions.mediaAspectRatio = GADMediaAspectRatioLandscape; + break; + case 3: + mediaOptions.mediaAspectRatio = GADMediaAspectRatioPortrait; + break; + case 4: + mediaOptions.mediaAspectRatio = GADMediaAspectRatioSquare; + break; + default: + NSLog(@"MediaAspectRatio should be an int in the range [0, 4]: %d", + _mediaAspectRatio.intValue); + break; } [options addObject:mediaOptions]; } diff --git a/packages/google_mobile_ads/ios/Classes/FLTAppStateNotifier.m b/packages/google_mobile_ads/ios/Classes/FLTAppStateNotifier.m index 08a5adf36..d4ef51ad8 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAppStateNotifier.m +++ b/packages/google_mobile_ads/ios/Classes/FLTAppStateNotifier.m @@ -29,21 +29,24 @@ - (instancetype _Nonnull)initWithBinaryMessenger: FLTAppStateNotifier *__weak weakSelf = self; _observers = [[NSMutableArray alloc] init]; _eventChannel = [FlutterEventChannel - eventChannelWithName:@"plugins.flutter.io/google_mobile_ads/app_state_event" + eventChannelWithName: + @"plugins.flutter.io/google_mobile_ads/app_state_event" binaryMessenger:messenger]; _methodChannel = [FlutterMethodChannel - methodChannelWithName:@"plugins.flutter.io/google_mobile_ads/app_state_method" + methodChannelWithName: + @"plugins.flutter.io/google_mobile_ads/app_state_method" binaryMessenger:messenger]; [_eventChannel setStreamHandler:self]; - [_methodChannel - setMethodCallHandler:^(FlutterMethodCall *_Nonnull call, FlutterResult _Nonnull result) { - [weakSelf handleMethodCall:call result:result]; - }]; + [_methodChannel setMethodCallHandler:^(FlutterMethodCall *_Nonnull call, + FlutterResult _Nonnull result) { + [weakSelf handleMethodCall:call result:result]; + }]; } return self; } -- (void)handleMethodCall:(FlutterMethodCall *_Nonnull)call result:(FlutterResult _Nonnull)result { +- (void)handleMethodCall:(FlutterMethodCall *_Nonnull)call + result:(FlutterResult _Nonnull)result { if ([call.method isEqualToString:@"start"]) { [self addAppStateObservers]; result(nil); @@ -90,13 +93,13 @@ - (void)addAppStateObservers { }]; [_observers addObject:foregroundSceneObserver]; - id backgroundSceneObserver = - [NSNotificationCenter.defaultCenter addObserverForName:UISceneDidEnterBackgroundNotification - object:nil - queue:nil - usingBlock:^(NSNotification *_Nonnull note) { - [self handleDidEnterBackground]; - }]; + id backgroundSceneObserver = [NSNotificationCenter.defaultCenter + addObserverForName:UISceneDidEnterBackgroundNotification + object:nil + queue:nil + usingBlock:^(NSNotification *_Nonnull note) { + [self handleDidEnterBackground]; + }]; [_observers addObject:backgroundSceneObserver]; } } @@ -130,7 +133,8 @@ - (FlutterError *_Nullable)onCancelWithArguments:(id _Nullable)arguments { } - (FlutterError *_Nullable)onListenWithArguments:(id _Nullable)arguments - eventSink:(nonnull FlutterEventSink)events { + eventSink: + (nonnull FlutterEventSink)events { _events = events; return nil; } diff --git a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsCollection_Internal.h b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsCollection_Internal.h index f063e569d..5034d4672 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsCollection_Internal.h +++ b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsCollection_Internal.h @@ -12,15 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import #import "FLTAd_Internal.h" #import "FLTGoogleMobileAdsPlugin.h" +#import @protocol FLTAd; // Thread-safe wrapper of NSMutableDictionary. @interface FLTGoogleMobileAdsCollection : NSObject -- (void)setObject:(ObjectType _Nonnull)object forKey:(KeyType _Nonnull)key; +- (void)setObject:(ObjectType _Nonnull)object + forKey:(KeyType _Nonnull)key; - (void)removeObjectForKey:(KeyType _Nonnull)key; - (id _Nullable)objectForKey:(KeyType _Nonnull)key; - (NSArray *_Nonnull)allKeysForObject:(ObjectType _Nonnull)object; diff --git a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsCollection_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsCollection_Internal.m index c99ec97b8..6efb188e6 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsCollection_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsCollection_Internal.m @@ -23,7 +23,8 @@ - (instancetype _Nonnull)init { self = [super init]; if (self) { _dictionary = [[NSMutableDictionary alloc] init]; - _lockQueue = dispatch_queue_create("FLTGoogleMobileAdsCollection", DISPATCH_QUEUE_SERIAL); + _lockQueue = dispatch_queue_create("FLTGoogleMobileAdsCollection", + DISPATCH_QUEUE_SERIAL); } return self; } diff --git a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.h b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.h index 470654ffa..f01782088 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.h +++ b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.h @@ -21,7 +21,7 @@ #import "FLTMediationNetworkExtrasProvider.h" #import "FLTMobileAds_Internal.h" -#define FLTLogWarning(format, ...) \ +#define FLTLogWarning(format, ...) \ NSLog((@"GoogleMobileAdsPlugin " format), ##__VA_ARGS__) /** @@ -42,7 +42,8 @@ * @return a `GADNativeAdView` that is overlaid on top of the FlutterView. */ - (GADNativeAdView *_Nullable)createNativeAd:(GADNativeAd *_Nonnull)nativeAd - customOptions:(NSDictionary *_Nullable)customOptions; + customOptions: + (NSDictionary *_Nullable)customOptions; @end /** @@ -62,15 +63,19 @@ * a FLTGoogleMobileAdsPlugin in the registry. */ + (BOOL)registerMediationNetworkExtrasProvider: - (id _Nonnull)mediationNetworkExtrasProvider - registry:(id _Nonnull)registry + (id _Nonnull) + mediationNetworkExtrasProvider + registry: + (id _Nonnull) + registry __deprecated_msg("Use MediationExtras instead"); /* * Unregisters any FLTMediationNetworkExtrasProvider that was associated with * the FLTGoogleMobileAdsPlugin in registry. */ -+ (void)unregisterMediationNetworkExtrasProvider:(id _Nonnull)registry ++ (void)unregisterMediationNetworkExtrasProvider: + (id _Nonnull)registry __deprecated_msg("Use MediationExtras instead"); /** @@ -87,7 +92,8 @@ */ + (BOOL)registerNativeAdFactory:(id _Nonnull)registry factoryId:(NSString *_Nonnull)factoryId - nativeAdFactory:(id _Nonnull)nativeAdFactory; + nativeAdFactory: + (id _Nonnull)nativeAdFactory; /** * Unregisters a `FLTNativeAdFactory` used to create `GADNativeAdView`s from a @@ -99,7 +105,7 @@ * @return the previous `FLTNativeAdFactory` associated with this factoryId, or * null if there was none for this factoryId. */ -+ (id _Nullable)unregisterNativeAdFactory: - (id _Nonnull)registry - factoryId:(NSString *_Nonnull)factoryId; ++ (id _Nullable) + unregisterNativeAdFactory:(id _Nonnull)registry + factoryId:(NSString *_Nonnull)factoryId; @end diff --git a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m index b872d164c..d76165594 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m +++ b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m @@ -22,7 +22,8 @@ @interface FLTGoogleMobileAdsPlugin () @property(nonatomic, retain) FlutterMethodChannel *channel; -@property NSMutableDictionary> *nativeAdFactories; +@property NSMutableDictionary> + *nativeAdFactories; @end /// Initialization handler for GMASDK. Invokes result at most once. @@ -74,26 +75,29 @@ @implementation FLTGoogleMobileAdsPlugin { } + (void)registerWithRegistrar:(NSObject *)registrar { - FLTGoogleMobileAdsPlugin *instance = - [[FLTGoogleMobileAdsPlugin alloc] initWithBinaryMessenger:registrar.messenger]; + FLTGoogleMobileAdsPlugin *instance = [[FLTGoogleMobileAdsPlugin alloc] + initWithBinaryMessenger:registrar.messenger]; [registrar publish:instance]; - FLTGoogleMobileAdsReaderWriter *readerWriter = [[FLTGoogleMobileAdsReaderWriter alloc] init]; + FLTGoogleMobileAdsReaderWriter *readerWriter = + [[FLTGoogleMobileAdsReaderWriter alloc] init]; instance->_readerWriter = readerWriter; NSObject *codec = [FlutterStandardMethodCodec codecWithReaderWriter:readerWriter]; - FlutterMethodChannel *channel = - [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/google_mobile_ads" - binaryMessenger:[registrar messenger] - codec:codec]; + FlutterMethodChannel *channel = [FlutterMethodChannel + methodChannelWithName:@"plugins.flutter.io/google_mobile_ads" + binaryMessenger:[registrar messenger] + codec:codec]; [registrar addMethodCallDelegate:instance channel:channel]; FLTNewGoogleMobileAdsViewFactory *viewFactory = - [[FLTNewGoogleMobileAdsViewFactory alloc] initWithManager:instance->_manager]; - [registrar registerViewFactory:viewFactory - withId:@"plugins.flutter.io/google_mobile_ads/ad_widget"]; + [[FLTNewGoogleMobileAdsViewFactory alloc] + initWithManager:instance->_manager]; + [registrar + registerViewFactory:viewFactory + withId:@"plugins.flutter.io/google_mobile_ads/ad_widget"]; [registrar addApplicationDelegate:instance]; } @@ -108,25 +112,32 @@ - (BOOL)application:(UIApplication *)application return YES; } -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger { +- (instancetype)initWithBinaryMessenger: + (id)binaryMessenger { self = [self init]; if (self) { _nativeAdFactories = [NSMutableDictionary dictionary]; - _manager = [[FLTAdInstanceManager alloc] initWithBinaryMessenger:binaryMessenger]; - _appStateNotifier = [[FLTAppStateNotifier alloc] initWithBinaryMessenger:binaryMessenger]; - _userMessagingPlatformManager = - [[FLTUserMessagingPlatformManager alloc] initWithBinaryMessenger:binaryMessenger]; + _manager = + [[FLTAdInstanceManager alloc] initWithBinaryMessenger:binaryMessenger]; + _appStateNotifier = + [[FLTAppStateNotifier alloc] initWithBinaryMessenger:binaryMessenger]; + _userMessagingPlatformManager = [[FLTUserMessagingPlatformManager alloc] + initWithBinaryMessenger:binaryMessenger]; } return self; } + (BOOL)registerMediationNetworkExtrasProvider: - (id _Nonnull)mediationNetworkExtrasProvider - registry:(id _Nonnull)registry { - NSString *pluginClassName = NSStringFromClass([FLTGoogleMobileAdsPlugin class]); - FLTGoogleMobileAdsPlugin *adMobPlugin = - (FLTGoogleMobileAdsPlugin *)[registry valuePublishedByPlugin:pluginClassName]; + (id _Nonnull) + mediationNetworkExtrasProvider + registry: + (id _Nonnull) + registry { + NSString *pluginClassName = + NSStringFromClass([FLTGoogleMobileAdsPlugin class]); + FLTGoogleMobileAdsPlugin *adMobPlugin = (FLTGoogleMobileAdsPlugin *)[registry + valuePublishedByPlugin:pluginClassName]; if (!adMobPlugin) { NSLog(@"Could not find a %@ instance registering mediation extras " @"provider. The plugin may " @@ -136,15 +147,18 @@ + (BOOL)registerMediationNetworkExtrasProvider: } adMobPlugin->_mediationNetworkExtrasProvider = mediationNetworkExtrasProvider; - adMobPlugin->_readerWriter.mediationNetworkExtrasProvider = mediationNetworkExtrasProvider; + adMobPlugin->_readerWriter.mediationNetworkExtrasProvider = + mediationNetworkExtrasProvider; return YES; } -+ (void)unregisterMediationNetworkExtrasProvider:(id _Nonnull)registry { - NSString *pluginClassName = NSStringFromClass([FLTGoogleMobileAdsPlugin class]); - FLTGoogleMobileAdsPlugin *adMobPlugin = - (FLTGoogleMobileAdsPlugin *)[registry valuePublishedByPlugin:pluginClassName]; ++ (void)unregisterMediationNetworkExtrasProvider: + (id _Nonnull)registry { + NSString *pluginClassName = + NSStringFromClass([FLTGoogleMobileAdsPlugin class]); + FLTGoogleMobileAdsPlugin *adMobPlugin = (FLTGoogleMobileAdsPlugin *)[registry + valuePublishedByPlugin:pluginClassName]; if (!adMobPlugin) { NSLog(@"Could not find a %@ instance deregistering mediation extras " @"provider. The plugin may " @@ -160,18 +174,23 @@ + (void)unregisterMediationNetworkExtrasProvider:(id _Non + (BOOL)registerNativeAdFactory:(id)registry factoryId:(NSString *)factoryId nativeAdFactory:(id)nativeAdFactory { - NSString *pluginClassName = NSStringFromClass([FLTGoogleMobileAdsPlugin class]); - FLTGoogleMobileAdsPlugin *adMobPlugin = - (FLTGoogleMobileAdsPlugin *)[registry valuePublishedByPlugin:pluginClassName]; + NSString *pluginClassName = + NSStringFromClass([FLTGoogleMobileAdsPlugin class]); + FLTGoogleMobileAdsPlugin *adMobPlugin = (FLTGoogleMobileAdsPlugin *)[registry + valuePublishedByPlugin:pluginClassName]; if (!adMobPlugin) { - NSString *reason = [NSString stringWithFormat:@"Could not find a %@ instance. The plugin " - @"may have not been registered.", - pluginClassName]; - [NSException exceptionWithName:NSInvalidArgumentException reason:reason userInfo:nil]; + NSString *reason = + [NSString stringWithFormat:@"Could not find a %@ instance. The plugin " + @"may have not been registered.", + pluginClassName]; + [NSException exceptionWithName:NSInvalidArgumentException + reason:reason + userInfo:nil]; } if (adMobPlugin.nativeAdFactories[factoryId]) { - NSLog(@"A NativeAdFactory with the following factoryId already exists: %@", factoryId); + NSLog(@"A NativeAdFactory with the following factoryId already exists: %@", + factoryId); return NO; } @@ -179,36 +198,38 @@ + (BOOL)registerNativeAdFactory:(id)registry return YES; } -+ (id)unregisterNativeAdFactory:(id)registry ++ (id)unregisterNativeAdFactory: + (id)registry factoryId:(NSString *)factoryId { FLTGoogleMobileAdsPlugin *adMobPlugin = (FLTGoogleMobileAdsPlugin *)[registry - valuePublishedByPlugin:NSStringFromClass([FLTGoogleMobileAdsPlugin class])]; + valuePublishedByPlugin:NSStringFromClass( + [FLTGoogleMobileAdsPlugin class])]; id factory = adMobPlugin.nativeAdFactories[factoryId]; - if (factory) [adMobPlugin.nativeAdFactories removeObjectForKey:factoryId]; + if (factory) + [adMobPlugin.nativeAdFactories removeObjectForKey:factoryId]; return factory; } - (UIViewController *)rootController { - UIViewController *root = UIApplication.sharedApplication.delegate.window.rootViewController; + UIViewController *root = + UIApplication.sharedApplication.delegate.window.rootViewController; if ([FLTAdUtil isNull:root]) { -// UIApplication.sharedApplication.delegate.window is not guaranteed to be -// set. Use the keyWindow in this case. -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" + // UIApplication.sharedApplication.delegate.window is not guaranteed to be + // set. Use the keyWindow in this case. + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdeprecated-declarations" root = UIApplication.sharedApplication.keyWindow.rootViewController; -#pragma clang diagnostic pop + #pragma clang diagnostic pop } UIViewController *presentedViewController = root; - while (presentedViewController.presentedViewController && - ![presentedViewController.presentedViewController isBeingDismissed]) { + while (presentedViewController.presentedViewController && ![presentedViewController.presentedViewController isBeingDismissed]) { if ([presentedViewController isKindOfClass:[UITabBarController class]]) { - UITabBarController *tabBarController = (UITabBarController *)presentedViewController; + UITabBarController* tabBarController = (UITabBarController*)presentedViewController; presentedViewController = tabBarController.selectedViewController; } else if ([presentedViewController isKindOfClass:[UINavigationController class]]) { - UINavigationController *navigationController = - (UINavigationController *)presentedViewController; + UINavigationController* navigationController = (UINavigationController*)presentedViewController; presentedViewController = navigationController.visibleViewController; } else { presentedViewController = presentedViewController.presentedViewController; @@ -217,26 +238,26 @@ - (UIViewController *)rootController { return presentedViewController; } -- (UIViewController *)topViewControllerWithRootViewController: - (UIViewController *)rootViewController { +- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController { if ([rootViewController isKindOfClass:[UITabBarController class]]) { - UITabBarController *tabBarController = (UITabBarController *)rootViewController; + UITabBarController* tabBarController = (UITabBarController*)rootViewController; return [self topViewControllerWithRootViewController:tabBarController.selectedViewController]; } else if ([rootViewController isKindOfClass:[UINavigationController class]]) { - UINavigationController *navigationController = (UINavigationController *)rootViewController; - return - [self topViewControllerWithRootViewController:navigationController.visibleViewController]; + UINavigationController* navigationController = (UINavigationController*)rootViewController; + return [self topViewControllerWithRootViewController:navigationController.visibleViewController]; } else { return rootViewController; } } -- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { +- (void)handleMethodCall:(FlutterMethodCall *)call + result:(FlutterResult)result { NSLog(@"handleMethodCall %@", call.method); UIViewController *rootController = self.rootController; if ([call.method isEqualToString:@"MobileAds#initialize"]) { - FLTInitializationHandler *handler = [[FLTInitializationHandler alloc] initWithResult:result]; + FLTInitializationHandler *handler = + [[FLTInitializationHandler alloc] initWithResult:result]; [[GADMobileAds sharedInstance] startWithCompletionHandler:^(GADInitializationStatus *_Nonnull status) { [handler handleInitializationComplete:status]; @@ -245,27 +266,35 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result [_manager disposeAllAds]; result(nil); } else if ([call.method isEqualToString:@"MobileAds#setSameAppKeyEnabled"]) { - GADRequestConfiguration *requestConfig = GADMobileAds.sharedInstance.requestConfiguration; + GADRequestConfiguration *requestConfig = + GADMobileAds.sharedInstance.requestConfiguration; NSNumber *isEnabled = call.arguments[@"isEnabled"]; [requestConfig setPublisherFirstPartyIDEnabled:isEnabled.boolValue]; result(nil); } else if ([call.method isEqualToString:@"MobileAds#setAppMuted"]) { - GADMobileAds.sharedInstance.applicationMuted = [call.arguments[@"muted"] boolValue]; + GADMobileAds.sharedInstance.applicationMuted = + [call.arguments[@"muted"] boolValue]; result(nil); } else if ([call.method isEqualToString:@"MobileAds#setAppVolume"]) { - GADMobileAds.sharedInstance.applicationVolume = [call.arguments[@"volume"] floatValue]; + GADMobileAds.sharedInstance.applicationVolume = + [call.arguments[@"volume"] floatValue]; result(nil); - } else if ([call.method isEqualToString:@"MobileAds#disableSDKCrashReporting"]) { + } else if ([call.method + isEqualToString:@"MobileAds#disableSDKCrashReporting"]) { [GADMobileAds.sharedInstance disableSDKCrashReporting]; result(nil); - } else if ([call.method isEqualToString:@"MobileAds#disableMediationInitialization"]) { + } else if ([call.method + isEqualToString:@"MobileAds#disableMediationInitialization"]) { [GADMobileAds.sharedInstance disableMediationInitialization]; result(nil); } else if ([call.method isEqualToString:@"MobileAds#openDebugMenu"]) { NSString *adUnitId = call.arguments[@"adUnitId"]; GADDebugOptionsViewController *debugOptionsViewController = - [GADDebugOptionsViewController debugOptionsViewControllerWithAdUnitID:adUnitId]; - [rootController presentViewController:debugOptionsViewController animated:YES completion:nil]; + [GADDebugOptionsViewController + debugOptionsViewControllerWithAdUnitID:adUnitId]; + [rootController presentViewController:debugOptionsViewController + animated:YES + completion:nil]; result(nil); } else if ([call.method isEqualToString:@"MobileAds#openAdInspector"]) { [GADMobileAds.sharedInstance @@ -273,7 +302,8 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result completionHandler:^(NSError *error) { if (error) { result([FlutterError - errorWithCode:[[NSString alloc] initWithInt:error.code] + errorWithCode:[[NSString alloc] + initWithInt:error.code] message:error.localizedDescription details:error.domain]); } else { @@ -281,22 +311,28 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result } }]; } else if ([call.method isEqualToString:@"MobileAds#getVersionString"]) { - result(GADGetStringFromVersionNumber(GADMobileAds.sharedInstance.versionNumber)); - } else if ([call.method isEqualToString:@"MobileAds#getRequestConfiguration"]) { + result(GADGetStringFromVersionNumber( + GADMobileAds.sharedInstance.versionNumber)); + } else if ([call.method + isEqualToString:@"MobileAds#getRequestConfiguration"]) { result(GADMobileAds.sharedInstance.requestConfiguration); } else if ([call.method isEqualToString:@"MobileAds#registerWebView"]) { if (!_appDelegate) { NSLog(@"App delegate is null in MobileAds#registerWebView, skipping"); } else { NSNumber *webViewId = call.arguments[@"webViewId"]; - WKWebView *webView = [FLTAdUtil getWebView:webViewId flutterPluginRegistry:_appDelegate]; + WKWebView *webView = [FLTAdUtil getWebView:webViewId + flutterPluginRegistry:_appDelegate]; [GADMobileAds.sharedInstance registerWebView:webView]; } result(nil); - } else if ([call.method isEqualToString:@"MobileAds#updateRequestConfiguration"]) { + } else if ([call.method + isEqualToString:@"MobileAds#updateRequestConfiguration"]) { NSString *maxAdContentRating = call.arguments[@"maxAdContentRating"]; - NSNumber *tagForChildDirectedTreatment = call.arguments[@"tagForChildDirectedTreatment"]; - NSNumber *tagForUnderAgeOfConsent = call.arguments[@"tagForUnderAgeOfConsent"]; + NSNumber *tagForChildDirectedTreatment = + call.arguments[@"tagForChildDirectedTreatment"]; + NSNumber *tagForUnderAgeOfConsent = + call.arguments[@"tagForUnderAgeOfConsent"]; NSArray *testDeviceIds = call.arguments[@"testDeviceIds"]; if (maxAdContentRating != NULL && maxAdContentRating != (id)[NSNull null]) { @@ -314,63 +350,76 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result GADMaxAdContentRatingMatureAudience; } } - if (tagForChildDirectedTreatment != NULL && tagForChildDirectedTreatment != (id)[NSNull null]) { + if (tagForChildDirectedTreatment != NULL && + tagForChildDirectedTreatment != (id)[NSNull null]) { switch ([tagForChildDirectedTreatment intValue]) { - case 0: - GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment = @NO; - break; - case 1: - GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment = @YES; - break; + case 0: + GADMobileAds.sharedInstance.requestConfiguration + .tagForChildDirectedTreatment = @NO; + break; + case 1: + GADMobileAds.sharedInstance.requestConfiguration + .tagForChildDirectedTreatment = @YES; + break; } } - if (tagForUnderAgeOfConsent != NULL && tagForUnderAgeOfConsent != (id)[NSNull null]) { + if (tagForUnderAgeOfConsent != NULL && + tagForUnderAgeOfConsent != (id)[NSNull null]) { switch ([tagForUnderAgeOfConsent intValue]) { - case 0: - GADMobileAds.sharedInstance.requestConfiguration.tagForUnderAgeOfConsent = @NO; - break; - case 1: - GADMobileAds.sharedInstance.requestConfiguration.tagForUnderAgeOfConsent = @YES; - break; + case 0: + GADMobileAds.sharedInstance.requestConfiguration + .tagForUnderAgeOfConsent = @NO; + break; + case 1: + GADMobileAds.sharedInstance.requestConfiguration + .tagForUnderAgeOfConsent = @YES; + break; } } if (testDeviceIds != NULL && testDeviceIds != (id)[NSNull null]) { - GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = testDeviceIds; + GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = + testDeviceIds; } result(nil); } else if ([call.method isEqualToString:@"loadBannerAd"]) { - FLTBannerAd *ad = [[FLTBannerAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - size:call.arguments[@"size"] - request:call.arguments[@"request"] - rootViewController:rootController - adId:call.arguments[@"adId"]]; + FLTBannerAd *ad = + [[FLTBannerAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + size:call.arguments[@"size"] + request:call.arguments[@"request"] + rootViewController:rootController + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadAdManagerBannerAd"]) { - FLTGAMBannerAd *ad = [[FLTGAMBannerAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - sizes:call.arguments[@"sizes"] - request:call.arguments[@"request"] - rootViewController:rootController - adId:call.arguments[@"adId"]]; + FLTGAMBannerAd *ad = + [[FLTGAMBannerAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + sizes:call.arguments[@"sizes"] + request:call.arguments[@"request"] + rootViewController:rootController + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadFluidAd"]) { - FLTFluidGAMBannerAd *ad = - [[FLTFluidGAMBannerAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - request:call.arguments[@"request"] - rootViewController:rootController - adId:call.arguments[@"adId"]]; + FLTFluidGAMBannerAd *ad = [[FLTFluidGAMBannerAd alloc] + initWithAdUnitId:call.arguments[@"adUnitId"] + request:call.arguments[@"request"] + rootViewController:rootController + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadNativeAd"]) { NSString *factoryId = call.arguments[@"factoryId"]; id factory = _nativeAdFactories[factoryId]; - FLTNativeTemplateStyle *templateStyle = call.arguments[@"nativeTemplateStyle"]; + FLTNativeTemplateStyle *templateStyle = + call.arguments[@"nativeTemplateStyle"]; if ([FLTAdUtil isNull:factory] && [FLTAdUtil isNull:templateStyle]) { - NSString *message = [NSString stringWithFormat:@"Can't find NativeAdFactory with id: %@ " - @"and nativeTemplateStyle is null", - factoryId]; - result([FlutterError errorWithCode:@"NativeAdError" message:message details:nil]); + NSString *message = + [NSString stringWithFormat:@"Can't find NativeAdFactory with id: %@ " + @"and nativeTemplateStyle is null", + factoryId]; + result([FlutterError errorWithCode:@"NativeAdError" + message:message + details:nil]); return; } @@ -381,27 +430,29 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result request = call.arguments[@"adManagerRequest"]; } - FLTNativeAd *ad = [[FLTNativeAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - request:request - nativeAdFactory:(id)factory - customOptions:call.arguments[@"customOptions"] - rootViewController:rootController - adId:call.arguments[@"adId"] - nativeAdOptions:call.arguments[@"nativeAdOptions"] - nativeTemplateStyle:call.arguments[@"nativeTemplateStyle"]]; + FLTNativeAd *ad = [[FLTNativeAd alloc] + initWithAdUnitId:call.arguments[@"adUnitId"] + request:request + nativeAdFactory:(id)factory + customOptions:call.arguments[@"customOptions"] + rootViewController:rootController + adId:call.arguments[@"adId"] + nativeAdOptions:call.arguments[@"nativeAdOptions"] + nativeTemplateStyle:call.arguments[@"nativeTemplateStyle"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadInterstitialAd"]) { - FLTInterstitialAd *ad = [[FLTInterstitialAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - request:call.arguments[@"request"] - adId:call.arguments[@"adId"]]; + FLTInterstitialAd *ad = + [[FLTInterstitialAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + request:call.arguments[@"request"] + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadAdManagerInterstitialAd"]) { - FLTGAMInterstitialAd *ad = - [[FLTGAMInterstitialAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - request:call.arguments[@"request"] - adId:call.arguments[@"adId"]]; + FLTGAMInterstitialAd *ad = [[FLTGAMInterstitialAd alloc] + initWithAdUnitId:call.arguments[@"adUnitId"] + request:call.arguments[@"request"] + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadRewardedAd"]) { @@ -411,15 +462,17 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result } else if ([FLTAdUtil isNotNull:call.arguments[@"adManagerRequest"]]) { request = call.arguments[@"adManagerRequest"]; } else { - result([FlutterError errorWithCode:@"InvalidRequest" - message:@"A null or invalid ad request was provided." - details:nil]); + result([FlutterError + errorWithCode:@"InvalidRequest" + message:@"A null or invalid ad request was provided." + details:nil]); return; } - FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - request:request - adId:call.arguments[@"adId"]]; + FLTRewardedAd *ad = + [[FLTRewardedAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + request:request + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadRewardedInterstitialAd"]) { @@ -429,16 +482,17 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result } else if ([FLTAdUtil isNotNull:call.arguments[@"adManagerRequest"]]) { request = call.arguments[@"adManagerRequest"]; } else { - result([FlutterError errorWithCode:@"InvalidRequest" - message:@"A null or invalid ad request was provided." - details:nil]); + result([FlutterError + errorWithCode:@"InvalidRequest" + message:@"A null or invalid ad request was provided." + details:nil]); return; } - FLTRewardedInterstitialAd *ad = - [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - request:request - adId:call.arguments[@"adId"]]; + FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] + initWithAdUnitId:call.arguments[@"adUnitId"] + request:request + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadAppOpenAd"]) { @@ -448,27 +502,31 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result } else if ([FLTAdUtil isNotNull:call.arguments[@"adManagerRequest"]]) { request = call.arguments[@"adManagerRequest"]; } else { - result([FlutterError errorWithCode:@"InvalidRequest" - message:@"A null or invalid ad request was provided." - details:nil]); + result([FlutterError + errorWithCode:@"InvalidRequest" + message:@"A null or invalid ad request was provided." + details:nil]); return; } - FLTAppOpenAd *ad = [[FLTAppOpenAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - request:request - adId:call.arguments[@"adId"]]; + FLTAppOpenAd *ad = + [[FLTAppOpenAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + request:request + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"disposeAd"]) { [_manager dispose:call.arguments[@"adId"]]; result(nil); } else if ([call.method isEqualToString:@"showAdWithoutView"]) { - [_manager showAdWithID:call.arguments[@"adId"] rootViewController:rootController]; + [_manager showAdWithID:call.arguments[@"adId"] + rootViewController:rootController]; result(nil); - } else if ([call.method isEqualToString:@"AdSize#getAnchoredAdaptiveBannerAdSize"]) { - FLTAnchoredAdaptiveBannerSize *size = - [[FLTAnchoredAdaptiveBannerSize alloc] initWithFactory:[[FLTAdSizeFactory alloc] init] - orientation:call.arguments[@"orientation"] - width:call.arguments[@"width"]]; + } else if ([call.method + isEqualToString:@"AdSize#getAnchoredAdaptiveBannerAdSize"]) { + FLTAnchoredAdaptiveBannerSize *size = [[FLTAnchoredAdaptiveBannerSize alloc] + initWithFactory:[[FLTAdSizeFactory alloc] init] + orientation:call.arguments[@"orientation"] + width:call.arguments[@"width"]]; if (IsGADAdSizeValid(size.size)) { result(size.height); } else { @@ -486,14 +544,17 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result } else { result(FlutterMethodNotImplemented); } - } else if ([call.method isEqualToString:@"setServerSideVerificationOptions"]) { + } else if ([call.method + isEqualToString:@"setServerSideVerificationOptions"]) { id ad = [_manager adFor:call.arguments[@"adId"]]; - FLTServerSideVerificationOptions *options = call.arguments[@"serverSideVerificationOptions"]; + FLTServerSideVerificationOptions *options = + call.arguments[@"serverSideVerificationOptions"]; if ([ad isKindOfClass:[FLTRewardedAd class]]) { FLTRewardedAd *rewardedAd = (FLTRewardedAd *)ad; [rewardedAd setServerSideVerificationOptions:options]; } else if ([ad isKindOfClass:[FLTRewardedInterstitialAd class]]) { - FLTRewardedInterstitialAd *rewardedInterstitialAd = (FLTRewardedInterstitialAd *)ad; + FLTRewardedInterstitialAd *rewardedInterstitialAd = + (FLTRewardedInterstitialAd *)ad; [rewardedInterstitialAd setServerSideVerificationOptions:options]; } else { NSLog(@"Error - setServerSideVerificationOptions called on missing or " diff --git a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsReaderWriter_Internal.h b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsReaderWriter_Internal.h index bb4ce9544..5d8092afa 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsReaderWriter_Internal.h +++ b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsReaderWriter_Internal.h @@ -12,23 +12,27 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import #import "FLTAd_Internal.h" #import "FLTMediationNetworkExtrasProvider.h" +#import @class FLTAdSizeFactory; @interface FLTGoogleMobileAdsReaderWriter : FlutterStandardReaderWriter @property(readonly) FLTAdSizeFactory *_Nonnull adSizeFactory; -@property id _Nullable mediationNetworkExtrasProvider; +@property id< + FLTMediationNetworkExtrasProvider> _Nullable mediationNetworkExtrasProvider; -- (instancetype _Nonnull)initWithFactory:(FLTAdSizeFactory *_Nonnull)adSizeFactory; +- (instancetype _Nonnull)initWithFactory: + (FLTAdSizeFactory *_Nonnull)adSizeFactory; @end @interface FLTGoogleMobileAdsReader : FlutterStandardReader @property(readonly) FLTAdSizeFactory *_Nonnull adSizeFactory; -@property id _Nullable mediationNetworkExtrasProvider; +@property id< + FLTMediationNetworkExtrasProvider> _Nullable mediationNetworkExtrasProvider; -- (instancetype _Nonnull)initWithFactory:(FLTAdSizeFactory *_Nonnull)adSizeFactory +- (instancetype _Nonnull)initWithFactory: + (FLTAdSizeFactory *_Nonnull)adSizeFactory data:(NSData *_Nonnull)data; @end diff --git a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsReaderWriter_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsReaderWriter_Internal.m index 34a1a7435..24572e60f 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsReaderWriter_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsReaderWriter_Internal.m @@ -59,7 +59,8 @@ - (instancetype)init { return [self initWithFactory:[[FLTAdSizeFactory alloc] init]]; } -- (instancetype _Nonnull)initWithFactory:(FLTAdSizeFactory *_Nonnull)adSizeFactory { +- (instancetype _Nonnull)initWithFactory: + (FLTAdSizeFactory *_Nonnull)adSizeFactory { self = [super init]; if (self) { _adSizeFactory = adSizeFactory; @@ -69,12 +70,14 @@ - (instancetype _Nonnull)initWithFactory:(FLTAdSizeFactory *_Nonnull)adSizeFacto - (FlutterStandardReader *_Nonnull)readerWithData:(NSData *_Nonnull)data { FLTGoogleMobileAdsReader *reader = - [[FLTGoogleMobileAdsReader alloc] initWithFactory:_adSizeFactory data:data]; + [[FLTGoogleMobileAdsReader alloc] initWithFactory:_adSizeFactory + data:data]; reader.mediationNetworkExtrasProvider = _mediationNetworkExtrasProvider; return reader; } -- (FlutterStandardWriter *_Nonnull)writerWithData:(NSMutableData *_Nonnull)data { +- (FlutterStandardWriter *_Nonnull)writerWithData: + (NSMutableData *_Nonnull)data { return [[FLTGoogleMobileAdsWriter alloc] initWithData:data]; } @end @@ -82,7 +85,8 @@ - (FlutterStandardWriter *_Nonnull)writerWithData:(NSMutableData *_Nonnull)data @implementation FLTGoogleMobileAdsReader { NSString *_requestAgent; } -- (instancetype _Nonnull)initWithFactory:(FLTAdSizeFactory *_Nonnull)adSizeFactory +- (instancetype _Nonnull)initWithFactory: + (FLTAdSizeFactory *_Nonnull)adSizeFactory data:(NSData *_Nonnull)data { self = [super initWithData:data]; if (self) { @@ -95,228 +99,248 @@ - (instancetype _Nonnull)initWithFactory:(FLTAdSizeFactory *_Nonnull)adSizeFacto - (id _Nullable)readValueOfType:(UInt8)type { FLTAdMobField field = (FLTAdMobField)type; switch (field) { - case FLTAdMobFieldAdSize: - return [[FLTAdSize alloc] initWithWidth:[self readValueOfType:[self readByte]] - height:[self readValueOfType:[self readByte]]]; - case FLTAdMobFieldFluidAdSize: - return [[FLTFluidSize alloc] init]; - case FLTAdMobFieldAdRequest: { - FLTAdRequest *request = [[FLTAdRequest alloc] init]; + case FLTAdMobFieldAdSize: + return [[FLTAdSize alloc] + initWithWidth:[self readValueOfType:[self readByte]] + height:[self readValueOfType:[self readByte]]]; + case FLTAdMobFieldFluidAdSize: + return [[FLTFluidSize alloc] init]; + case FLTAdMobFieldAdRequest: { + FLTAdRequest *request = [[FLTAdRequest alloc] init]; - request.keywords = [self readValueOfType:[self readByte]]; - request.contentURL = [self readValueOfType:[self readByte]]; + request.keywords = [self readValueOfType:[self readByte]]; + request.contentURL = [self readValueOfType:[self readByte]]; - NSNumber *nonPersonalizedAds = [self readValueOfType:[self readByte]]; - request.nonPersonalizedAds = nonPersonalizedAds.boolValue; - request.neighboringContentURLs = [self readValueOfType:[self readByte]]; - request.mediationExtrasIdentifier = [self readValueOfType:[self readByte]]; - request.mediationNetworkExtrasProvider = _mediationNetworkExtrasProvider; - request.adMobExtras = [self readValueOfType:[self readByte]]; - request.requestAgent = _requestAgent; - request.mediationExtras = [self readValueOfType:[self readByte]]; - return request; - } - case FLTAdmobFieldMediationExtras: { - id flutterMediationExtras = - [[NSClassFromString([self readValueOfType:[self readByte]]) alloc] init]; - NSMutableDictionary *flutterExtras = [self readValueOfType:[self readByte]]; - flutterMediationExtras.extras = flutterExtras; - return flutterMediationExtras; - } - case FLTAdMobFieldRewardItem: { - return [[FLTRewardItem alloc] initWithAmount:[self readValueOfType:[self readByte]] - type:[self readValueOfType:[self readByte]]]; - } - case FLTAdmobFieldGadResponseInfo: { - NSString *responseIdentifier = [self readValueOfType:[self readByte]]; - NSString *adNetworkClassName = [self readValueOfType:[self readByte]]; - NSArray *adNetworkInfoArray = - [self readValueOfType:[self readByte]]; - FLTGADAdNetworkResponseInfo *loadedResponseInfo = [self readValueOfType:[self readByte]]; - NSDictionary *extrasDictionary = [self readValueOfType:[self readByte]]; - FLTGADResponseInfo *gadResponseInfo = [[FLTGADResponseInfo alloc] init]; - gadResponseInfo.adNetworkClassName = adNetworkClassName; - gadResponseInfo.responseIdentifier = responseIdentifier; - gadResponseInfo.adNetworkInfoArray = adNetworkInfoArray; - gadResponseInfo.loadedAdNetworkResponseInfo = loadedResponseInfo; - gadResponseInfo.extrasDictionary = extrasDictionary; - return gadResponseInfo; - } - case FLTAdmobFieldGADAdNetworkResponseInfo: { - NSString *adNetworkClassName = [self readValueOfType:[self readByte]]; - NSNumber *latency = [self readValueOfType:[self readByte]]; - NSString *dictionaryDescription = [self readValueOfType:[self readByte]]; - NSDictionary *adUnitMapping = [self readValueOfType:[self readByte]]; - NSError *error = [self readValueOfType:[self readByte]]; - NSString *adSourceName = [self readValueOfType:[self readByte]]; - NSString *adSourceID = [self readValueOfType:[self readByte]]; - NSString *adSourceInstanceName = [self readValueOfType:[self readByte]]; - NSString *adSourceInstanceID = [self readValueOfType:[self readByte]]; - FLTGADAdNetworkResponseInfo *adNetworkResponseInfo = - [[FLTGADAdNetworkResponseInfo alloc] init]; - adNetworkResponseInfo.adNetworkClassName = adNetworkClassName; - adNetworkResponseInfo.latency = latency; - adNetworkResponseInfo.dictionaryDescription = dictionaryDescription; - adNetworkResponseInfo.adUnitMapping = adUnitMapping; - adNetworkResponseInfo.error = error; - adNetworkResponseInfo.adSourceName = adSourceName; - adNetworkResponseInfo.adSourceID = adSourceID; - adNetworkResponseInfo.adSourceInstanceName = adSourceInstanceName; - adNetworkResponseInfo.adSourceInstanceID = adSourceInstanceID; + NSNumber *nonPersonalizedAds = [self readValueOfType:[self readByte]]; + request.nonPersonalizedAds = nonPersonalizedAds.boolValue; + request.neighboringContentURLs = [self readValueOfType:[self readByte]]; + request.mediationExtrasIdentifier = [self readValueOfType:[self readByte]]; + request.mediationNetworkExtrasProvider = _mediationNetworkExtrasProvider; + request.adMobExtras = [self readValueOfType:[self readByte]]; + request.requestAgent = _requestAgent; + request.mediationExtras = [self readValueOfType:[self readByte]]; + return request; + } + case FLTAdmobFieldMediationExtras: { + id flutterMediationExtras = + [[NSClassFromString([self readValueOfType:[self readByte]]) alloc] + init]; + NSMutableDictionary *flutterExtras = [self readValueOfType:[self readByte]]; + flutterMediationExtras.extras = flutterExtras; + return flutterMediationExtras; + } + case FLTAdMobFieldRewardItem: { + return [[FLTRewardItem alloc] + initWithAmount:[self readValueOfType:[self readByte]] + type:[self readValueOfType:[self readByte]]]; + } + case FLTAdmobFieldGadResponseInfo: { + NSString *responseIdentifier = [self readValueOfType:[self readByte]]; + NSString *adNetworkClassName = [self readValueOfType:[self readByte]]; + NSArray *adNetworkInfoArray = + [self readValueOfType:[self readByte]]; + FLTGADAdNetworkResponseInfo *loadedResponseInfo = + [self readValueOfType:[self readByte]]; + NSDictionary *extrasDictionary = + [self readValueOfType:[self readByte]]; + FLTGADResponseInfo *gadResponseInfo = [[FLTGADResponseInfo alloc] init]; + gadResponseInfo.adNetworkClassName = adNetworkClassName; + gadResponseInfo.responseIdentifier = responseIdentifier; + gadResponseInfo.adNetworkInfoArray = adNetworkInfoArray; + gadResponseInfo.loadedAdNetworkResponseInfo = loadedResponseInfo; + gadResponseInfo.extrasDictionary = extrasDictionary; + return gadResponseInfo; + } + case FLTAdmobFieldGADAdNetworkResponseInfo: { + NSString *adNetworkClassName = [self readValueOfType:[self readByte]]; + NSNumber *latency = [self readValueOfType:[self readByte]]; + NSString *dictionaryDescription = [self readValueOfType:[self readByte]]; + NSDictionary *adUnitMapping = + [self readValueOfType:[self readByte]]; + NSError *error = [self readValueOfType:[self readByte]]; + NSString *adSourceName = [self readValueOfType:[self readByte]]; + NSString *adSourceID = [self readValueOfType:[self readByte]]; + NSString *adSourceInstanceName = [self readValueOfType:[self readByte]]; + NSString *adSourceInstanceID = [self readValueOfType:[self readByte]]; + FLTGADAdNetworkResponseInfo *adNetworkResponseInfo = + [[FLTGADAdNetworkResponseInfo alloc] init]; + adNetworkResponseInfo.adNetworkClassName = adNetworkClassName; + adNetworkResponseInfo.latency = latency; + adNetworkResponseInfo.dictionaryDescription = dictionaryDescription; + adNetworkResponseInfo.adUnitMapping = adUnitMapping; + adNetworkResponseInfo.error = error; + adNetworkResponseInfo.adSourceName = adSourceName; + adNetworkResponseInfo.adSourceID = adSourceID; + adNetworkResponseInfo.adSourceInstanceName = adSourceInstanceName; + adNetworkResponseInfo.adSourceInstanceID = adSourceInstanceID; - return adNetworkResponseInfo; - } - case FLTAdMobFieldLoadError: { - NSNumber *code = [self readValueOfType:[self readByte]]; - NSString *domain = [self readValueOfType:[self readByte]]; - NSString *message = [self readValueOfType:[self readByte]]; - FLTGADResponseInfo *responseInfo = [self readValueOfType:[self readByte]]; - FLTLoadAdError *loadAdError = [[FLTLoadAdError alloc] init]; - loadAdError.code = code.longValue; - loadAdError.domain = domain; - loadAdError.message = message; - loadAdError.responseInfo = responseInfo; - return loadAdError; - } - case FLTAdmobFieldAdError: { - NSNumber *code = [self readValueOfType:[self readByte]]; - NSString *domain = [self readValueOfType:[self readByte]]; - NSString *message = [self readValueOfType:[self readByte]]; - return [NSError errorWithDomain:domain - code:code.longValue - userInfo:@{NSLocalizedDescriptionKey : message}]; - } - case FLTAdMobFieldAdManagerAdRequest: { - FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init]; - request.keywords = [self readValueOfType:[self readByte]]; - request.contentURL = [self readValueOfType:[self readByte]]; - request.customTargeting = [self readValueOfType:[self readByte]]; - request.customTargetingLists = [self readValueOfType:[self readByte]]; - NSNumber *nonPersonalizedAds = [self readValueOfType:[self readByte]]; - request.nonPersonalizedAds = nonPersonalizedAds.boolValue; - request.neighboringContentURLs = [self readValueOfType:[self readByte]]; - request.pubProvidedID = [self readValueOfType:[self readByte]]; - request.mediationExtrasIdentifier = [self readValueOfType:[self readByte]]; - request.mediationNetworkExtrasProvider = _mediationNetworkExtrasProvider; - request.adMobExtras = [self readValueOfType:[self readByte]]; - request.requestAgent = _requestAgent; - request.mediationExtras = [self readValueOfType:[self readByte]]; - return request; - } - case FLTAdMobFieldAdapterInitializationState: { - NSString *state = [self readValueOfType:[self readByte]]; - if (!state) { - return nil; - } else if ([@"notReady" isEqualToString:state]) { - return @(FLTAdapterInitializationStateNotReady); - } else if ([@"ready" isEqualToString:state]) { - return @(FLTAdapterInitializationStateReady); - } - NSLog(@"Failed to interpret AdapterInitializationState of: %@", state); + return adNetworkResponseInfo; + } + case FLTAdMobFieldLoadError: { + NSNumber *code = [self readValueOfType:[self readByte]]; + NSString *domain = [self readValueOfType:[self readByte]]; + NSString *message = [self readValueOfType:[self readByte]]; + FLTGADResponseInfo *responseInfo = [self readValueOfType:[self readByte]]; + FLTLoadAdError *loadAdError = [[FLTLoadAdError alloc] init]; + loadAdError.code = code.longValue; + loadAdError.domain = domain; + loadAdError.message = message; + loadAdError.responseInfo = responseInfo; + return loadAdError; + } + case FLTAdmobFieldAdError: { + NSNumber *code = [self readValueOfType:[self readByte]]; + NSString *domain = [self readValueOfType:[self readByte]]; + NSString *message = [self readValueOfType:[self readByte]]; + return [NSError errorWithDomain:domain + code:code.longValue + userInfo:@{NSLocalizedDescriptionKey : message}]; + } + case FLTAdMobFieldAdManagerAdRequest: { + FLTGAMAdRequest *request = [[FLTGAMAdRequest alloc] init]; + request.keywords = [self readValueOfType:[self readByte]]; + request.contentURL = [self readValueOfType:[self readByte]]; + request.customTargeting = [self readValueOfType:[self readByte]]; + request.customTargetingLists = [self readValueOfType:[self readByte]]; + NSNumber *nonPersonalizedAds = [self readValueOfType:[self readByte]]; + request.nonPersonalizedAds = nonPersonalizedAds.boolValue; + request.neighboringContentURLs = [self readValueOfType:[self readByte]]; + request.pubProvidedID = [self readValueOfType:[self readByte]]; + request.mediationExtrasIdentifier = [self readValueOfType:[self readByte]]; + request.mediationNetworkExtrasProvider = _mediationNetworkExtrasProvider; + request.adMobExtras = [self readValueOfType:[self readByte]]; + request.requestAgent = _requestAgent; + request.mediationExtras = [self readValueOfType:[self readByte]]; + return request; + } + case FLTAdMobFieldAdapterInitializationState: { + NSString *state = [self readValueOfType:[self readByte]]; + if (!state) { return nil; + } else if ([@"notReady" isEqualToString:state]) { + return @(FLTAdapterInitializationStateNotReady); + } else if ([@"ready" isEqualToString:state]) { + return @(FLTAdapterInitializationStateReady); } - case FLTAdMobFieldAdapterStatus: { - FLTAdapterStatus *status = [[FLTAdapterStatus alloc] init]; - status.state = [self readValueOfType:[self readByte]]; - status.statusDescription = [self readValueOfType:[self readByte]]; - status.latency = [self readValueOfType:[self readByte]]; - return status; - } - case FLTAdMobFieldInitializationStatus: { - FLTInitializationStatus *status = [[FLTInitializationStatus alloc] init]; - status.adapterStatuses = [self readValueOfType:[self readByte]]; - return status; - } - case FLTAdmobFieldServerSideVerificationOptions: { - FLTServerSideVerificationOptions *options = [[FLTServerSideVerificationOptions alloc] init]; - options.userIdentifier = [self readValueOfType:[self readByte]]; - options.customRewardString = [self readValueOfType:[self readByte]]; - return options; - } - case FLTAdmobFieldAnchoredAdaptiveBannerAdSize: { - NSString *orientation = [self readValueOfType:[self readByte]]; - NSNumber *width = [self readValueOfType:[self readByte]]; - return [[FLTAnchoredAdaptiveBannerSize alloc] initWithFactory:_adSizeFactory - orientation:orientation - width:width]; - } - case FLTAdmobFieldSmartBannerAdSize: - return - [[FLTSmartBannerSize alloc] initWithOrientation:[self readValueOfType:[self readByte]]]; - case FLTAdmobFieldNativeAdOptions: { - return [[FLTNativeAdOptions alloc] - initWithAdChoicesPlacement:[self readValueOfType:[self readByte]] - mediaAspectRatio:[self readValueOfType:[self readByte]] - videoOptions:[self readValueOfType:[self readByte]] - requestCustomMuteThisAd:[self readValueOfType:[self readByte]] - shouldRequestMultipleImages:[self readValueOfType:[self readByte]] - shouldReturnUrlsForImageAssets:[self readValueOfType:[self readByte]]]; - } - case FLTAdmobFieldVideoOptions: { - return [[FLTVideoOptions alloc] - initWithClickToExpandRequested:[self readValueOfType:[self readByte]] - customControlsRequested:[self readValueOfType:[self readByte]] - startMuted:[self readValueOfType:[self readByte]]]; - } - case FLTAdmobRequestConfigurationParams: { - GADMobileAds.sharedInstance.requestConfiguration.maxAdContentRating = - [self readValueOfType:[self readByte]]; - GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment = - [self readValueOfType:[self readByte]]; - GADMobileAds.sharedInstance.requestConfiguration.tagForUnderAgeOfConsent = - [self readValueOfType:[self readByte]]; - GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = - [self readValueOfType:[self readByte]]; - return GADMobileAds.sharedInstance.requestConfiguration; - } - case FLTAdmobFieldInlineAdaptiveAdSize: { - return [[FLTInlineAdaptiveBannerSize alloc] - initWithFactory:_adSizeFactory - width:[self readValueOfType:[self readByte]] - maxHeight:[self readValueOfType:[self readByte]] - orientation:[self readValueOfType:[self readByte]]]; - } - case FLTAdmobFieldNativeTemplateStyle: { - FLTNativeTemplateType *templateType = [self readValueOfType:[self readByte]]; - FLTNativeTemplateColor *mainBackgroundColor = [self readValueOfType:[self readByte]]; - FLTNativeTemplateTextStyle *callToActionStyle = [self readValueOfType:[self readByte]]; - FLTNativeTemplateTextStyle *primaryTextStyle = [self readValueOfType:[self readByte]]; - FLTNativeTemplateTextStyle *secondaryTextStyle = [self readValueOfType:[self readByte]]; - FLTNativeTemplateTextStyle *tertiaryTextStyle = [self readValueOfType:[self readByte]]; - NSNumber *cornerRadius = [self readValueOfType:[self readByte]]; - return [[FLTNativeTemplateStyle alloc] initWithTemplateType:templateType - mainBackgroundColor:mainBackgroundColor - callToActionStyle:callToActionStyle - primaryTextStyle:primaryTextStyle - secondaryTextStyle:secondaryTextStyle - tertiaryTextStyle:tertiaryTextStyle - cornerRadius:cornerRadius]; - } - case FLTAdmobFieldNativeTemplateTextStyle: { - FLTNativeTemplateColor *textColor = [self readValueOfType:[self readByte]]; - FLTNativeTemplateColor *backgroundColor = [self readValueOfType:[self readByte]]; - FLTNativeTemplateFontStyleWrapper *fontStyle = [self readValueOfType:[self readByte]]; - NSNumber *size = [self readValueOfType:[self readByte]]; - return [[FLTNativeTemplateTextStyle alloc] initWithTextColor:textColor - backgroundColor:backgroundColor - fontStyle:fontStyle - size:size]; - } - case FLTAdmobFieldNativeTemplateFontStyle: { - NSNumber *fontStyleIndex = [self readValueOfType:[self readByte]]; - return [[FLTNativeTemplateFontStyleWrapper alloc] initWithInt:fontStyleIndex.intValue]; - } - case FLTAdmobFieldNativeTemplateType: { - NSNumber *templateIndex = [self readValueOfType:[self readByte]]; - return [[FLTNativeTemplateType alloc] initWithInt:templateIndex.intValue]; - } - case FLTAdmobFieldNativeTemplateColor: { - NSNumber *alpha = [self readValueOfType:[self readByte]]; - NSNumber *red = [self readValueOfType:[self readByte]]; - NSNumber *green = [self readValueOfType:[self readByte]]; - NSNumber *blue = [self readValueOfType:[self readByte]]; - return [[FLTNativeTemplateColor alloc] initWithAlpha:alpha red:red green:green blue:blue]; - } + NSLog(@"Failed to interpret AdapterInitializationState of: %@", state); + return nil; + } + case FLTAdMobFieldAdapterStatus: { + FLTAdapterStatus *status = [[FLTAdapterStatus alloc] init]; + status.state = [self readValueOfType:[self readByte]]; + status.statusDescription = [self readValueOfType:[self readByte]]; + status.latency = [self readValueOfType:[self readByte]]; + return status; + } + case FLTAdMobFieldInitializationStatus: { + FLTInitializationStatus *status = [[FLTInitializationStatus alloc] init]; + status.adapterStatuses = [self readValueOfType:[self readByte]]; + return status; + } + case FLTAdmobFieldServerSideVerificationOptions: { + FLTServerSideVerificationOptions *options = + [[FLTServerSideVerificationOptions alloc] init]; + options.userIdentifier = [self readValueOfType:[self readByte]]; + options.customRewardString = [self readValueOfType:[self readByte]]; + return options; + } + case FLTAdmobFieldAnchoredAdaptiveBannerAdSize: { + NSString *orientation = [self readValueOfType:[self readByte]]; + NSNumber *width = [self readValueOfType:[self readByte]]; + return [[FLTAnchoredAdaptiveBannerSize alloc] initWithFactory:_adSizeFactory + orientation:orientation + width:width]; + } + case FLTAdmobFieldSmartBannerAdSize: + return [[FLTSmartBannerSize alloc] + initWithOrientation:[self readValueOfType:[self readByte]]]; + case FLTAdmobFieldNativeAdOptions: { + return [[FLTNativeAdOptions alloc] + initWithAdChoicesPlacement:[self readValueOfType:[self readByte]] + mediaAspectRatio:[self readValueOfType:[self readByte]] + videoOptions:[self readValueOfType:[self readByte]] + requestCustomMuteThisAd:[self readValueOfType:[self readByte]] + shouldRequestMultipleImages:[self readValueOfType:[self readByte]] + shouldReturnUrlsForImageAssets:[self readValueOfType:[self readByte]]]; + } + case FLTAdmobFieldVideoOptions: { + return [[FLTVideoOptions alloc] + initWithClickToExpandRequested:[self readValueOfType:[self readByte]] + customControlsRequested:[self readValueOfType:[self readByte]] + startMuted:[self readValueOfType:[self readByte]]]; + } + case FLTAdmobRequestConfigurationParams: { + GADMobileAds.sharedInstance.requestConfiguration.maxAdContentRating = + [self readValueOfType:[self readByte]]; + GADMobileAds.sharedInstance.requestConfiguration + .tagForChildDirectedTreatment = [self readValueOfType:[self readByte]]; + GADMobileAds.sharedInstance.requestConfiguration.tagForUnderAgeOfConsent = + [self readValueOfType:[self readByte]]; + GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = + [self readValueOfType:[self readByte]]; + return GADMobileAds.sharedInstance.requestConfiguration; + } + case FLTAdmobFieldInlineAdaptiveAdSize: { + return [[FLTInlineAdaptiveBannerSize alloc] + initWithFactory:_adSizeFactory + width:[self readValueOfType:[self readByte]] + maxHeight:[self readValueOfType:[self readByte]] + orientation:[self readValueOfType:[self readByte]]]; + } + case FLTAdmobFieldNativeTemplateStyle: { + FLTNativeTemplateType *templateType = + [self readValueOfType:[self readByte]]; + FLTNativeTemplateColor *mainBackgroundColor = + [self readValueOfType:[self readByte]]; + FLTNativeTemplateTextStyle *callToActionStyle = + [self readValueOfType:[self readByte]]; + FLTNativeTemplateTextStyle *primaryTextStyle = + [self readValueOfType:[self readByte]]; + FLTNativeTemplateTextStyle *secondaryTextStyle = + [self readValueOfType:[self readByte]]; + FLTNativeTemplateTextStyle *tertiaryTextStyle = + [self readValueOfType:[self readByte]]; + NSNumber *cornerRadius = [self readValueOfType:[self readByte]]; + return + [[FLTNativeTemplateStyle alloc] initWithTemplateType:templateType + mainBackgroundColor:mainBackgroundColor + callToActionStyle:callToActionStyle + primaryTextStyle:primaryTextStyle + secondaryTextStyle:secondaryTextStyle + tertiaryTextStyle:tertiaryTextStyle + cornerRadius:cornerRadius]; + } + case FLTAdmobFieldNativeTemplateTextStyle: { + FLTNativeTemplateColor *textColor = [self readValueOfType:[self readByte]]; + FLTNativeTemplateColor *backgroundColor = + [self readValueOfType:[self readByte]]; + FLTNativeTemplateFontStyleWrapper *fontStyle = + [self readValueOfType:[self readByte]]; + NSNumber *size = [self readValueOfType:[self readByte]]; + return [[FLTNativeTemplateTextStyle alloc] initWithTextColor:textColor + backgroundColor:backgroundColor + fontStyle:fontStyle + size:size]; + } + case FLTAdmobFieldNativeTemplateFontStyle: { + NSNumber *fontStyleIndex = [self readValueOfType:[self readByte]]; + return [[FLTNativeTemplateFontStyleWrapper alloc] + initWithInt:fontStyleIndex.intValue]; + } + case FLTAdmobFieldNativeTemplateType: { + NSNumber *templateIndex = [self readValueOfType:[self readByte]]; + return [[FLTNativeTemplateType alloc] initWithInt:templateIndex.intValue]; + } + case FLTAdmobFieldNativeTemplateColor: { + NSNumber *alpha = [self readValueOfType:[self readByte]]; + NSNumber *red = [self readValueOfType:[self readByte]]; + NSNumber *green = [self readValueOfType:[self readByte]]; + NSNumber *blue = [self readValueOfType:[self readByte]]; + return [[FLTNativeTemplateColor alloc] initWithAlpha:alpha + red:red + green:green + blue:blue]; + } } return [super readValueOfType:type]; } @@ -332,7 +356,8 @@ - (void)writeAdSize:(FLTAdSize *_Nonnull)value { [self writeValue:size.orientation]; } else if ([value isKindOfClass:[FLTAnchoredAdaptiveBannerSize class]]) { [self writeByte:FLTAdmobFieldAnchoredAdaptiveBannerAdSize]; - FLTAnchoredAdaptiveBannerSize *size = (FLTAnchoredAdaptiveBannerSize *)value; + FLTAnchoredAdaptiveBannerSize *size = + (FLTAnchoredAdaptiveBannerSize *)value; [self writeValue:size.orientation]; [self writeValue:size.width]; } else if ([value isKindOfClass:[FLTSmartBannerSize class]]) { @@ -423,12 +448,15 @@ - (void)writeValue:(id)value { [self writeByte:FLTAdMobFieldAdapterInitializationState]; if (!status.state) { [self writeValue:[NSNull null]]; - } else if (status.state.unsignedLongValue == FLTAdapterInitializationStateNotReady) { + } else if (status.state.unsignedLongValue == + FLTAdapterInitializationStateNotReady) { [self writeValue:@"notReady"]; - } else if (status.state.unsignedLongValue == FLTAdapterInitializationStateReady) { + } else if (status.state.unsignedLongValue == + FLTAdapterInitializationStateReady) { [self writeValue:@"ready"]; } else { - NSLog(@"Failed to interpret AdapterInitializationState of: %@", status.state); + NSLog(@"Failed to interpret AdapterInitializationState of: %@", + status.state); [self writeValue:[NSNull null]]; } [self writeValue:status.statusDescription]; diff --git a/packages/google_mobile_ads/ios/Classes/FLTMediationNetworkExtrasProvider.h b/packages/google_mobile_ads/ios/Classes/FLTMediationNetworkExtrasProvider.h index d91e01ee2..3f2c9281e 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTMediationNetworkExtrasProvider.h +++ b/packages/google_mobile_ads/ios/Classes/FLTMediationNetworkExtrasProvider.h @@ -35,8 +35,8 @@ __attribute__((deprecated)) * which extras to include for an ad request, beyond just the ad unit. * @return an array of GADAdNetworkExtras to include in the ad request. */ -- (NSArray> *_Nullable)getMediationExtras:(NSString *_Nonnull)adUnitId - mediationExtrasIdentifier: - (NSString *_Nullable)mediationExtrasIdentifier; +- (NSArray> *_Nullable) + getMediationExtras:(NSString *_Nonnull)adUnitId + mediationExtrasIdentifier:(NSString *_Nullable)mediationExtrasIdentifier; @end diff --git a/packages/google_mobile_ads/ios/Classes/FLTMobileAds_Internal.h b/packages/google_mobile_ads/ios/Classes/FLTMobileAds_Internal.h index 5d46def90..06414f4d3 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTMobileAds_Internal.h +++ b/packages/google_mobile_ads/ios/Classes/FLTMobileAds_Internal.h @@ -51,6 +51,7 @@ typedef NS_ENUM(NSUInteger, FLTAdapterInitializationState) { @interface FLTServerSideVerificationOptions : NSObject @property(nonatomic, copy, nullable) NSString *userIdentifier; @property(nonatomic, copy, nullable) NSString *customRewardString; -- (GADServerSideVerificationOptions *_Nonnull)asGADServerSideVerificationOptions; +- (GADServerSideVerificationOptions *_Nonnull) + asGADServerSideVerificationOptions; @end NS_ASSUME_NONNULL_END diff --git a/packages/google_mobile_ads/ios/Classes/FLTMobileAds_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTMobileAds_Internal.m index 9dd6d66be..cb3a3fba2 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTMobileAds_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTMobileAds_Internal.m @@ -19,12 +19,12 @@ - (instancetype)initWithStatus:(GADAdapterStatus *)status { self = [self init]; if (self) { switch (status.state) { - case GADAdapterInitializationStateNotReady: - _state = @(FLTAdapterInitializationStateNotReady); - break; - case GADAdapterInitializationStateReady: - _state = @(FLTAdapterInitializationStateReady); - break; + case GADAdapterInitializationStateNotReady: + _state = @(FLTAdapterInitializationStateNotReady); + break; + case GADAdapterInitializationStateReady: + _state = @(FLTAdapterInitializationStateReady); + break; } _statusDescription = status.description; _latency = @(status.latency); @@ -39,8 +39,8 @@ - (instancetype)initWithStatus:(GADInitializationStatus *)status { if (self) { NSMutableDictionary *newDictionary = [NSMutableDictionary dictionary]; for (NSString *name in status.adapterStatusesByClassName.allKeys) { - FLTAdapterStatus *adapterStatus = - [[FLTAdapterStatus alloc] initWithStatus:status.adapterStatusesByClassName[name]]; + FLTAdapterStatus *adapterStatus = [[FLTAdapterStatus alloc] + initWithStatus:status.adapterStatusesByClassName[name]]; [newDictionary setValue:adapterStatus forKey:name]; } _adapterStatuses = newDictionary; @@ -50,8 +50,10 @@ - (instancetype)initWithStatus:(GADInitializationStatus *)status { @end @implementation FLTServerSideVerificationOptions -- (GADServerSideVerificationOptions *_Nonnull)asGADServerSideVerificationOptions { - GADServerSideVerificationOptions *options = [[GADServerSideVerificationOptions alloc] init]; +- (GADServerSideVerificationOptions *_Nonnull) + asGADServerSideVerificationOptions { + GADServerSideVerificationOptions *options = + [[GADServerSideVerificationOptions alloc] init]; options.userIdentifier = _userIdentifier; options.customRewardString = _customRewardString; return options; diff --git a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateFontStyle.m b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateFontStyle.m index f61fa6c2d..1d1fdbed1 100644 --- a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateFontStyle.m +++ b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateFontStyle.m @@ -28,17 +28,17 @@ - (instancetype _Nonnull)initWithInt:(int)intValue { - (FLTNativeTemplateFontStyle)fontStyle { switch (_intValue) { - case 0: - return FLTNativeTemplateFontNormal; - case 1: - return FLTNativeTemplateFontBold; - case 2: - return FLTNativeTemplateFontItalic; - case 3: - return FLTNativeTemplateFontMonospace; - default: - NSLog(@"Unknown FLTNativeTemplateFontStyle value: %d", _intValue); - return FLTNativeTemplateFontNormal; + case 0: + return FLTNativeTemplateFontNormal; + case 1: + return FLTNativeTemplateFontBold; + case 2: + return FLTNativeTemplateFontItalic; + case 3: + return FLTNativeTemplateFontMonospace; + default: + NSLog(@"Unknown FLTNativeTemplateFontStyle value: %d", _intValue); + return FLTNativeTemplateFontNormal; } } diff --git a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateStyle.h b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateStyle.h index 627485d35..58ecc30d6 100644 --- a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateStyle.h +++ b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateStyle.h @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import -#import -#import #import "FLTNativeTemplateColor.h" #import "FLTNativeTemplateTextStyle.h" #import "FLTNativeTemplateType.h" #import "GADTTemplateView.h" +#import +#import +#import /** * Wraps a GADTTemplateView for being displayed as a platform view. @@ -35,10 +35,13 @@ - (instancetype _Nonnull) initWithTemplateType:(FLTNativeTemplateType *_Nonnull)templateType mainBackgroundColor:(FLTNativeTemplateColor *_Nullable)mainBackgroundColor - callToActionStyle:(FLTNativeTemplateTextStyle *_Nullable)callToActionStyle + callToActionStyle: + (FLTNativeTemplateTextStyle *_Nullable)callToActionStyle primaryTextStyle:(FLTNativeTemplateTextStyle *_Nullable)primaryTextStyle - secondaryTextStyle:(FLTNativeTemplateTextStyle *_Nullable)secondaryTextStyle - tertiaryTextStyle:(FLTNativeTemplateTextStyle *_Nullable)tertiaryTextStyle + secondaryTextStyle: + (FLTNativeTemplateTextStyle *_Nullable)secondaryTextStyle + tertiaryTextStyle: + (FLTNativeTemplateTextStyle *_Nullable)tertiaryTextStyle cornerRadius:(NSNumber *_Nullable)cornerRadius; @property(readonly) FLTNativeTemplateType *_Nonnull templateType; @property(readonly) FLTNativeTemplateColor *_Nullable mainBackgroundColor; @@ -49,6 +52,7 @@ @property(readonly) NSNumber *_Nullable cornerRadius; /** The actual view to be displayed. */ -- (FLTNativeTemplateViewWrapper *_Nonnull)getDisplayedView:(GADNativeAd *_Nonnull)gadNativeAd; +- (FLTNativeTemplateViewWrapper *_Nonnull)getDisplayedView: + (GADNativeAd *_Nonnull)gadNativeAd; @end diff --git a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateStyle.m b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateStyle.m index 49de53e18..1de7bb509 100644 --- a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateStyle.m +++ b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateStyle.m @@ -22,10 +22,13 @@ @implementation FLTNativeTemplateStyle - (instancetype _Nonnull) initWithTemplateType:(FLTNativeTemplateType *_Nonnull)templateType mainBackgroundColor:(FLTNativeTemplateColor *_Nullable)mainBackgroundColor - callToActionStyle:(FLTNativeTemplateTextStyle *_Nullable)callToActionStyle + callToActionStyle: + (FLTNativeTemplateTextStyle *_Nullable)callToActionStyle primaryTextStyle:(FLTNativeTemplateTextStyle *_Nullable)primaryTextStyle - secondaryTextStyle:(FLTNativeTemplateTextStyle *_Nullable)secondaryTextStyle - tertiaryTextStyle:(FLTNativeTemplateTextStyle *_Nullable)tertiaryTextStyle + secondaryTextStyle: + (FLTNativeTemplateTextStyle *_Nullable)secondaryTextStyle + tertiaryTextStyle: + (FLTNativeTemplateTextStyle *_Nullable)tertiaryTextStyle cornerRadius:(NSNumber *_Nullable)cornerRadius { self = [super init]; if (self) { @@ -40,13 +43,15 @@ @implementation FLTNativeTemplateStyle return self; } -- (FLTNativeTemplateViewWrapper *_Nonnull)getDisplayedView:(GADNativeAd *_Nonnull)gadNativeAd { +- (FLTNativeTemplateViewWrapper *_Nonnull)getDisplayedView: + (GADNativeAd *_Nonnull)gadNativeAd { GADTTemplateView *templateView = _templateType.templateView; templateView.nativeAd = gadNativeAd; NSMutableDictionary *styles = [[NSMutableDictionary alloc] init]; if ([FLTAdUtil isNotNull:_mainBackgroundColor]) { - styles[GADTNativeTemplateStyleKeyMainBackgroundColor] = _mainBackgroundColor.uiColor; + styles[GADTNativeTemplateStyleKeyMainBackgroundColor] = + _mainBackgroundColor.uiColor; } if ([FLTAdUtil isNotNull:_cornerRadius]) { styles[GADTNativeTemplateStyleKeyCornerRadius] = _cornerRadius; @@ -57,7 +62,8 @@ - (FLTNativeTemplateViewWrapper *_Nonnull)getDisplayedView:(GADNativeAd *_Nonnul _callToActionStyle.backgroundColor.uiColor; } if ([FLTAdUtil isNotNull:_callToActionStyle.uiFont]) { - styles[GADTNativeTemplateStyleKeyCallToActionFont] = _callToActionStyle.uiFont; + styles[GADTNativeTemplateStyleKeyCallToActionFont] = + _callToActionStyle.uiFont; } if ([FLTAdUtil isNotNull:_callToActionStyle.textColor]) { styles[GADTNativeTemplateStyleKeyCallToActionFontColor] = @@ -73,7 +79,8 @@ - (FLTNativeTemplateViewWrapper *_Nonnull)getDisplayedView:(GADNativeAd *_Nonnul styles[GADTNativeTemplateStyleKeyPrimaryFont] = _primaryTextStyle.uiFont; } if ([FLTAdUtil isNotNull:_primaryTextStyle.textColor]) { - styles[GADTNativeTemplateStyleKeyPrimaryFontColor] = _primaryTextStyle.textColor.uiColor; + styles[GADTNativeTemplateStyleKeyPrimaryFontColor] = + _primaryTextStyle.textColor.uiColor; } } if ([FLTAdUtil isNotNull:_secondaryTextStyle]) { @@ -82,10 +89,12 @@ - (FLTNativeTemplateViewWrapper *_Nonnull)getDisplayedView:(GADNativeAd *_Nonnul _secondaryTextStyle.backgroundColor.uiColor; } if ([FLTAdUtil isNotNull:_secondaryTextStyle.uiFont]) { - styles[GADTNativeTemplateStyleKeySecondaryFont] = _secondaryTextStyle.uiFont; + styles[GADTNativeTemplateStyleKeySecondaryFont] = + _secondaryTextStyle.uiFont; } if ([FLTAdUtil isNotNull:_secondaryTextStyle.textColor]) { - styles[GADTNativeTemplateStyleKeySecondaryFontColor] = _secondaryTextStyle.textColor.uiColor; + styles[GADTNativeTemplateStyleKeySecondaryFontColor] = + _secondaryTextStyle.textColor.uiColor; } } if ([FLTAdUtil isNotNull:_tertiaryTextStyle]) { @@ -94,10 +103,12 @@ - (FLTNativeTemplateViewWrapper *_Nonnull)getDisplayedView:(GADNativeAd *_Nonnul _tertiaryTextStyle.backgroundColor.uiColor; } if ([FLTAdUtil isNotNull:_tertiaryTextStyle.uiFont]) { - styles[GADTNativeTemplateStyleKeyTertiaryFont] = _tertiaryTextStyle.uiFont; + styles[GADTNativeTemplateStyleKeyTertiaryFont] = + _tertiaryTextStyle.uiFont; } if ([FLTAdUtil isNotNull:_tertiaryTextStyle.textColor]) { - styles[GADTNativeTemplateStyleKeyTertiaryFontColor] = _tertiaryTextStyle.textColor.uiColor; + styles[GADTNativeTemplateStyleKeyTertiaryFontColor] = + _tertiaryTextStyle.textColor.uiColor; } } templateView.styles = styles; @@ -120,21 +131,24 @@ - (void)layoutSubviews { // aligns the template view if (_templateView.superview) { [_templateView.superview - addConstraint:[NSLayoutConstraint constraintWithItem:_templateView.superview - attribute:NSLayoutAttributeTop - relatedBy:NSLayoutRelationEqual - toItem:_templateView - attribute:NSLayoutAttributeTop - multiplier:1 - constant:0]]; + addConstraint:[NSLayoutConstraint + constraintWithItem:_templateView.superview + attribute:NSLayoutAttributeTop + relatedBy:NSLayoutRelationEqual + toItem:_templateView + attribute:NSLayoutAttributeTop + multiplier:1 + constant:0]]; [_templateView.superview - addConstraint:[NSLayoutConstraint constraintWithItem:_templateView.superview - attribute:NSLayoutAttributeBottom - relatedBy:NSLayoutRelationGreaterThanOrEqual - toItem:_templateView - attribute:NSLayoutAttributeBottom - multiplier:1 - constant:0]]; + addConstraint: + [NSLayoutConstraint + constraintWithItem:_templateView.superview + attribute:NSLayoutAttributeBottom + relatedBy:NSLayoutRelationGreaterThanOrEqual + toItem:_templateView + attribute:NSLayoutAttributeBottom + multiplier:1 + constant:0]]; } [_templateView addHorizontalConstraintsToSuperviewWidth]; } diff --git a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateTextStyle.h b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateTextStyle.h index 921e14140..d4068a786 100644 --- a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateTextStyle.h +++ b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateTextStyle.h @@ -20,10 +20,11 @@ */ @interface FLTNativeTemplateTextStyle : NSObject -- (instancetype _Nonnull)initWithTextColor:(FLTNativeTemplateColor *_Nullable)textColor - backgroundColor:(FLTNativeTemplateColor *_Nullable)backgroundColor - fontStyle:(FLTNativeTemplateFontStyleWrapper *_Nullable)fontStyle - size:(NSNumber *_Nullable)size; +- (instancetype _Nonnull) + initWithTextColor:(FLTNativeTemplateColor *_Nullable)textColor + backgroundColor:(FLTNativeTemplateColor *_Nullable)backgroundColor + fontStyle:(FLTNativeTemplateFontStyleWrapper *_Nullable)fontStyle + size:(NSNumber *_Nullable)size; @property(readonly) FLTNativeTemplateColor *_Nullable textColor; @property(readonly) FLTNativeTemplateColor *_Nullable backgroundColor; diff --git a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateTextStyle.m b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateTextStyle.m index ec8c97a0c..82716ba18 100644 --- a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateTextStyle.m +++ b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateTextStyle.m @@ -17,10 +17,11 @@ @implementation FLTNativeTemplateTextStyle -- (instancetype _Nonnull)initWithTextColor:(FLTNativeTemplateColor *_Nullable)textColor - backgroundColor:(FLTNativeTemplateColor *_Nullable)backgroundColor - fontStyle:(FLTNativeTemplateFontStyleWrapper *_Nullable)fontStyle - size:(NSNumber *_Nullable)size { +- (instancetype _Nonnull) + initWithTextColor:(FLTNativeTemplateColor *_Nullable)textColor + backgroundColor:(FLTNativeTemplateColor *_Nullable)backgroundColor + fontStyle:(FLTNativeTemplateFontStyleWrapper *_Nullable)fontStyle + size:(NSNumber *_Nullable)size { self = [super init]; if (self) { _textColor = textColor; @@ -36,26 +37,29 @@ - (UIFont *_Nullable)uiFont { return nil; } - CGFloat size = [FLTAdUtil isNull:_size] ? UIFont.systemFontSize : _size.floatValue; + CGFloat size = + [FLTAdUtil isNull:_size] ? UIFont.systemFontSize : _size.floatValue; if ([FLTAdUtil isNull:_fontStyle]) { return [UIFont systemFontOfSize:size]; } else { switch (_fontStyle.fontStyle) { - case FLTNativeTemplateFontNormal: - return [UIFont systemFontOfSize:size]; - case FLTNativeTemplateFontBold: - return [UIFont boldSystemFontOfSize:size]; - case FLTNativeTemplateFontItalic: - return [UIFont italicSystemFontOfSize:size]; - case FLTNativeTemplateFontMonospace: - if (@available(iOS 13.0, *)) { - return [UIFont monospacedSystemFontOfSize:size weight:UIFontWeightRegular]; - } else { - return [UIFont monospacedDigitSystemFontOfSize:size weight:UIFontWeightRegular]; - } - default: - NSLog(@"Unknown fontStyle case: %ld", _fontStyle.fontStyle); - return [UIFont systemFontOfSize:size]; + case FLTNativeTemplateFontNormal: + return [UIFont systemFontOfSize:size]; + case FLTNativeTemplateFontBold: + return [UIFont boldSystemFontOfSize:size]; + case FLTNativeTemplateFontItalic: + return [UIFont italicSystemFontOfSize:size]; + case FLTNativeTemplateFontMonospace: + if (@available(iOS 13.0, *)) { + return [UIFont monospacedSystemFontOfSize:size + weight:UIFontWeightRegular]; + } else { + return [UIFont monospacedDigitSystemFontOfSize:size + weight:UIFontWeightRegular]; + } + default: + NSLog(@"Unknown fontStyle case: %ld", _fontStyle.fontStyle); + return [UIFont systemFontOfSize:size]; } } } diff --git a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateType.h b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateType.h index dda7b3a01..65bda99b7 100644 --- a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateType.h +++ b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateType.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import #import "GADTTemplateView.h" +#import /** Maps int values to template layout types. */ @interface FLTNativeTemplateType : NSObject diff --git a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateType.m b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateType.m index 126bb09a8..6a8b4579b 100644 --- a/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateType.m +++ b/packages/google_mobile_ads/ios/Classes/NativeTemplates/FLTNativeTemplateType.m @@ -28,19 +28,20 @@ - (instancetype _Nonnull)initWithInt:(int)intValue { - (NSString *_Nonnull)xibName { switch (_intValue) { - case 0: - return @"GADTSmallTemplateView"; - case 1: - return @"GADTMediumTemplateView"; - default: - NSLog(@"Unknown template type value: %d", _intValue); - return @"GADTMediumTemplateView"; + case 0: + return @"GADTSmallTemplateView"; + case 1: + return @"GADTMediumTemplateView"; + default: + NSLog(@"Unknown template type value: %d", _intValue); + return @"GADTMediumTemplateView"; } } - (GADTTemplateView *_Nonnull)templateView { // Bundle file name is declared in podspec - id bundleURL = [NSBundle.mainBundle URLForResource:@"google_mobile_ads" withExtension:@"bundle"]; + id bundleURL = [NSBundle.mainBundle URLForResource:@"google_mobile_ads" + withExtension:@"bundle"]; NSBundle *bundle = [NSBundle bundleWithURL:bundleURL]; GADTTemplateView *templateView = [bundle loadNibNamed:self.xibName owner:nil options:nil].firstObject; diff --git a/packages/google_mobile_ads/ios/Classes/NativeTemplates/GoogleAdsMobileIosNativeTemplates/GADTTemplateView.h b/packages/google_mobile_ads/ios/Classes/NativeTemplates/GoogleAdsMobileIosNativeTemplates/GADTTemplateView.h index 358c5f13c..82a27630a 100644 --- a/packages/google_mobile_ads/ios/Classes/NativeTemplates/GoogleAdsMobileIosNativeTemplates/GADTTemplateView.h +++ b/packages/google_mobile_ads/ios/Classes/NativeTemplates/GoogleAdsMobileIosNativeTemplates/GADTTemplateView.h @@ -22,13 +22,16 @@ typedef NSString *GADTNativeTemplateStyleKey NS_STRING_ENUM; #pragma mark - Call To Action /// Call to action font. Expects a UIFont. -extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyCallToActionFont; +extern GADTNativeTemplateStyleKey const + GADTNativeTemplateStyleKeyCallToActionFont; /// Call to action font color. Expects a UIColor. -extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyCallToActionFontColor; +extern GADTNativeTemplateStyleKey const + GADTNativeTemplateStyleKeyCallToActionFontColor; /// Call to action background color. Expects a UIColor. -extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyCallToActionBackgroundColor; +extern GADTNativeTemplateStyleKey const + GADTNativeTemplateStyleKeyCallToActionBackgroundColor; /// The font, font color and background color for the first row of text in the /// template. All templates have a primary text area which is populated by the @@ -39,10 +42,12 @@ extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyCallToActionBa extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyPrimaryFont; /// Primary text font color. Expects a UIColor. -extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyPrimaryFontColor; +extern GADTNativeTemplateStyleKey const + GADTNativeTemplateStyleKeyPrimaryFontColor; /// Primary text background color. Expects a UIColor. -extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyPrimaryBackgroundColor; +extern GADTNativeTemplateStyleKey const + GADTNativeTemplateStyleKeyPrimaryBackgroundColor; /// The font, font color and background color for the second row of text in the /// template. All templates have a secondary text area which is populated either @@ -53,10 +58,12 @@ extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyPrimaryBackgro extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeySecondaryFont; /// Secondary text font color. Expects a UIColor. -extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeySecondaryFontColor; +extern GADTNativeTemplateStyleKey const + GADTNativeTemplateStyleKeySecondaryFontColor; /// Secondary text background color. Expects a UIColor. -extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeySecondaryBackgroundColor; +extern GADTNativeTemplateStyleKey const + GADTNativeTemplateStyleKeySecondaryBackgroundColor; /// The font, font color and background color for the third row of text in the /// template. The third row is used to display store name or the default @@ -67,15 +74,18 @@ extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeySecondaryBackg extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyTertiaryFont; /// Tertiary text font color. Expects a UIColor. -extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyTertiaryFontColor; +extern GADTNativeTemplateStyleKey const + GADTNativeTemplateStyleKeyTertiaryFontColor; /// Tertiary text background color. Expects a UIColor. -extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyTertiaryBackgroundColor; +extern GADTNativeTemplateStyleKey const + GADTNativeTemplateStyleKeyTertiaryBackgroundColor; #pragma mark - Additional Style Options /// The background color for the bulk of the ad. Expects a UIColor. -extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyMainBackgroundColor; +extern GADTNativeTemplateStyleKey const + GADTNativeTemplateStyleKeyMainBackgroundColor; /// The corner rounding radius for the icon view and call to action. Expects an /// NSNumber. @@ -84,7 +94,8 @@ extern GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyCornerRadius; /// The super class for every template object. /// This class has the majority of all layout and styling logic. @interface GADTTemplateView : GADNativeAdView -@property(nonatomic, copy) NSDictionary *styles; +@property(nonatomic, copy) + NSDictionary *styles; @property(weak) IBOutlet UILabel *adBadge; @property(weak) UIView *rootView; diff --git a/packages/google_mobile_ads/ios/Classes/NativeTemplates/GoogleAdsMobileIosNativeTemplates/GADTTemplateView.m b/packages/google_mobile_ads/ios/Classes/NativeTemplates/GoogleAdsMobileIosNativeTemplates/GADTTemplateView.m index bfd085865..2c8f34134 100644 --- a/packages/google_mobile_ads/ios/Classes/NativeTemplates/GoogleAdsMobileIosNativeTemplates/GADTTemplateView.m +++ b/packages/google_mobile_ads/ios/Classes/NativeTemplates/GoogleAdsMobileIosNativeTemplates/GADTTemplateView.m @@ -18,39 +18,49 @@ GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyCallToActionFont = @"call_to_action_font"; -GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyCallToActionFontColor = - @"call_to_action_font_color"; +GADTNativeTemplateStyleKey const + GADTNativeTemplateStyleKeyCallToActionFontColor = + @"call_to_action_font_color"; -GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyCallToActionBackgroundColor = - @"call_to_action_background_color"; +GADTNativeTemplateStyleKey const + GADTNativeTemplateStyleKeyCallToActionBackgroundColor = + @"call_to_action_background_color"; -GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeySecondaryFont = @"secondary_font"; +GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeySecondaryFont = + @"secondary_font"; GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeySecondaryFontColor = @"secondary_font_color"; -GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeySecondaryBackgroundColor = - @"secondary_background_color"; +GADTNativeTemplateStyleKey const + GADTNativeTemplateStyleKeySecondaryBackgroundColor = + @"secondary_background_color"; -GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyPrimaryFont = @"primary_font"; +GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyPrimaryFont = + @"primary_font"; -GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyPrimaryFontColor = @"primary_font_color"; +GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyPrimaryFontColor = + @"primary_font_color"; -GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyPrimaryBackgroundColor = - @"primary_background_color"; +GADTNativeTemplateStyleKey const + GADTNativeTemplateStyleKeyPrimaryBackgroundColor = + @"primary_background_color"; -GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyTertiaryFont = @"tertiary_font"; +GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyTertiaryFont = + @"tertiary_font"; GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyTertiaryFontColor = @"tertiary_font_color"; -GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyTertiaryBackgroundColor = - @"tertiary_background_color"; +GADTNativeTemplateStyleKey const + GADTNativeTemplateStyleKeyTertiaryBackgroundColor = + @"tertiary_background_color"; GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyMainBackgroundColor = @"main_background_color"; -GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyCornerRadius = @"corner_radius"; +GADTNativeTemplateStyleKey const GADTNativeTemplateStyleKeyCornerRadius = + @"corner_radius"; static NSString *const GADTBlue = @"#5C84F0"; @@ -60,25 +70,28 @@ @implementation GADTTemplateView { - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { - _rootView = [NSBundle.mainBundle loadNibNamed:NSStringFromClass([self class]) - owner:self - options:nil] - .firstObject; + _rootView = + [NSBundle.mainBundle loadNibNamed:NSStringFromClass([self class]) + owner:self + options:nil] + .firstObject; [self addSubview:_rootView]; - [self - addConstraints:[NSLayoutConstraint - constraintsWithVisualFormat:@"H:|[_rootView]|" - options:0 - metrics:nil - views:NSDictionaryOfVariableBindings(_rootView)]]; - [self - addConstraints:[NSLayoutConstraint - constraintsWithVisualFormat:@"V:|[_rootView]|" - options:0 - metrics:nil - views:NSDictionaryOfVariableBindings(_rootView)]]; + [self addConstraints: + [NSLayoutConstraint + constraintsWithVisualFormat:@"H:|[_rootView]|" + options:0 + metrics:nil + views:NSDictionaryOfVariableBindings( + _rootView)]]; + [self addConstraints: + [NSLayoutConstraint + constraintsWithVisualFormat:@"V:|[_rootView]|" + options:0 + metrics:nil + views:NSDictionaryOfVariableBindings( + _rootView)]]; [self applyStyles]; [self styleAdBadge]; } @@ -98,17 +111,20 @@ - (id)styleForKey:(GADTNativeTemplateStyleKey)key { // Goes through all recognized style keys and updates the views accordingly, // overwriting the defaults. - (void)applyStyles { - self.layer.borderColor = [GADTTemplateView colorFromHexString:@"E0E0E0"].CGColor; + self.layer.borderColor = + [GADTTemplateView colorFromHexString:@"E0E0E0"].CGColor; self.layer.borderWidth = 1.0f; [self.mediaView sizeToFit]; if ([self styleForKey:GADTNativeTemplateStyleKeyCornerRadius]) { float roundedCornerRadius = - ((NSNumber *)[self styleForKey:GADTNativeTemplateStyleKeyCornerRadius]).floatValue; + ((NSNumber *)[self styleForKey:GADTNativeTemplateStyleKeyCornerRadius]) + .floatValue; // Rounded corners self.iconView.layer.cornerRadius = roundedCornerRadius; self.iconView.clipsToBounds = YES; - ((UIButton *)self.callToActionView).layer.cornerRadius = roundedCornerRadius; + ((UIButton *)self.callToActionView).layer.cornerRadius = + roundedCornerRadius; ((UIButton *)self.callToActionView).clipsToBounds = YES; } @@ -135,49 +151,52 @@ - (void)applyStyles { // Font colors if ([self styleForKey:GADTNativeTemplateStyleKeyPrimaryFontColor]) - ((UILabel *)self.headlineView).textColor = - (UIColor *)[self styleForKey:GADTNativeTemplateStyleKeyPrimaryFontColor]; + ((UILabel *)self.headlineView).textColor = (UIColor *)[self + styleForKey:GADTNativeTemplateStyleKeyPrimaryFontColor]; if ([self styleForKey:GADTNativeTemplateStyleKeySecondaryFontColor]) { - ((UILabel *)self.bodyView).textColor = - (UIColor *)[self styleForKey:GADTNativeTemplateStyleKeySecondaryFontColor]; + ((UILabel *)self.bodyView).textColor = (UIColor *)[self + styleForKey:GADTNativeTemplateStyleKeySecondaryFontColor]; } if ([self styleForKey:GADTNativeTemplateStyleKeyTertiaryFontColor]) { - ((UILabel *)self.advertiserView).textColor = - (UIColor *)[self styleForKey:GADTNativeTemplateStyleKeyTertiaryFontColor]; + ((UILabel *)self.advertiserView).textColor = (UIColor *)[self + styleForKey:GADTNativeTemplateStyleKeyTertiaryFontColor]; } if ([self styleForKey:GADTNativeTemplateStyleKeyCallToActionFontColor]) { [((UIButton *)self.callToActionView) - setTitleColor:(UIColor *)[self styleForKey:GADTNativeTemplateStyleKeyCallToActionFontColor] + setTitleColor: + (UIColor *)[self + styleForKey:GADTNativeTemplateStyleKeyCallToActionFontColor] forState:UIControlStateNormal]; } // Background colors if ([self styleForKey:GADTNativeTemplateStyleKeyPrimaryBackgroundColor]) { - ((UILabel *)self.headlineView).backgroundColor = - (UIColor *)[self styleForKey:GADTNativeTemplateStyleKeyPrimaryBackgroundColor]; + ((UILabel *)self.headlineView).backgroundColor = (UIColor *)[self + styleForKey:GADTNativeTemplateStyleKeyPrimaryBackgroundColor]; } if ([self styleForKey:GADTNativeTemplateStyleKeySecondaryBackgroundColor]) { - ((UILabel *)self.bodyView).backgroundColor = - (UIColor *)[self styleForKey:GADTNativeTemplateStyleKeySecondaryBackgroundColor]; + ((UILabel *)self.bodyView).backgroundColor = (UIColor *)[self + styleForKey:GADTNativeTemplateStyleKeySecondaryBackgroundColor]; } if ([self styleForKey:GADTNativeTemplateStyleKeyTertiaryBackgroundColor]) { - ((UILabel *)self.advertiserView).backgroundColor = - (UIColor *)[self styleForKey:GADTNativeTemplateStyleKeyTertiaryBackgroundColor]; + ((UILabel *)self.advertiserView).backgroundColor = (UIColor *)[self + styleForKey:GADTNativeTemplateStyleKeyTertiaryBackgroundColor]; } - if ([self styleForKey:GADTNativeTemplateStyleKeyCallToActionBackgroundColor]) { - ((UIButton *)self.callToActionView).backgroundColor = - (UIColor *)[self styleForKey:GADTNativeTemplateStyleKeyCallToActionBackgroundColor]; + if ([self + styleForKey:GADTNativeTemplateStyleKeyCallToActionBackgroundColor]) { + ((UIButton *)self.callToActionView).backgroundColor = (UIColor *)[self + styleForKey:GADTNativeTemplateStyleKeyCallToActionBackgroundColor]; } if ([self styleForKey:GADTNativeTemplateStyleKeyMainBackgroundColor]) { - self.backgroundColor = - (UIColor *)[self styleForKey:GADTNativeTemplateStyleKeyMainBackgroundColor]; + self.backgroundColor = (UIColor *)[self + styleForKey:GADTNativeTemplateStyleKeyMainBackgroundColor]; } [self styleAdBadge]; } @@ -190,7 +209,8 @@ - (void)styleAdBadge { adBadge.layer.masksToBounds = YES; } -- (void)setStyles:(NSDictionary *)styles { +- (void)setStyles: + (NSDictionary *)styles { _styles = [styles copy]; [self applyStyles]; } @@ -258,24 +278,28 @@ - (void)addHorizontalConstraintsToSuperviewWidth { if (self.superview) { UIView *child = self; [self.superview - addConstraints:[NSLayoutConstraint - constraintsWithVisualFormat:@"H:|[child]|" - options:0 - metrics:nil - views:NSDictionaryOfVariableBindings(child)]]; + addConstraints: + [NSLayoutConstraint + constraintsWithVisualFormat:@"H:|[child]|" + options:0 + metrics:nil + views:NSDictionaryOfVariableBindings( + child)]]; } } - (void)addVerticalCenterConstraintToSuperview { if (self.superview) { UIView *child = self; - [self.superview addConstraint:[NSLayoutConstraint constraintWithItem:self.superview - attribute:NSLayoutAttributeCenterY - relatedBy:NSLayoutRelationEqual - toItem:child - attribute:NSLayoutAttributeCenterY - multiplier:1 - constant:0]]; + [self.superview + addConstraint:[NSLayoutConstraint + constraintWithItem:self.superview + attribute:NSLayoutAttributeCenterY + relatedBy:NSLayoutRelationEqual + toItem:child + attribute:NSLayoutAttributeCenterY + multiplier:1 + constant:0]]; } } @@ -284,13 +308,14 @@ + (UIColor *)colorFromHexString:(NSString *)hexString { if (hexString == nil) { return nil; } - NSRange range = [hexString rangeOfString:@"^#[0-9a-fA-F]{6}$" options:NSRegularExpressionSearch]; + NSRange range = [hexString rangeOfString:@"^#[0-9a-fA-F]{6}$" + options:NSRegularExpressionSearch]; if (range.location == NSNotFound) { return nil; } unsigned rgbValue = 0; NSScanner *scanner = [NSScanner scannerWithString:hexString]; - [scanner setScanLocation:1]; // Bypass '#' character. + [scanner setScanLocation:1]; // Bypass '#' character. [scanner scanHexInt:&rgbValue]; return [UIColor colorWithRed:((rgbValue & 0xff0000) >> 16) / 255.0f diff --git a/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformManager.h b/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformManager.h index e9e8a8211..9bfd93cf7 100644 --- a/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformManager.h +++ b/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformManager.h @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "FLTUserMessagingPlatformReaderWriter.h" #import #import -#include "FLTUserMessagingPlatformReaderWriter.h" @interface FLTUserMessagingPlatformManager : NSObject @@ -23,6 +23,7 @@ - (instancetype _Nonnull)initWithBinaryMessenger: (NSObject *_Nonnull)binaryMessenger; -- (void)handleMethodCall:(FlutterMethodCall *_Nonnull)call result:(FlutterResult _Nonnull)result; +- (void)handleMethodCall:(FlutterMethodCall *_Nonnull)call + result:(FlutterResult _Nonnull)result; @end diff --git a/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformManager.m b/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformManager.m index 71e81eb93..4201b34d9 100644 --- a/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformManager.m +++ b/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformManager.m @@ -13,10 +13,10 @@ // limitations under the License. #import "FLTUserMessagingPlatformManager.h" -#include #import "../FLTAdUtil.h" #import "../FLTNSString.h" #import "FLTUserMessagingPlatformReaderWriter.h" +#include @implementation FLTUserMessagingPlatformManager { FlutterMethodChannel *_methodChannel; @@ -29,16 +29,16 @@ - (instancetype _Nonnull)initWithBinaryMessenger: self.readerWriter = [[FLTUserMessagingPlatformReaderWriter alloc] init]; NSObject *methodCodec = [FlutterStandardMethodCodec codecWithReaderWriter:_readerWriter]; - _methodChannel = - [[FlutterMethodChannel alloc] initWithName:@"plugins.flutter.io/google_mobile_ads/ump" - binaryMessenger:binaryMessenger - codec:methodCodec]; + _methodChannel = [[FlutterMethodChannel alloc] + initWithName:@"plugins.flutter.io/google_mobile_ads/ump" + binaryMessenger:binaryMessenger + codec:methodCodec]; FLTUserMessagingPlatformManager *__weak weakSelf = self; - [_methodChannel - setMethodCallHandler:^(FlutterMethodCall *_Nonnull call, FlutterResult _Nonnull result) { - [weakSelf handleMethodCall:call result:result]; - }]; + [_methodChannel setMethodCallHandler:^(FlutterMethodCall *_Nonnull call, + FlutterResult _Nonnull result) { + [weakSelf handleMethodCall:call result:result]; + }]; } return self; } @@ -47,31 +47,37 @@ - (UIViewController *)rootController { return UIApplication.sharedApplication.delegate.window.rootViewController; } -- (void)handleMethodCall:(FlutterMethodCall *_Nonnull)call result:(FlutterResult _Nonnull)result { +- (void)handleMethodCall:(FlutterMethodCall *_Nonnull)call + result:(FlutterResult _Nonnull)result { if ([call.method isEqualToString:@"ConsentInformation#reset"]) { [UMPConsentInformation.sharedInstance reset]; result(nil); - } else if ([call.method isEqualToString:@"ConsentInformation#getConsentStatus"]) { - UMPConsentStatus status = UMPConsentInformation.sharedInstance.consentStatus; + } else if ([call.method + isEqualToString:@"ConsentInformation#getConsentStatus"]) { + UMPConsentStatus status = + UMPConsentInformation.sharedInstance.consentStatus; result([[NSNumber alloc] initWithInteger:status]); - } else if ([call.method isEqualToString:@"ConsentInformation#canRequestAds"]) { + } else if ([call.method + isEqualToString:@"ConsentInformation#canRequestAds"]) { result(@([UMPConsentInformation.sharedInstance canRequestAds])); - } else if ([call.method isEqualToString:@"ConsentInformation#" - @"getPrivacyOptionsRequirementStatus"]) { + } else if ([call.method + isEqualToString:@"ConsentInformation#" + @"getPrivacyOptionsRequirementStatus"]) { UMPPrivacyOptionsRequirementStatus status = UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus; switch (status) { - case UMPPrivacyOptionsRequirementStatusNotRequired: - result([[NSNumber alloc] initWithInt:0]); - break; - case UMPPrivacyOptionsRequirementStatusRequired: - result([[NSNumber alloc] initWithInt:1]); - break; - default: - result([[NSNumber alloc] initWithInt:2]); - break; + case UMPPrivacyOptionsRequirementStatusNotRequired: + result([[NSNumber alloc] initWithInt:0]); + break; + case UMPPrivacyOptionsRequirementStatusRequired: + result([[NSNumber alloc] initWithInt:1]); + break; + default: + result([[NSNumber alloc] initWithInt:2]); + break; } - } else if ([call.method isEqualToString:@"ConsentInformation#requestConsentInfoUpdate"]) { + } else if ([call.method isEqualToString: + @"ConsentInformation#requestConsentInfoUpdate"]) { UMPRequestParameters *parameters = call.arguments[@"params"]; [UMPConsentInformation.sharedInstance requestConsentInfoUpdateWithParameters:parameters @@ -80,13 +86,15 @@ - (void)handleMethodCall:(FlutterMethodCall *_Nonnull)call result:(FlutterResult result(nil); } else { result([FlutterError - errorWithCode:[[NSString alloc] initWithInt:error.code] + errorWithCode:[[NSString alloc] + initWithInt:error.code] message:error.localizedDescription details:error.domain]); } }]; - } else if ([call.method isEqualToString:@"UserMessagingPlatform#" - @"loadAndShowConsentFormIfRequired"]) { + } else if ([call.method + isEqualToString:@"UserMessagingPlatform#" + @"loadAndShowConsentFormIfRequired"]) { [UMPConsentForm loadAndPresentIfRequiredFromViewController:self.rootController completionHandler:^(NSError *_Nullable error) { @@ -94,37 +102,52 @@ - (void)handleMethodCall:(FlutterMethodCall *_Nonnull)call result:(FlutterResult result(nil); } else { result([FlutterError - errorWithCode:[[NSString alloc] initWithInt:error.code] - message:error.localizedDescription + errorWithCode: + [[NSString alloc] + initWithInt:error.code] + message:error + .localizedDescription details:error.domain]); } }]; - } else if ([call.method isEqualToString:@"UserMessagingPlatform#loadConsentForm"]) { - [UMPConsentForm loadWithCompletionHandler:^(UMPConsentForm *form, NSError *loadError) { - if ([FLTAdUtil isNull:loadError]) { - [self.readerWriter trackConsentForm:form]; - result(form); - } else { - result([FlutterError errorWithCode:[[NSString alloc] initWithInt:loadError.code] - message:loadError.localizedDescription - details:loadError.domain]); - } - }]; - } else if ([call.method isEqualToString:@"UserMessagingPlatform#showPrivacyOptionsForm"]) { - [UMPConsentForm presentPrivacyOptionsFormFromViewController:self.rootController - completionHandler:^(NSError *_Nullable formError) { - if ([FLTAdUtil isNull:formError]) { - result(nil); - } else { - result([FlutterError - errorWithCode:[[NSString alloc] - initWithInt:formError.code] - message:formError.localizedDescription - details:formError.domain]); - } - }]; - } else if ([call.method isEqualToString:@"ConsentInformation#isConsentFormAvailable"]) { - BOOL isAvailable = UMPConsentInformation.sharedInstance.formStatus == UMPFormStatusAvailable; + } else if ([call.method + isEqualToString:@"UserMessagingPlatform#loadConsentForm"]) { + [UMPConsentForm + loadWithCompletionHandler:^(UMPConsentForm *form, NSError *loadError) { + if ([FLTAdUtil isNull:loadError]) { + [self.readerWriter trackConsentForm:form]; + result(form); + } else { + result([FlutterError + errorWithCode:[[NSString alloc] initWithInt:loadError.code] + message:loadError.localizedDescription + details:loadError.domain]); + } + }]; + } else if ([call.method + isEqualToString: + @"UserMessagingPlatform#showPrivacyOptionsForm"]) { + [UMPConsentForm + presentPrivacyOptionsFormFromViewController:self.rootController + completionHandler:^( + NSError *_Nullable formError) { + if ([FLTAdUtil isNull:formError]) { + result(nil); + } else { + result([FlutterError + errorWithCode: + [[NSString alloc] + initWithInt:formError.code] + message: + formError + .localizedDescription + details:formError.domain]); + } + }]; + } else if ([call.method isEqualToString: + @"ConsentInformation#isConsentFormAvailable"]) { + BOOL isAvailable = UMPConsentInformation.sharedInstance.formStatus == + UMPFormStatusAvailable; result([[NSNumber alloc] initWithBool:isAvailable]); } else if ([call.method isEqualToString:@"ConsentForm#show"]) { UMPConsentForm *consentForm = call.arguments[@"consentForm"]; @@ -134,9 +157,10 @@ - (void)handleMethodCall:(FlutterMethodCall *_Nonnull)call result:(FlutterResult if ([FLTAdUtil isNull:error]) { result(nil); } else { - result([FlutterError errorWithCode:[[NSString alloc] initWithInt:error.code] - message:error.localizedDescription - details:error.domain]); + result([FlutterError + errorWithCode:[[NSString alloc] initWithInt:error.code] + message:error.localizedDescription + details:error.domain]); } }]; } else if ([call.method isEqualToString:@"ConsentForm#dispose"]) { diff --git a/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformReaderWriter.m b/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformReaderWriter.m index 6f9b8d5de..7056f984f 100644 --- a/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformReaderWriter.m +++ b/packages/google_mobile_ads/ios/Classes/UserMessagingPlatform/FLTUserMessagingPlatformReaderWriter.m @@ -13,8 +13,8 @@ // limitations under the License. #import "FLTUserMessagingPlatformReaderWriter.h" -#include #import "../FLTAdUtil.h" +#include // The type values below must be consistent for each platform. typedef NS_ENUM(NSInteger, FLTUserMessagingPlatformField) { @@ -62,7 +62,8 @@ - (FlutterStandardReader *_Nonnull)readerWithData:(NSData *_Nonnull)data { return reader; } -- (FlutterStandardWriter *_Nonnull)writerWithData:(NSMutableData *_Nonnull)data { +- (FlutterStandardWriter *_Nonnull)writerWithData: + (NSMutableData *_Nonnull)data { FLTUserMessagingPlatformWriter *writer = [[FLTUserMessagingPlatformWriter alloc] initWithData:data]; writer.consentFormDict = self.consentFormDict; @@ -82,12 +83,14 @@ - (void)writeValue:(id)value { UMPRequestParameters *params = (UMPRequestParameters *)value; [self writeByte:FLTValueConsentRequestParameters]; - [self writeValue:[[NSNumber alloc] initWithBool:params.tagForUnderAgeOfConsent]]; + [self writeValue:[[NSNumber alloc] + initWithBool:params.tagForUnderAgeOfConsent]]; [self writeValue:params.debugSettings]; } else if ([value isKindOfClass:[UMPDebugSettings class]]) { UMPDebugSettings *debugSettings = (UMPDebugSettings *)value; [self writeByte:FLTValueConsentDebugSettings]; - [self writeValue:[[NSNumber alloc] initWithInteger:debugSettings.geography]]; + [self + writeValue:[[NSNumber alloc] initWithInteger:debugSettings.geography]]; [self writeValue:debugSettings.testDeviceIdentifiers]; } else { [super writeValue:value]; @@ -101,33 +104,34 @@ @implementation FLTUserMessagingPlatformReader - (id _Nullable)readValueOfType:(UInt8)type { FLTUserMessagingPlatformField field = (FLTUserMessagingPlatformField)type; switch (field) { - case FLTValueConsentRequestParameters: { - UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init]; - NSNumber *tfuac = [self readValueOfType:[self readByte]]; - - parameters.tagForUnderAgeOfConsent = tfuac.boolValue; - UMPDebugSettings *debugSettings = [self readValueOfType:[self readByte]]; - parameters.debugSettings = debugSettings; - return parameters; - } - case FLTValueConsentDebugSettings: { - UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init]; - NSNumber *geography = [self readValueOfType:[self readByte]]; - NSArray *testIdentifiers = [self readValueOfType:[self readByte]]; - if ([FLTAdUtil isNotNull:geography]) { - debugSettings.geography = geography.intValue; - } - if ([FLTAdUtil isNotNull:testIdentifiers]) { - debugSettings.testDeviceIdentifiers = testIdentifiers; - } - return debugSettings; + case FLTValueConsentRequestParameters: { + UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init]; + NSNumber *tfuac = [self readValueOfType:[self readByte]]; + + parameters.tagForUnderAgeOfConsent = tfuac.boolValue; + UMPDebugSettings *debugSettings = [self readValueOfType:[self readByte]]; + parameters.debugSettings = debugSettings; + return parameters; + } + case FLTValueConsentDebugSettings: { + UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init]; + NSNumber *geography = [self readValueOfType:[self readByte]]; + NSArray *testIdentifiers = + [self readValueOfType:[self readByte]]; + if ([FLTAdUtil isNotNull:geography]) { + debugSettings.geography = geography.intValue; } - case FLTValueConsentForm: { - NSNumber *hash = [self readValueOfType:[self readByte]]; - return _consentFormDict[hash]; + if ([FLTAdUtil isNotNull:testIdentifiers]) { + debugSettings.testDeviceIdentifiers = testIdentifiers; } - default: - return [super readValueOfType:type]; + return debugSettings; + } + case FLTValueConsentForm: { + NSNumber *hash = [self readValueOfType:[self readByte]]; + return _consentFormDict[hash]; + } + default: + return [super readValueOfType:type]; } } From 64f1d6d7d3e0ac4c34b769c3d4ee5ee667192233 Mon Sep 17 00:00:00 2001 From: Aldo Becerril Date: Fri, 9 Aug 2024 11:52:54 -0700 Subject: [PATCH 06/15] format fix --- .../ios/RunnerTests/FLTAppOpenAdTest.m | 73 ++- .../RunnerTests/FLTGamInterstitialAdTest.m | 91 ++-- .../ios/RunnerTests/FLTGoogleMobileAdsTest.m | 336 ++++++------ .../ios/RunnerTests/FLTInterstitialAdTest.m | 77 ++- .../ios/RunnerTests/FLTRewardedAdTest.m | 89 ++-- .../FLTRewardedInterstitialAdTest.m | 122 ++--- .../Classes/FLTAdInstanceManager_Internal.h | 19 +- .../Classes/FLTAdInstanceManager_Internal.m | 36 +- .../ios/Classes/FLTAd_Internal.h | 108 ++-- .../ios/Classes/FLTAd_Internal.m | 490 +++++++----------- .../ios/Classes/FLTGoogleMobileAdsPlugin.m | 357 ++++++------- 11 files changed, 747 insertions(+), 1051 deletions(-) diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m index dfc65a59d..93286f3cb 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m @@ -47,8 +47,7 @@ - (void)testLoadShowGAMRequest { OCMClassMock([FLTServerSideVerificationOptions class]); GADServerSideVerificationOptions *gadOptions = OCMClassMock([GADServerSideVerificationOptions class]); - OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]) - .andReturn(gadOptions); + OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]).andReturn(gadOptions); [self testLoadShowAppOpenAd:request gadOrGAMRequest:gamRequest]; } @@ -56,12 +55,8 @@ - (void)testLoadShowGAMRequest { // Helper method for testing with FLTAdRequest and FLTGAMAdRequest. - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request gadOrGAMRequest:(GADRequest *)gadOrGAMRequest { - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); - FLTAppOpenAd *ad = - [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); + FLTAppOpenAd *ad = [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" request:request adId:@1]; ad.manager = mockManager; // Stub the load call to invoke successful load callback. @@ -86,8 +81,7 @@ - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request [delegate adDidDismissFullScreenContent:appOpenClassMock]; [delegate adWillPresentFullScreenContent:appOpenClassMock]; [delegate adWillDismissFullScreenContent:appOpenClassMock]; - [delegate ad:appOpenClassMock - didFailToPresentFullScreenContentWithError:error]; + [delegate ad:appOpenClassMock didFailToPresentFullScreenContentWithError:error]; }); GADResponseInfo *responseInfo = OCMClassMock([GADResponseInfo class]); OCMStub([appOpenClassMock responseInfo]).andReturn(responseInfo); @@ -97,40 +91,36 @@ - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request OCMStub([adValue value]).andReturn(NSDecimalNumber.one); OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated); OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); - OCMStub([appOpenClassMock - setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - GADPaidEventHandler handler = obj; - handler(adValue); - return YES; - }]]); + OCMStub([appOpenClassMock setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + GADPaidEventHandler handler = obj; + handler(adValue); + return YES; + }]]); // Call load and check expected interactions with mocks. [ad load]; - OCMVerify(ClassMethod([appOpenClassMock - loadWithAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadOrGAMRequest] - completionHandler:[OCMArg any]])); + OCMVerify(ClassMethod([appOpenClassMock loadWithAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadOrGAMRequest] + completionHandler:[OCMArg any]])); OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad] responseInfo:[OCMArg isEqual:responseInfo]]); - OCMVerify( - [appOpenClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); + OCMVerify([appOpenClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); XCTAssertEqual(ad.appOpenAd, appOpenClassMock); - OCMVerify([mockManager - onPaidEvent:[OCMArg isEqual:ad] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); [ad showFromRootViewController:mockRootViewController]; - OCMVerify([appOpenClassMock - presentFromRootViewController:[OCMArg isEqual:mockRootViewController]]); + OCMVerify( + [appOpenClassMock presentFromRootViewController:[OCMArg isEqual:mockRootViewController]]); // Verify full screen callbacks. OCMVerify([mockManager adWillPresentFullScreenContent:[OCMArg isEqual:ad]]); @@ -138,9 +128,8 @@ - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request OCMVerify([mockManager adWillDismissFullScreenContent:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordImpression:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:ad]]); - OCMVerify([mockManager - didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); } - (void)testFailedToLoadGADRequest { @@ -161,10 +150,7 @@ - (void)testFailedToLoadGAMRequest { // Helper for testing failed to load. - (void)testFailedToLoad:(FLTAdRequest *)request { - FLTAppOpenAd *ad = - [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + FLTAppOpenAd *ad = [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" request:request adId:@1]; ad.manager = mockManager; id appOpenClassMock = OCMClassMock([GADAppOpenAd class]); @@ -183,8 +169,7 @@ - (void)testFailedToLoad:(FLTAdRequest *)request { OCMVerify(ClassMethod([appOpenClassMock loadWithAdUnitID:[OCMArg any] request:[OCMArg any] completionHandler:[OCMArg any]])); - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m index c3d55f8d7..3cc61b069 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m @@ -35,19 +35,16 @@ - (void)testLoadShowInterstitialAd { GAMRequest *gadRequest = OCMClassMock([GAMRequest class]); OCMStub([request asGAMRequest:[OCMArg any]]).andReturn(gadRequest); - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); - FLTGAMInterstitialAd *ad = - [[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); + FLTGAMInterstitialAd *ad = [[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id interstitialClassMock = OCMClassMock([GAMInterstitialAd class]); - OCMStub(ClassMethod([interstitialClassMock - loadWithAdManagerAdUnitID:[OCMArg any] - request:[OCMArg any] - completionHandler:[OCMArg any]])) + OCMStub(ClassMethod([interstitialClassMock loadWithAdManagerAdUnitID:[OCMArg any] + request:[OCMArg any] + completionHandler:[OCMArg any]])) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(GAMInterstitialAd *ad, NSError *error); [invocation getArgument:&completionHandler atIndex:4]; @@ -64,8 +61,7 @@ - (void)testLoadShowInterstitialAd { [delegate adDidDismissFullScreenContent:interstitialClassMock]; [delegate adWillPresentFullScreenContent:interstitialClassMock]; [delegate adWillDismissFullScreenContent:interstitialClassMock]; - [delegate ad:interstitialClassMock - didFailToPresentFullScreenContentWithError:error]; + [delegate ad:interstitialClassMock didFailToPresentFullScreenContentWithError:error]; }); OCMStub([interstitialClassMock setAppEventDelegate:[OCMArg any]]) @@ -86,35 +82,31 @@ - (void)testLoadShowInterstitialAd { OCMStub([adValue value]).andReturn(NSDecimalNumber.one); OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated); OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); - OCMStub([interstitialClassMock - setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - GADPaidEventHandler handler = obj; - handler(adValue); - return YES; - }]]); + OCMStub([interstitialClassMock setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + GADPaidEventHandler handler = obj; + handler(adValue); + return YES; + }]]); // Call load and verify interactions with mocks. [ad load]; - OCMVerify(ClassMethod([interstitialClassMock - loadWithAdManagerAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadRequest] - completionHandler:[OCMArg any]])); + OCMVerify(ClassMethod([interstitialClassMock loadWithAdManagerAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadRequest] + completionHandler:[OCMArg any]])); OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad] responseInfo:[OCMArg isEqual:responseInfo]]); - OCMVerify( - [interstitialClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); + OCMVerify([interstitialClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); XCTAssertEqual(ad.interstitial, interstitialClassMock); - OCMVerify([mockManager - onPaidEvent:[OCMArg isEqual:ad] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); // Show the ad [ad showFromRootViewController:mockRootViewController]; @@ -128,9 +120,8 @@ - (void)testLoadShowInterstitialAd { OCMVerify([mockManager adWillDismissFullScreenContent:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordImpression:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:ad]]); - OCMVerify([mockManager - didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); // Verify app event OCMVerify([mockManager onAppEvent:ad @@ -144,18 +135,16 @@ - (void)testFailToLoad { GAMRequest *gadRequest = OCMClassMock([GAMRequest class]); OCMStub([request asGAMRequest:[OCMArg any]]).andReturn(gadRequest); - FLTGAMInterstitialAd *ad = - [[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + FLTGAMInterstitialAd *ad = [[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id interstitialClassMock = OCMClassMock([GAMInterstitialAd class]); NSError *error = OCMClassMock([NSError class]); - OCMStub(ClassMethod([interstitialClassMock - loadWithAdManagerAdUnitID:[OCMArg any] - request:[OCMArg any] - completionHandler:[OCMArg any]])) + OCMStub(ClassMethod([interstitialClassMock loadWithAdManagerAdUnitID:[OCMArg any] + request:[OCMArg any] + completionHandler:[OCMArg any]])) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(GAMInterstitialAd *ad, NSError *error); [invocation getArgument:&completionHandler atIndex:4]; @@ -164,12 +153,10 @@ - (void)testFailToLoad { [ad load]; - OCMVerify(ClassMethod([interstitialClassMock - loadWithAdManagerAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadRequest] - completionHandler:[OCMArg any]])); - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify(ClassMethod([interstitialClassMock loadWithAdManagerAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadRequest] + completionHandler:[OCMArg any]])); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m index 5cccc781f..fbebd24e7 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m @@ -35,20 +35,19 @@ @implementation FLTGoogleMobileAdsTest { - (void)setUp { _mockMessenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger)); - _manager = - [[FLTAdInstanceManager alloc] initWithBinaryMessenger:_mockMessenger]; + _manager = [[FLTAdInstanceManager alloc] initWithBinaryMessenger:_mockMessenger]; _methodCodec = [FlutterStandardMethodCodec codecWithReaderWriter:[[FLTGoogleMobileAdsReaderWriter alloc] init]]; } - (void)testAdInstanceManagerLoadAd { FLTAdSize *size = [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)]; - FLTBannerAd *bannerAd = [[FLTBannerAd alloc] - initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@1]; + FLTBannerAd *bannerAd = + [[FLTBannerAd alloc] initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@1]; FLTBannerAd *mockBannerAd = OCMPartialMock(bannerAd); OCMStub([mockBannerAd load]); @@ -62,12 +61,12 @@ - (void)testAdInstanceManagerLoadAd { - (void)testAdInstanceManagerDisposeAd { FLTAdSize *size = [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)]; - FLTBannerAd *bannerAd = [[FLTBannerAd alloc] - initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@1]; + FLTBannerAd *bannerAd = + [[FLTBannerAd alloc] initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@1]; FLTBannerAd *mockBannerAd = OCMPartialMock(bannerAd); OCMStub([mockBannerAd load]); @@ -80,21 +79,21 @@ - (void)testAdInstanceManagerDisposeAd { - (void)testAdInstanceManagerDisposeAllAds { FLTAdSize *size = [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)]; - FLTBannerAd *bannerAd1 = [[FLTBannerAd alloc] - initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@1]; + FLTBannerAd *bannerAd1 = + [[FLTBannerAd alloc] initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@1]; FLTBannerAd *mockBannerAd1 = OCMPartialMock(bannerAd1); OCMStub([mockBannerAd1 load]); - FLTBannerAd *bannerAd2 = [[FLTBannerAd alloc] - initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@2]; + FLTBannerAd *bannerAd2 = + [[FLTBannerAd alloc] initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@2]; FLTBannerAd *mockBannerAd2 = OCMPartialMock(bannerAd2); OCMStub([mockBannerAd2 load]); @@ -109,15 +108,15 @@ - (void)testAdInstanceManagerDisposeAllAds { } - (void)testAdInstanceManagerOnAdLoaded { - FLTNativeAd *ad = [[FLTNativeAd alloc] - initWithAdUnitId:@"testAdUnitId" - request:[[FLTAdRequest alloc] init] - nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) - customOptions:nil - rootViewController:OCMClassMock([UIViewController class]) - adId:@1 - nativeAdOptions:nil - nativeTemplateStyle:nil]; + FLTNativeAd *ad = + [[FLTNativeAd alloc] initWithAdUnitId:@"testAdUnitId" + request:[[FLTAdRequest alloc] init] + nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) + customOptions:nil + rootViewController:OCMClassMock([UIViewController class]) + adId:@1 + nativeAdOptions:nil + nativeTemplateStyle:nil]; [_manager loadAd:ad]; GADResponseInfo *responseInfo = OCMClassMock([GADResponseInfo class]); @@ -125,26 +124,25 @@ - (void)testAdInstanceManagerOnAdLoaded { [[FLTGADResponseInfo alloc] initWithResponseInfo:responseInfo]; [_manager onAdLoaded:ad responseInfo:responseInfo]; NSData *data = [_methodCodec - encodeMethodCall:[FlutterMethodCall - methodCallWithMethodName:@"onAdEvent" - arguments:@{ - @"adId" : @1, - @"eventName" : @"onAdLoaded", - @"responseInfo" : fltResponseInfo, - }]]; + encodeMethodCall:[FlutterMethodCall methodCallWithMethodName:@"onAdEvent" + arguments:@{ + @"adId" : @1, + @"eventName" : @"onAdLoaded", + @"responseInfo" : fltResponseInfo, + }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); } - (void)testAdInstanceManagerOnAdFailedToLoad { - FLTNativeAd *ad = [[FLTNativeAd alloc] - initWithAdUnitId:@"testAdUnitId" - request:[[FLTAdRequest alloc] init] - nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) - customOptions:nil - rootViewController:OCMClassMock([UIViewController class]) - adId:@1 - nativeAdOptions:nil - nativeTemplateStyle:nil]; + FLTNativeAd *ad = + [[FLTNativeAd alloc] initWithAdUnitId:@"testAdUnitId" + request:[[FLTAdRequest alloc] init] + nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) + customOptions:nil + rootViewController:OCMClassMock([UIViewController class]) + adId:@1 + nativeAdOptions:nil + nativeTemplateStyle:nil]; [_manager loadAd:ad]; NSDictionary *userInfo = @{NSLocalizedDescriptionKey : @"message"}; @@ -153,13 +151,12 @@ - (void)testAdInstanceManagerOnAdFailedToLoad { FLTLoadAdError *loadAdError = [[FLTLoadAdError alloc] initWithError:error]; [_manager onAdFailedToLoad:ad error:error]; NSData *data = [_methodCodec - encodeMethodCall:[FlutterMethodCall - methodCallWithMethodName:@"onAdEvent" - arguments:@{ - @"adId" : @1, - @"eventName" : @"onAdFailedToLoad", - @"loadAdError" : loadAdError, - }]]; + encodeMethodCall:[FlutterMethodCall methodCallWithMethodName:@"onAdEvent" + arguments:@{ + @"adId" : @1, + @"eventName" : @"onAdFailedToLoad", + @"loadAdError" : loadAdError, + }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); } @@ -177,50 +174,44 @@ - (void)testAdInstanceManagerOnAdFailedToShow { methodCallWithMethodName:@"onAdEvent" arguments:@{ @"adId" : @1, - @"eventName" : - @"didFailToPresentFullScreenCon" - @"tentWithError", + @"eventName" : @"didFailToPresentFullScreenCon" + @"tentWithError", @"error" : error, }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); } - (void)testAdInstanceManagerOnAppEvent { - FLTNativeAd *ad = [[FLTNativeAd alloc] - initWithAdUnitId:@"testAdUnitId" - request:[[FLTAdRequest alloc] init] - nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) - customOptions:nil - rootViewController:OCMClassMock([UIViewController class]) - adId:@1 - nativeAdOptions:nil - nativeTemplateStyle:nil]; - FlutterMethodChannel *mockMethodChannel = - OCMClassMock([FlutterMethodChannel class]); + FLTNativeAd *ad = + [[FLTNativeAd alloc] initWithAdUnitId:@"testAdUnitId" + request:[[FLTAdRequest alloc] init] + nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) + customOptions:nil + rootViewController:OCMClassMock([UIViewController class]) + adId:@1 + nativeAdOptions:nil + nativeTemplateStyle:nil]; + FlutterMethodChannel *mockMethodChannel = OCMClassMock([FlutterMethodChannel class]); [_manager setValue:mockMethodChannel forKey:@"_channel"]; [_manager loadAd:ad]; [_manager onAppEvent:ad name:@"color" data:@"red"]; - NSDictionary *arguments = @{ - @"adId" : @1, - @"eventName" : @"onAppEvent", - @"name" : @"color", - @"data" : @"red" - }; + NSDictionary *arguments = + @{@"adId" : @1, @"eventName" : @"onAppEvent", @"name" : @"color", @"data" : @"red"}; OCMVerify([mockMethodChannel invokeMethod:@"onAdEvent" arguments:arguments]); } - (void)testAdInstanceManagerOnNativeAdEvents { - FLTNativeAd *ad = [[FLTNativeAd alloc] - initWithAdUnitId:@"testAdUnitId" - request:[[FLTAdRequest alloc] init] - nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) - customOptions:nil - rootViewController:OCMClassMock([UIViewController class]) - adId:@1 - nativeAdOptions:nil - nativeTemplateStyle:nil]; + FLTNativeAd *ad = + [[FLTNativeAd alloc] initWithAdUnitId:@"testAdUnitId" + request:[[FLTAdRequest alloc] init] + nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) + customOptions:nil + rootViewController:OCMClassMock([UIViewController class]) + adId:@1 + nativeAdOptions:nil + nativeTemplateStyle:nil]; [_manager loadAd:ad]; [_manager adDidRecordClick:ad]; @@ -228,89 +219,78 @@ - (void)testAdInstanceManagerOnNativeAdEvents { OCMVerify([_mockMessenger sendOnChannel:channel message:clickData]); [_manager onNativeAdImpression:ad]; - NSData *impressionData = [self getDataForEvent:@"onNativeAdImpression" - adId:@1]; + NSData *impressionData = [self getDataForEvent:@"onNativeAdImpression" adId:@1]; OCMVerify([_mockMessenger sendOnChannel:channel message:impressionData]); [_manager onNativeAdWillPresentScreen:ad]; - NSData *presentScreenData = - [self getDataForEvent:@"onNativeAdWillPresentScreen" adId:@1]; + NSData *presentScreenData = [self getDataForEvent:@"onNativeAdWillPresentScreen" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:presentScreenData])); [_manager onNativeAdDidDismissScreen:ad]; - NSData *didDismissData = [self getDataForEvent:@"onNativeAdDidDismissScreen" - adId:@1]; + NSData *didDismissData = [self getDataForEvent:@"onNativeAdDidDismissScreen" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didDismissData])); [_manager onNativeAdWillDismissScreen:ad]; - NSData *willDismissData = [self getDataForEvent:@"onNativeAdWillDismissScreen" - adId:@1]; + NSData *willDismissData = [self getDataForEvent:@"onNativeAdWillDismissScreen" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:willDismissData])); } - (void)testAdInstanceManagerOnRewardedAdUserEarnedReward { - FLTRewardedAd *ad = [[FLTRewardedAd alloc] - initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager loadAd:ad]; [_manager onRewardedAdUserEarnedReward:ad - reward:[[FLTRewardItem alloc] - initWithAmount:@(1) - type:@"type"]]; + reward:[[FLTRewardItem alloc] initWithAmount:@(1) type:@"type"]]; NSData *data = [_methodCodec encodeMethodCall:[FlutterMethodCall methodCallWithMethodName:@"onAdEvent" arguments:@{ @"adId" : @1, - @"eventName" : - @"onRewardedAdUserEarnedReward", + @"eventName" : @"onRewardedAdUserEarnedReward", @"rewardItem" : - [[FLTRewardItem alloc] - initWithAmount:@(1) - type:@"type"] + [[FLTRewardItem alloc] initWithAmount:@(1) + type:@"type"] }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); } - (void)testAdInstanceManagerOnRewardedInterstitialAdUserEarnedReward { - FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] - initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + FLTRewardedInterstitialAd *ad = + [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager loadAd:ad]; [_manager onRewardedInterstitialAdUserEarnedReward:ad - reward:[[FLTRewardItem alloc] - initWithAmount:@(1) - type:@"type"]]; + reward:[[FLTRewardItem alloc] initWithAmount:@(1) + type:@"type"]]; NSData *data = [_methodCodec - encodeMethodCall: - [FlutterMethodCall - methodCallWithMethodName:@"onAdEvent" - arguments:@{ - @"adId" : @1, - @"eventName" : - @"onRewardedInterstitialAdUserEarnedReward", - @"rewardItem" : [[FLTRewardItem alloc] - initWithAmount:@(1) - type:@"type"] - }]]; + encodeMethodCall:[FlutterMethodCall + methodCallWithMethodName:@"onAdEvent" + arguments:@{ + @"adId" : @1, + @"eventName" : + @"onRewardedInterstitialAdUserEarnedReward", + @"rewardItem" : + [[FLTRewardItem alloc] initWithAmount:@(1) + type:@"type"] + }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); } - (void)testAdInstanceManagerOnPaidEvent { - FLTNativeAd *ad = [[FLTNativeAd alloc] - initWithAdUnitId:@"testAdUnitId" - request:[[FLTAdRequest alloc] init] - nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) - customOptions:nil - rootViewController:OCMClassMock([UIViewController class]) - adId:@1 - nativeAdOptions:nil - nativeTemplateStyle:nil]; + FLTNativeAd *ad = + [[FLTNativeAd alloc] initWithAdUnitId:@"testAdUnitId" + request:[[FLTAdRequest alloc] init] + nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) + customOptions:nil + rootViewController:OCMClassMock([UIViewController class]) + adId:@1 + nativeAdOptions:nil + nativeTemplateStyle:nil]; [_manager loadAd:ad]; NSDecimalNumber *valueDecimal = [[NSDecimalNumber alloc] initWithInt:1]; @@ -326,8 +306,7 @@ - (void)testAdInstanceManagerOnPaidEvent { @"adId" : @1, @"eventName" : @"onPaidEvent", @"valueMicros" : value.valueMicros, - @"precision" : - [NSNumber numberWithInteger:12], + @"precision" : [NSNumber numberWithInteger:12], @"currencyCode" : @"code" }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); @@ -335,12 +314,11 @@ - (void)testAdInstanceManagerOnPaidEvent { - (void)testBannerEvents { FLTAdSize *size = [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)]; - FLTBannerAd *ad = [[FLTBannerAd alloc] - initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@1]; + FLTBannerAd *ad = [[FLTBannerAd alloc] initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@1]; FLTBannerAd *mockBannerAd = OCMPartialMock(ad); OCMStub([mockBannerAd load]); @@ -351,86 +329,73 @@ - (void)testBannerEvents { OCMVerify(([_mockMessenger sendOnChannel:channel message:impressionData])); [_manager onBannerWillDismissScreen:ad]; - NSData *willDismissData = [self getDataForEvent:@"onBannerWillDismissScreen" - adId:@1]; + NSData *willDismissData = [self getDataForEvent:@"onBannerWillDismissScreen" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:willDismissData])); [_manager onBannerDidDismissScreen:ad]; - NSData *didDismissData = [self getDataForEvent:@"onBannerDidDismissScreen" - adId:@1]; + NSData *didDismissData = [self getDataForEvent:@"onBannerDidDismissScreen" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didDismissData])); [_manager onBannerWillPresentScreen:ad]; - NSData *willPresentData = [self getDataForEvent:@"onBannerWillPresentScreen" - adId:@1]; + NSData *willPresentData = [self getDataForEvent:@"onBannerWillPresentScreen" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:willPresentData])); } - (void)testFullScreenEventsRewardedAd { - FLTRewardedAd *rewardedAd = [[FLTRewardedAd alloc] - initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + FLTRewardedAd *rewardedAd = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager loadAd:rewardedAd]; [_manager adWillPresentFullScreenContent:rewardedAd]; - NSData *didPresentData = - [self getDataForEvent:@"adWillPresentFullScreenContent" adId:@1]; + NSData *didPresentData = [self getDataForEvent:@"adWillPresentFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didPresentData])); [_manager adDidDismissFullScreenContent:rewardedAd]; - NSData *didDismissData = - [self getDataForEvent:@"adDidDismissFullScreenContent" adId:@1]; + NSData *didDismissData = [self getDataForEvent:@"adDidDismissFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didDismissData])); [_manager adWillDismissFullScreenContent:rewardedAd]; - NSData *willDismissData = - [self getDataForEvent:@"adWillDismissFullScreenContent" adId:@1]; + NSData *willDismissData = [self getDataForEvent:@"adWillDismissFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:willDismissData])); [_manager adDidRecordImpression:rewardedAd]; - NSData *impressionData = [self getDataForEvent:@"adDidRecordImpression" - adId:@1]; + NSData *impressionData = [self getDataForEvent:@"adDidRecordImpression" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:impressionData])); } - (void)testFullScreenEventsRewardedInterstitialAd { FLTRewardedInterstitialAd *rewardedInterstitialAd = - [[FLTRewardedInterstitialAd alloc] - initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager loadAd:rewardedInterstitialAd]; [_manager adWillPresentFullScreenContent:rewardedInterstitialAd]; - NSData *didPresentData = - [self getDataForEvent:@"adWillPresentFullScreenContent" adId:@1]; + NSData *didPresentData = [self getDataForEvent:@"adWillPresentFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didPresentData])); [_manager adDidDismissFullScreenContent:rewardedInterstitialAd]; - NSData *didDismissData = - [self getDataForEvent:@"adDidDismissFullScreenContent" adId:@1]; + NSData *didDismissData = [self getDataForEvent:@"adDidDismissFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didDismissData])); [_manager adWillDismissFullScreenContent:rewardedInterstitialAd]; - NSData *willDismissData = - [self getDataForEvent:@"adWillDismissFullScreenContent" adId:@1]; + NSData *willDismissData = [self getDataForEvent:@"adWillDismissFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:willDismissData])); [_manager adDidRecordImpression:rewardedInterstitialAd]; - NSData *impressionData = [self getDataForEvent:@"adDidRecordImpression" - adId:@1]; + NSData *impressionData = [self getDataForEvent:@"adDidRecordImpression" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:impressionData])); } - (void)testEventSentForDisposedAd { FLTAdSize *size = [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)]; - FLTBannerAd *bannerAd = [[FLTBannerAd alloc] - initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@1]; + FLTBannerAd *bannerAd = + [[FLTBannerAd alloc] initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@1]; FLTBannerAd *mockBannerAd = OCMPartialMock(bannerAd); OCMStub([mockBannerAd load]); @@ -450,19 +415,16 @@ - (void)testEventSentForDisposedAd { // Helper method to create encoded data for an event and ad id. - (NSData *)getDataForEvent:(NSString *)name adId:(NSNumber *)adId { return [_methodCodec - encodeMethodCall:[FlutterMethodCall methodCallWithMethodName:@"onAdEvent" - arguments:@{ - @"adId" : @1, - @"eventName" : name - }]]; + encodeMethodCall:[FlutterMethodCall + methodCallWithMethodName:@"onAdEvent" + arguments:@{@"adId" : @1, @"eventName" : name}]]; } - (void)testAdClick { FLTRewardedInterstitialAd *rewardedInterstitialAd = - [[FLTRewardedInterstitialAd alloc] - initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager adDidRecordClick:rewardedInterstitialAd]; NSData *impressionData = [self getDataForEvent:@"adDidRecordClick" adId:@1]; diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m index 02819d7f3..6b4bf4654 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m @@ -35,12 +35,10 @@ - (void)testLoadShowInterstitialAd { GADRequest *gadRequest = OCMClassMock([GADRequest class]); OCMStub([request asGADRequest:[OCMArg any]]).andReturn(gadRequest); - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); - FLTInterstitialAd *ad = - [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); + FLTInterstitialAd *ad = [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id interstitialClassMock = OCMClassMock([GADInterstitialAd class]); @@ -63,8 +61,7 @@ - (void)testLoadShowInterstitialAd { [delegate adDidDismissFullScreenContent:interstitialClassMock]; [delegate adWillPresentFullScreenContent:interstitialClassMock]; [delegate adWillDismissFullScreenContent:interstitialClassMock]; - [delegate ad:interstitialClassMock - didFailToPresentFullScreenContentWithError:error]; + [delegate ad:interstitialClassMock didFailToPresentFullScreenContentWithError:error]; }); GADResponseInfo *mockResponseInfo = OCMClassMock([GADResponseInfo class]); @@ -75,35 +72,31 @@ - (void)testLoadShowInterstitialAd { OCMStub([adValue value]).andReturn(NSDecimalNumber.one); OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated); OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); - OCMStub([interstitialClassMock - setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - GADPaidEventHandler handler = obj; - handler(adValue); - return YES; - }]]); + OCMStub([interstitialClassMock setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + GADPaidEventHandler handler = obj; + handler(adValue); + return YES; + }]]); // Call load and verify interactions with mocks. [ad load]; - OCMVerify(ClassMethod([interstitialClassMock - loadWithAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadRequest] - completionHandler:[OCMArg any]])); + OCMVerify(ClassMethod([interstitialClassMock loadWithAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadRequest] + completionHandler:[OCMArg any]])); OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad] responseInfo:[OCMArg isEqual:mockResponseInfo]]); - OCMVerify( - [interstitialClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); + OCMVerify([interstitialClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); XCTAssertEqual(ad.interstitial, interstitialClassMock); - OCMVerify([mockManager - onPaidEvent:[OCMArg isEqual:ad] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); // Show the ad [ad showFromRootViewController:mockRootViewController]; @@ -117,9 +110,8 @@ - (void)testLoadShowInterstitialAd { OCMVerify([mockManager adWillDismissFullScreenContent:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordImpression:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:ad]]); - OCMVerify([mockManager - didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); } - (void)testFailedToLoad { @@ -128,10 +120,9 @@ - (void)testFailedToLoad { GADRequest *gadRequest = OCMClassMock([GADRequest class]); OCMStub([request asGADRequest:[OCMArg any]]).andReturn(gadRequest); - FLTInterstitialAd *ad = - [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + FLTInterstitialAd *ad = [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id interstitialClassMock = OCMClassMock([GADInterstitialAd class]); @@ -147,12 +138,10 @@ - (void)testFailedToLoad { [ad load]; - OCMVerify(ClassMethod([interstitialClassMock - loadWithAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadRequest] - completionHandler:[OCMArg any]])); - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify(ClassMethod([interstitialClassMock loadWithAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadRequest] + completionHandler:[OCMArg any]])); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m index a64936b57..d7c36cfc4 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m @@ -50,12 +50,8 @@ - (void)testLoadShowRewardedAdGAMRequest { // Helper method for testing with FLTAdRequest and FLTGAMAdRequest. - (void)testLoadShowRewardedAd:(FLTAdRequest *)request gadOrGAMRequest:(GADRequest *)gadOrGAMRequest { - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); - FLTRewardedAd *ad = - [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); + FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" request:request adId:@1]; ad.manager = mockManager; // Stub the load call to invoke successful load callback. @@ -96,12 +92,11 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request OCMStub([adValue value]).andReturn(NSDecimalNumber.one); OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated); OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); - OCMStub([rewardedClassMock - setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - GADPaidEventHandler handler = obj; - handler(adValue); - return YES; - }]]); + OCMStub([rewardedClassMock setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + GADPaidEventHandler handler = obj; + handler(adValue); + return YES; + }]]); // Setup mock for UIApplication.sharedInstance id uiApplicationClassMock = OCMClassMock([UIApplication class]); @@ -111,46 +106,40 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request // Call load and check expected interactions with mocks. [ad load]; - OCMVerify(ClassMethod([rewardedClassMock - loadWithAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadOrGAMRequest] - completionHandler:[OCMArg any]])); + OCMVerify(ClassMethod([rewardedClassMock loadWithAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadOrGAMRequest] + completionHandler:[OCMArg any]])); OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad] responseInfo:[OCMArg isEqual:responseInfo]]); - OCMVerify( - [rewardedClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); + OCMVerify([rewardedClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); XCTAssertEqual(ad.rewardedAd, rewardedClassMock); - OCMVerify([mockManager - onPaidEvent:[OCMArg isEqual:ad] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); // Set SSV and verify interactions with mocks FLTServerSideVerificationOptions *serverSideVerificationOptions = OCMClassMock([FLTServerSideVerificationOptions class]); GADServerSideVerificationOptions *gadOptions = OCMClassMock([GADServerSideVerificationOptions class]); - OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]) - .andReturn(gadOptions); + OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]).andReturn(gadOptions); [ad setServerSideVerificationOptions:serverSideVerificationOptions]; - OCMVerify([rewardedClassMock - setServerSideVerificationOptions:[OCMArg isEqual:gadOptions]]); + OCMVerify([rewardedClassMock setServerSideVerificationOptions:[OCMArg isEqual:gadOptions]]); // Show the ad and verify callbacks invoked [ad showFromRootViewController:mockRootViewController]; - OCMVerify([rewardedClassMock - presentFromRootViewController:[OCMArg isEqual:mockRootViewController] - userDidEarnRewardHandler:[OCMArg any]]); + OCMVerify([rewardedClassMock presentFromRootViewController:[OCMArg isEqual:mockRootViewController] + userDidEarnRewardHandler:[OCMArg any]]); [fullScreenContentDelegate adWillPresentFullScreenContent:rewardedClassMock]; OCMVerify([mockManager adWillPresentFullScreenContent:[OCMArg isEqual:ad]]); @@ -177,19 +166,17 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request #pragma clang diagnostic pop [ad ad:rewardedClassMock didFailToPresentFullScreenContentWithError:error]; - OCMVerify([mockManager - didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); // Verify reward callback. - OCMVerify([mockManager - onRewardedAdUserEarnedReward:[OCMArg isEqual:ad] - reward:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTRewardItem *reward = (FLTRewardItem *)obj; - XCTAssertEqual(reward.amount, @1.0); - XCTAssertEqual(reward.type, @"type"); - return true; - }]]); + OCMVerify([mockManager onRewardedAdUserEarnedReward:[OCMArg isEqual:ad] + reward:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTRewardItem *reward = (FLTRewardItem *)obj; + XCTAssertEqual(reward.amount, @1.0); + XCTAssertEqual(reward.type, @"type"); + return true; + }]]); // Explicitly stop mocking. There is an issue when running tests on Github // actions where the mock does not get deallocated properly, so without this @@ -215,10 +202,7 @@ - (void)testFailedToLoadGAMRequest { // Helper for testing failed to load. - (void)testFailedToLoad:(FLTAdRequest *)request { - FLTRewardedAd *ad = - [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" request:request adId:@1]; ad.manager = mockManager; id rewardedClassMock = OCMClassMock([GADRewardedAd class]); @@ -237,8 +221,7 @@ - (void)testFailedToLoad:(FLTAdRequest *)request { OCMVerify(ClassMethod([rewardedClassMock loadWithAdUnitID:[OCMArg any] request:[OCMArg any] completionHandler:[OCMArg any]])); - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m index 261a9e049..a732ef9b8 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m @@ -50,31 +50,25 @@ - (void)testLoadShowRewardedInterstitialAdGAMRequest { // Helper method for testing with FLTAdRequest and FLTGAMAdRequest. - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request gadOrGAMRequest:(GADRequest *)gadOrGAMRequest { - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); - FLTRewardedInterstitialAd *ad = - [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); + FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; // Stub the load call to invoke successful load callback. - id rewardedInterstitialClassMock = - OCMClassMock([GADRewardedInterstitialAd class]); - OCMStub(ClassMethod([rewardedInterstitialClassMock - loadWithAdUnitID:[OCMArg any] - request:[OCMArg any] - completionHandler:[OCMArg any]])) + id rewardedInterstitialClassMock = OCMClassMock([GADRewardedInterstitialAd class]); + OCMStub(ClassMethod([rewardedInterstitialClassMock loadWithAdUnitID:[OCMArg any] + request:[OCMArg any] + completionHandler:[OCMArg any]])) .andDo(^(NSInvocation *invocation) { - void (^completionHandler)(GADRewardedInterstitialAd *ad, - NSError *error); + void (^completionHandler)(GADRewardedInterstitialAd *ad, NSError *error); [invocation getArgument:&completionHandler atIndex:4]; completionHandler(rewardedInterstitialClassMock, nil); }); // Stub setting of FullScreenContentDelegate to invoke delegate callbacks. NSError *error = OCMClassMock([NSError class]); - OCMStub( - [rewardedInterstitialClassMock setFullScreenContentDelegate:[OCMArg any]]) + OCMStub([rewardedInterstitialClassMock setFullScreenContentDelegate:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { id delegate; [invocation getArgument:&delegate atIndex:2]; @@ -94,9 +88,8 @@ - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request OCMStub([mockReward amount]).andReturn(@1.0); OCMStub([mockReward type]).andReturn(@"type"); OCMStub([rewardedInterstitialClassMock adReward]).andReturn(mockReward); - OCMStub([rewardedInterstitialClassMock - presentFromRootViewController:[OCMArg any] - userDidEarnRewardHandler:[OCMArg any]]) + OCMStub([rewardedInterstitialClassMock presentFromRootViewController:[OCMArg any] + userDidEarnRewardHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { GADUserDidEarnRewardHandler rewardHandler; [invocation getArgument:&rewardHandler atIndex:3]; @@ -108,47 +101,43 @@ - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request OCMStub([adValue value]).andReturn(NSDecimalNumber.one); OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated); OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); - OCMStub([rewardedInterstitialClassMock - setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - GADPaidEventHandler handler = obj; - handler(adValue); - return YES; - }]]); + OCMStub([rewardedInterstitialClassMock setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + GADPaidEventHandler handler = obj; + handler(adValue); + return YES; + }]]); // Call load and check expected interactions with mocks. [ad load]; - OCMVerify(ClassMethod([rewardedInterstitialClassMock - loadWithAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadOrGAMRequest] - completionHandler:[OCMArg any]])); + OCMVerify( + ClassMethod([rewardedInterstitialClassMock loadWithAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadOrGAMRequest] + completionHandler:[OCMArg any]])); OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad] responseInfo:[OCMArg isEqual:responseInfo]]); - OCMVerify([rewardedInterstitialClassMock - setFullScreenContentDelegate:[OCMArg isEqual:ad]]); - OCMVerify([mockManager - onPaidEvent:[OCMArg isEqual:ad] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([rewardedInterstitialClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); + OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); // Set SSV and verify interactions with mocks FLTServerSideVerificationOptions *serverSideVerificationOptions = OCMClassMock([FLTServerSideVerificationOptions class]); GADServerSideVerificationOptions *gadOptions = OCMClassMock([GADServerSideVerificationOptions class]); - OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]) - .andReturn(gadOptions); + OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]).andReturn(gadOptions); [ad setServerSideVerificationOptions:serverSideVerificationOptions]; - OCMVerify([rewardedInterstitialClassMock - setServerSideVerificationOptions:[OCMArg isEqual:gadOptions]]); + OCMVerify( + [rewardedInterstitialClassMock setServerSideVerificationOptions:[OCMArg isEqual:gadOptions]]); // Show the ad and verify callbacks are invoked [ad showFromRootViewController:mockRootViewController]; @@ -163,17 +152,14 @@ - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request OCMVerify([mockManager adWillDismissFullScreenContent:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordImpression:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:ad]]); - OCMVerify([mockManager - didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); // Verify reward callback. OCMVerify([mockManager onRewardedInterstitialAdUserEarnedReward:[OCMArg isEqual:ad] - reward:[OCMArg checkWithBlock:^BOOL( - id obj) { - FLTRewardItem *reward = - (FLTRewardItem *)obj; + reward:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTRewardItem *reward = (FLTRewardItem *)obj; XCTAssertEqual(reward.amount, @1.0); XCTAssertEqual(reward.type, @"type"); return true; @@ -201,34 +187,28 @@ - (void)testFailedToLoadGAMRequest { // Helper for testing failed to load. - (void)testFailedToLoad:(FLTAdRequest *)request { - FLTRewardedInterstitialAd *ad = - [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; - id rewardedInterstitialClassMock = - OCMClassMock([GADRewardedInterstitialAd class]); + id rewardedInterstitialClassMock = OCMClassMock([GADRewardedInterstitialAd class]); NSError *error = OCMClassMock([NSError class]); - OCMStub(ClassMethod([rewardedInterstitialClassMock - loadWithAdUnitID:[OCMArg any] - request:[OCMArg any] - completionHandler:[OCMArg any]])) + OCMStub(ClassMethod([rewardedInterstitialClassMock loadWithAdUnitID:[OCMArg any] + request:[OCMArg any] + completionHandler:[OCMArg any]])) .andDo(^(NSInvocation *invocation) { - void (^completionHandler)(GADRewardedInterstitialAd *ad, - NSError *error); + void (^completionHandler)(GADRewardedInterstitialAd *ad, NSError *error); [invocation getArgument:&completionHandler atIndex:4]; completionHandler(nil, error); }); [ad load]; - OCMVerify(ClassMethod([rewardedInterstitialClassMock - loadWithAdUnitID:[OCMArg any] - request:[OCMArg any] - completionHandler:[OCMArg any]])); - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify(ClassMethod([rewardedInterstitialClassMock loadWithAdUnitID:[OCMArg any] + request:[OCMArg any] + completionHandler:[OCMArg any]])); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]); } @end diff --git a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h index 1ddf4096e..2f3662c9e 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h +++ b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. +#import #import "FLTAd_Internal.h" #import "FLTGoogleMobileAdsCollection_Internal.h" #import "FLTGoogleMobileAdsReaderWriter_Internal.h" -#import @protocol FLTAd; @class FLTBannerAd; @@ -33,9 +33,8 @@ - (void)loadAd:(id _Nonnull)ad; - (void)dispose:(NSNumber *_Nonnull)adId; - (void)showAdWithID:(NSNumber *_Nonnull)adId - rootViewController:(UIViewController *_Nonnull)rootViewController; -- (void)onAdLoaded:(id _Nonnull)ad - responseInfo:(GADResponseInfo *_Nonnull)responseInfo; + rootViewController:(UIViewController *_Nonnull)rootViewController; +- (void)onAdLoaded:(id _Nonnull)ad responseInfo:(GADResponseInfo *_Nonnull)responseInfo; - (void)onAdFailedToLoad:(id _Nonnull)ad error:(NSError *_Nonnull)error; - (void)onAppEvent:(id _Nonnull)ad name:(NSString *_Nullable)name @@ -46,10 +45,8 @@ - (void)onNativeAdWillDismissScreen:(FLTNativeAd *_Nonnull)ad; - (void)onRewardedAdUserEarnedReward:(FLTRewardedAd *_Nonnull)ad reward:(FLTRewardItem *_Nonnull)reward; -- (void)onRewardedInterstitialAdUserEarnedReward: - (FLTRewardedInterstitialAd *_Nonnull)ad - reward: - (FLTRewardItem *_Nonnull)reward; +- (void)onRewardedInterstitialAdUserEarnedReward:(FLTRewardedInterstitialAd *_Nonnull)ad + reward:(FLTRewardItem *_Nonnull)reward; - (void)onPaidEvent:(id _Nonnull)ad value:(FLTAdValue *_Nonnull)value; - (void)onBannerImpression:(FLTBannerAd *_Nonnull)ad; - (void)onBannerWillDismissScreen:(FLTBannerAd *_Nonnull)ad; @@ -67,9 +64,7 @@ - (void)disposeAllAds; @end -@interface FLTNewGoogleMobileAdsViewFactory - : NSObject +@interface FLTNewGoogleMobileAdsViewFactory : NSObject @property(readonly) FLTAdInstanceManager *_Nonnull manager; -- (instancetype _Nonnull)initWithManager: - (FLTAdInstanceManager *_Nonnull)manager; +- (instancetype _Nonnull)initWithManager:(FLTAdInstanceManager *_Nonnull)manager; @end diff --git a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m index 2ec069c95..e384dc1dd 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m @@ -26,10 +26,9 @@ - (instancetype _Nonnull)initWithBinaryMessenger: _ads = [[FLTGoogleMobileAdsCollection alloc] init]; NSObject *methodCodec = [FlutterStandardMethodCodec codecWithReaderWriter:[[FLTGoogleMobileAdsReaderWriter alloc] init]]; - _channel = [[FlutterMethodChannel alloc] - initWithName:@"plugins.flutter.io/google_mobile_ads" - binaryMessenger:binaryMessenger - codec:methodCodec]; + _channel = [[FlutterMethodChannel alloc] initWithName:@"plugins.flutter.io/google_mobile_ads" + binaryMessenger:binaryMessenger + codec:methodCodec]; } return self; } @@ -68,7 +67,7 @@ - (void)disposeAllAds { } - (void)showAdWithID:(NSNumber *_Nonnull)adId - rootViewController:(UIViewController *_Nonnull)rootViewController{ + rootViewController:(UIViewController *_Nonnull)rootViewController { id ad = (id)[self adFor:adId]; if (!ad) { @@ -79,14 +78,12 @@ - (void)showAdWithID:(NSNumber *_Nonnull)adId [ad showFromRootViewController:rootViewController]; } -- (void)onAdLoaded:(id _Nonnull)ad - responseInfo:(GADResponseInfo *_Nonnull)responseInfo { +- (void)onAdLoaded:(id _Nonnull)ad responseInfo:(GADResponseInfo *_Nonnull)responseInfo { [_channel invokeMethod:@"onAdEvent" arguments:@{ @"adId" : ad.adId, @"eventName" : @"onAdLoaded", - @"responseInfo" : [[FLTGADResponseInfo alloc] - initWithResponseInfo:responseInfo] + @"responseInfo" : [[FLTGADResponseInfo alloc] initWithResponseInfo:responseInfo] }]; } @@ -99,9 +96,7 @@ - (void)onAdFailedToLoad:(id _Nonnull)ad error:(NSError *_Nonnull)error { }]; } -- (void)onAppEvent:(id _Nonnull)ad - name:(NSString *)name - data:(NSString *)data { +- (void)onAppEvent:(id _Nonnull)ad name:(NSString *)name data:(NSString *)data { [_channel invokeMethod:@"onAdEvent" arguments:@{ @"adId" : ad.adId, @@ -137,10 +132,8 @@ - (void)onRewardedAdUserEarnedReward:(FLTRewardedAd *_Nonnull)ad }]; } -- (void)onRewardedInterstitialAdUserEarnedReward: - (FLTRewardedInterstitialAd *_Nonnull)ad - reward: - (FLTRewardItem *_Nonnull)reward { +- (void)onRewardedInterstitialAdUserEarnedReward:(FLTRewardedInterstitialAd *_Nonnull)ad + reward:(FLTRewardItem *_Nonnull)reward { [_channel invokeMethod:@"onAdEvent" arguments:@{ @"adId" : ad.adId, @@ -239,17 +232,12 @@ - (instancetype)initWithManager:(FLTAdInstanceManager *_Nonnull)manager { viewIdentifier:(int64_t)viewId arguments:(id _Nullable)args { NSNumber *adId = args; - NSObject *view = - (NSObject *)[_manager adFor:adId]; + NSObject *view = (NSObject *)[_manager adFor:adId]; if (!view) { NSString *reason = [NSString - stringWithFormat: - @"Could not find an ad with id: %@. Was this ad already disposed?", - adId]; - @throw [NSException exceptionWithName:NSInvalidArgumentException - reason:reason - userInfo:nil]; + stringWithFormat:@"Could not find an ad with id: %@. Was this ad already disposed?", adId]; + @throw [NSException exceptionWithName:NSInvalidArgumentException reason:reason userInfo:nil]; } return view; } diff --git a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h index 2f3264a56..09e571ee3 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h +++ b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#import +#import #import "FLTAdInstanceManager_Internal.h" #import "FLTGoogleMobileAdsPlugin.h" #import "FLTMediationExtras.h" @@ -19,8 +21,6 @@ #import "FLTMobileAds_Internal.h" #import "FLTNativeTemplateStyle.h" #import "GADTTemplateView.h" -#import -#import @class FLTAdInstanceManager; @protocol FLTNativeAdFactory; @@ -29,8 +29,7 @@ @property(readonly) GADAdSize size; @property(readonly) NSNumber *_Nonnull width; @property(readonly) NSNumber *_Nonnull height; -- (instancetype _Nonnull)initWithWidth:(NSNumber *_Nonnull)width - height:(NSNumber *_Nonnull)height; +- (instancetype _Nonnull)initWithWidth:(NSNumber *_Nonnull)width height:(NSNumber *_Nonnull)height; - (instancetype _Nonnull)initWithAdSize:(GADAdSize)size; @end @@ -39,22 +38,14 @@ * Plugin. */ @interface FLTAdSizeFactory : NSObject -- (GADAdSize)portraitAnchoredAdaptiveBannerAdSizeWithWidth: - (NSNumber *_Nonnull)width; -- (GADAdSize)landscapeAnchoredAdaptiveBannerAdSizeWithWidth: - (NSNumber *_Nonnull)width; -- (GADAdSize)currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth: - (NSNumber *_Nonnull)width; -- (GADAdSize)currentOrientationInlineAdaptiveBannerSizeWithWidth: - (NSNumber *_Nonnull)width; -- (GADAdSize)portraitOrientationInlineAdaptiveBannerSizeWithWidth: - (NSNumber *_Nonnull)width; -- (GADAdSize)landscapeInlineAdaptiveBannerAdSizeWithWidth: - (NSNumber *_Nonnull)width; -- (GADAdSize) - inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:(NSNumber *_Nonnull)width - maxHeight: - (NSNumber *_Nonnull)maxHeight; +- (GADAdSize)portraitAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width; +- (GADAdSize)landscapeAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width; +- (GADAdSize)currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width; +- (GADAdSize)currentOrientationInlineAdaptiveBannerSizeWithWidth:(NSNumber *_Nonnull)width; +- (GADAdSize)portraitOrientationInlineAdaptiveBannerSizeWithWidth:(NSNumber *_Nonnull)width; +- (GADAdSize)landscapeInlineAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width; +- (GADAdSize)inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:(NSNumber *_Nonnull)width + maxHeight:(NSNumber *_Nonnull)maxHeight; @end @@ -87,10 +78,9 @@ @property NSString *_Nullable contentURL; @property BOOL nonPersonalizedAds; @property NSArray *_Nullable neighboringContentURLs; -@property NSString *_Nullable mediationExtrasIdentifier - DEPRECATED_MSG_ATTRIBUTE("Use mediationExtras instead."); -@property id< - FLTMediationNetworkExtrasProvider> _Nullable mediationNetworkExtrasProvider +@property NSString *_Nullable mediationExtrasIdentifier DEPRECATED_MSG_ATTRIBUTE( + "Use mediationExtras instead."); +@property id _Nullable mediationNetworkExtrasProvider DEPRECATED_MSG_ATTRIBUTE("Use mediationExtras instead."); @property NSDictionary *_Nullable adMobExtras; @property NSString *_Nonnull requestAgent; @@ -114,8 +104,7 @@ @property NSString *_Nullable adSourceName; @property NSString *_Nullable adSourceInstanceName; -- (instancetype _Nonnull)initWithResponseInfo: - (GADAdNetworkResponseInfo *_Nonnull)responseInfo; +- (instancetype _Nonnull)initWithResponseInfo:(GADAdNetworkResponseInfo *_Nonnull)responseInfo; @end /** @@ -128,8 +117,7 @@ @property FLTGADAdNetworkResponseInfo *_Nullable loadedAdNetworkResponseInfo; @property NSDictionary *_Nullable extrasDictionary; -- (instancetype _Nonnull)initWithResponseInfo: - (GADResponseInfo *_Nonnull)responseInfo; +- (instancetype _Nonnull)initWithResponseInfo:(GADResponseInfo *_Nonnull)responseInfo; @end /** @@ -150,8 +138,7 @@ */ @interface FLTGAMAdRequest : FLTAdRequest @property NSDictionary *_Nullable customTargeting; -@property NSDictionary *> - *_Nullable customTargetingLists; +@property NSDictionary *> *_Nullable customTargetingLists; @property NSString *_Nullable pubProvidedID; - (GAMRequest *_Nonnull)asGAMRequest:(NSString *_Nonnull)adUnitId; @@ -171,13 +158,11 @@ @property(readonly) NSNumber *_Nonnull adId; @end -@interface FLTBannerAd - : FLTBaseAd +@interface FLTBannerAd : FLTBaseAd - (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId size:(FLTAdSize *_Nonnull)size request:(FLTAdRequest *_Nonnull)request - rootViewController: - (UIViewController *_Nonnull)rootViewController + rootViewController:(UIViewController *_Nonnull)rootViewController adId:(NSNumber *_Nonnull)adId; - (FLTAdSize *_Nullable)getAdSize; - (GADBannerView *_Nonnull)bannerView; @@ -190,8 +175,7 @@ - (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId sizes:(NSArray *_Nonnull)sizes request:(FLTGAMAdRequest *_Nonnull)request - rootViewController: - (UIViewController *_Nonnull)rootViewController + rootViewController:(UIViewController *_Nonnull)rootViewController adId:(NSNumber *_Nonnull)adId; @end @@ -202,13 +186,11 @@ @interface FLTFluidGAMBannerAd : FLTGAMBannerAd - (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId request:(FLTGAMAdRequest *_Nonnull)request - rootViewController: - (UIViewController *_Nonnull)rootViewController + rootViewController:(UIViewController *_Nonnull)rootViewController adId:(NSNumber *_Nonnull)adId; @end -@interface FLTFullScreenAd - : FLTBaseAd +@interface FLTFullScreenAd : FLTBaseAd @end @interface FLTInterstitialAd : FLTFullScreenAd @@ -256,10 +238,9 @@ @property(readonly) NSNumber *_Nullable clickToExpandRequested; @property(readonly) NSNumber *_Nullable customControlsRequested; @property(readonly) NSNumber *_Nullable startMuted; -- (instancetype _Nonnull) - initWithClickToExpandRequested:(NSNumber *_Nullable)clickToExpandRequested - customControlsRequested:(NSNumber *_Nullable)customControlsRequested - startMuted:(NSNumber *_Nullable)startMuted; +- (instancetype _Nonnull)initWithClickToExpandRequested:(NSNumber *_Nullable)clickToExpandRequested + customControlsRequested:(NSNumber *_Nullable)customControlsRequested + startMuted:(NSNumber *_Nullable)startMuted; - (GADVideoOptions *_Nonnull)asGADVideoOptions; @end @@ -272,39 +253,34 @@ @property(readonly) NSNumber *_Nullable shouldRequestMultipleImages; @property(readonly) NSNumber *_Nullable shouldReturnUrlsForImageAssets; -- (instancetype _Nonnull) - initWithAdChoicesPlacement:(NSNumber *_Nullable)adChoicesPlacement - mediaAspectRatio:(NSNumber *_Nullable)mediaAspectRatio - videoOptions:(FLTVideoOptions *_Nullable)videoOptions - requestCustomMuteThisAd:(NSNumber *_Nullable)requestCustomMuteThisAd - shouldRequestMultipleImages: - (NSNumber *_Nullable)shouldRequestMultipleImages - shouldReturnUrlsForImageAssets: - (NSNumber *_Nullable)shouldReturnUrlsForImageAssets; +- (instancetype _Nonnull)initWithAdChoicesPlacement:(NSNumber *_Nullable)adChoicesPlacement + mediaAspectRatio:(NSNumber *_Nullable)mediaAspectRatio + videoOptions:(FLTVideoOptions *_Nullable)videoOptions + requestCustomMuteThisAd:(NSNumber *_Nullable)requestCustomMuteThisAd + shouldRequestMultipleImages:(NSNumber *_Nullable)shouldRequestMultipleImages + shouldReturnUrlsForImageAssets: + (NSNumber *_Nullable)shouldReturnUrlsForImageAssets; - (NSArray *_Nonnull)asGADAdLoaderOptions; @end @interface FLTNativeAd - : FLTBaseAd -- (instancetype _Nonnull) - initWithAdUnitId:(NSString *_Nonnull)adUnitId - request:(FLTAdRequest *_Nonnull)request - nativeAdFactory:(NSObject *_Nonnull)nativeAdFactory - customOptions:(NSDictionary *_Nullable)customOptions - rootViewController:(UIViewController *_Nonnull)rootViewController - adId:(NSNumber *_Nonnull)adId - nativeAdOptions:(FLTNativeAdOptions *_Nullable)nativeAdOptions - nativeTemplateStyle:(FLTNativeTemplateStyle *_Nullable)nativeTemplateStyle; + : FLTBaseAd +- (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId + request:(FLTAdRequest *_Nonnull)request + nativeAdFactory:(NSObject *_Nonnull)nativeAdFactory + customOptions:(NSDictionary *_Nullable)customOptions + rootViewController:(UIViewController *_Nonnull)rootViewController + adId:(NSNumber *_Nonnull)adId + nativeAdOptions:(FLTNativeAdOptions *_Nullable)nativeAdOptions + nativeTemplateStyle:(FLTNativeTemplateStyle *_Nullable)nativeTemplateStyle; - (GADAdLoader *_Nonnull)adLoader; @end @interface FLTRewardItem : NSObject @property(readonly) NSNumber *_Nonnull amount; @property(readonly) NSString *_Nonnull type; -- (instancetype _Nonnull)initWithAmount:(NSNumber *_Nonnull)amount - type:(NSString *_Nonnull)type; +- (instancetype _Nonnull)initWithAmount:(NSNumber *_Nonnull)amount type:(NSString *_Nonnull)type; @end @interface FLTAdValue : NSObject diff --git a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m index 12ae3348a..a2c2d36ea 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m @@ -17,10 +17,9 @@ #import "FLTNativeTemplateStyle.h" @implementation FLTAdSize -- (instancetype _Nonnull)initWithWidth:(NSNumber *_Nonnull)width - height:(NSNumber *_Nonnull)height { - return [self initWithAdSize:GADAdSizeFromCGSize(CGSizeMake( - width.doubleValue, height.doubleValue))]; +- (instancetype _Nonnull)initWithWidth:(NSNumber *_Nonnull)width height:(NSNumber *_Nonnull)height { + return + [self initWithAdSize:GADAdSizeFromCGSize(CGSizeMake(width.doubleValue, height.doubleValue))]; } - (instancetype _Nonnull)initWithAdSize:(GADAdSize)size { @@ -35,42 +34,31 @@ - (instancetype _Nonnull)initWithAdSize:(GADAdSize)size { @end @implementation FLTAdSizeFactory -- (GADAdSize)portraitAnchoredAdaptiveBannerAdSizeWithWidth: - (NSNumber *_Nonnull)width { +- (GADAdSize)portraitAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width { return GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth(width.doubleValue); } -- (GADAdSize)landscapeAnchoredAdaptiveBannerAdSizeWithWidth: - (NSNumber *_Nonnull)width { +- (GADAdSize)landscapeAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width { return GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth(width.doubleValue); } -- (GADAdSize)currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth: - (NSNumber *_Nonnull)width { - return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth( - width.doubleValue); +- (GADAdSize)currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width { + return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(width.doubleValue); } -- (GADAdSize)currentOrientationInlineAdaptiveBannerSizeWithWidth: - (NSNumber *_Nonnull)width { - return GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth( - width.floatValue); +- (GADAdSize)currentOrientationInlineAdaptiveBannerSizeWithWidth:(NSNumber *_Nonnull)width { + return GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(width.floatValue); } -- (GADAdSize)portraitOrientationInlineAdaptiveBannerSizeWithWidth: - (NSNumber *_Nonnull)width { +- (GADAdSize)portraitOrientationInlineAdaptiveBannerSizeWithWidth:(NSNumber *_Nonnull)width { return GADPortraitInlineAdaptiveBannerAdSizeWithWidth(width.floatValue); } -- (GADAdSize)landscapeInlineAdaptiveBannerAdSizeWithWidth: - (NSNumber *_Nonnull)width { +- (GADAdSize)landscapeInlineAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width { return GADLandscapeInlineAdaptiveBannerAdSizeWithWidth(width.floatValue); } -- (GADAdSize) - inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:(NSNumber *_Nonnull)width - maxHeight: - (NSNumber *_Nonnull)maxHeight { - return GADInlineAdaptiveBannerAdSizeWithWidthAndMaxHeight( - width.floatValue, maxHeight.floatValue); +- (GADAdSize)inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:(NSNumber *_Nonnull)width + maxHeight:(NSNumber *_Nonnull)maxHeight { + return GADInlineAdaptiveBannerAdSizeWithWidthAndMaxHeight(width.floatValue, maxHeight.floatValue); } @end @@ -81,8 +69,7 @@ - (instancetype _Nonnull)initWithFactory:(FLTAdSizeFactory *_Nonnull)factory width:(NSNumber *_Nonnull)width { GADAdSize size; if ([FLTAdUtil isNull:orientation]) { - size = - [factory currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:width]; + size = [factory currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:width]; } else if ([orientation isEqualToString:@"portrait"]) { size = [factory portraitAnchoredAdaptiveBannerAdSizeWithWidth:width]; } else if ([orientation isEqualToString:@"landscape"]) { @@ -107,18 +94,13 @@ - (instancetype _Nonnull)initWithFactory:(FLTAdSizeFactory *_Nonnull)factory orientation:(NSNumber *_Nullable)orientation { GADAdSize gadAdSize; if ([FLTAdUtil isNotNull:orientation]) { - gadAdSize = - orientation.intValue == 0 - ? [factory - portraitOrientationInlineAdaptiveBannerSizeWithWidth:width] - : [factory landscapeInlineAdaptiveBannerAdSizeWithWidth:width]; + gadAdSize = orientation.intValue == 0 + ? [factory portraitOrientationInlineAdaptiveBannerSizeWithWidth:width] + : [factory landscapeInlineAdaptiveBannerAdSizeWithWidth:width]; } else if ([FLTAdUtil isNotNull:maxHeight]) { - gadAdSize = - [factory inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:width - maxHeight:maxHeight]; + gadAdSize = [factory inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:width maxHeight:maxHeight]; } else { - gadAdSize = - [factory currentOrientationInlineAdaptiveBannerSizeWithWidth:width]; + gadAdSize = [factory currentOrientationInlineAdaptiveBannerSizeWithWidth:width]; } self = [self initWithAdSize:gadAdSize]; if (self) { @@ -140,8 +122,7 @@ - (instancetype _Nonnull)initWithOrientation:(NSString *_Nonnull)orientation { size = kGADAdSizeSmartBannerLandscape; #pragma clang diagnostic pop } else { - NSLog(@"SmartBanner orientation should be 'portrait' or 'landscape': %@", - orientation); + NSLog(@"SmartBanner orientation should be 'portrait' or 'landscape': %@", orientation); return nil; } @@ -169,21 +150,18 @@ - (void)addNetworkExtrasToGADRequest:(GADRequest *_Nonnull)request @implementation FLTAdRequest -- (void)addNetworkExtrasToGADRequest:(GADRequest *)request - adUnitId:(NSString *_Nonnull)adUnitId { +- (void)addNetworkExtrasToGADRequest:(GADRequest *)request adUnitId:(NSString *_Nonnull)adUnitId { NSArray> *extras; if (_mediationExtras != NULL) { - NSMutableArray> *flutterExtras = - [NSMutableArray array]; + NSMutableArray> *flutterExtras = [NSMutableArray array]; for (id extra in _mediationExtras) { [flutterExtras addObject:[extra getMediationExtras]]; } extras = [NSArray arrayWithArray:flutterExtras]; } else { - extras = [_mediationNetworkExtrasProvider - getMediationExtras:adUnitId - mediationExtrasIdentifier:_mediationExtrasIdentifier]; + extras = [_mediationNetworkExtrasProvider getMediationExtras:adUnitId + mediationExtrasIdentifier:_mediationExtrasIdentifier]; } BOOL addedNpaToGADExtras = false; @@ -192,8 +170,8 @@ - (void)addNetworkExtrasToGADRequest:(GADRequest *)request // If GADExtras are present and npa is true, add npa = 1 to the GADExtras if ([extra isKindOfClass:[GADExtras class]] && _nonPersonalizedAds) { GADExtras *gadExtras = (GADExtras *)extra; - NSMutableDictionary *newParams = [[NSMutableDictionary alloc] - initWithDictionary:gadExtras.additionalParameters]; + NSMutableDictionary *newParams = + [[NSMutableDictionary alloc] initWithDictionary:gadExtras.additionalParameters]; newParams[@"npa"] = @"1"; gadExtras.additionalParameters = newParams; [request registerAdNetworkExtras:gadExtras]; @@ -240,25 +218,20 @@ - (GADRequest *_Nonnull)asGADRequest:(NSString *_Nonnull)adUnitId { @implementation FLTGADResponseInfo -- (instancetype _Nonnull)initWithResponseInfo: - (GADResponseInfo *_Nonnull)responseInfo { +- (instancetype _Nonnull)initWithResponseInfo:(GADResponseInfo *_Nonnull)responseInfo { self = [super init]; if (self) { _responseIdentifier = responseInfo.responseIdentifier; - _adNetworkClassName = - responseInfo.loadedAdNetworkResponseInfo.adNetworkClassName; - NSMutableArray *infoArray = - [[NSMutableArray alloc] init]; - for (GADAdNetworkResponseInfo *adNetworkInfo in responseInfo - .adNetworkInfoArray) { - [infoArray addObject:[[FLTGADAdNetworkResponseInfo alloc] - initWithResponseInfo:adNetworkInfo]]; + _adNetworkClassName = responseInfo.loadedAdNetworkResponseInfo.adNetworkClassName; + NSMutableArray *infoArray = [[NSMutableArray alloc] init]; + for (GADAdNetworkResponseInfo *adNetworkInfo in responseInfo.adNetworkInfoArray) { + [infoArray + addObject:[[FLTGADAdNetworkResponseInfo alloc] initWithResponseInfo:adNetworkInfo]]; } _adNetworkInfoArray = infoArray; _loadedAdNetworkResponseInfo = [[FLTGADAdNetworkResponseInfo alloc] initWithResponseInfo:responseInfo.loadedAdNetworkResponseInfo]; - _extrasDictionary = - responseInfo.extrasDictionary ? responseInfo.extrasDictionary : @{}; + _extrasDictionary = responseInfo.extrasDictionary ? responseInfo.extrasDictionary : @{}; } return self; } @@ -266,13 +239,11 @@ - (instancetype _Nonnull)initWithResponseInfo: @implementation FLTGADAdNetworkResponseInfo -- (instancetype _Nonnull)initWithResponseInfo: - (GADAdNetworkResponseInfo *_Nonnull)responseInfo { +- (instancetype _Nonnull)initWithResponseInfo:(GADAdNetworkResponseInfo *_Nonnull)responseInfo { self = [super init]; if (self) { _adNetworkClassName = responseInfo.adNetworkClassName; - NSNumber *timeInMillis = - [[NSNumber alloc] initWithDouble:responseInfo.latency * 1000]; + NSNumber *timeInMillis = [[NSNumber alloc] initWithDouble:responseInfo.latency * 1000]; _latency = @(timeInMillis.longValue); _dictionaryDescription = responseInfo.dictionaryRepresentation.description; _adUnitMapping = [[NSMutableDictionary alloc] init]; @@ -303,11 +274,9 @@ - (instancetype _Nonnull)initWithError:(NSError *_Nonnull)error { _code = error.code; _domain = error.domain; _message = error.localizedDescription; - GADResponseInfo *responseInfo = - error.userInfo[GADErrorUserInfoKeyResponseInfo]; + GADResponseInfo *responseInfo = error.userInfo[GADErrorUserInfoKeyResponseInfo]; if (responseInfo) { - _responseInfo = - [[FLTGADResponseInfo alloc] initWithResponseInfo:responseInfo]; + _responseInfo = [[FLTGADResponseInfo alloc] initWithResponseInfo:responseInfo]; } } return self; @@ -328,8 +297,7 @@ - (GADRequest *_Nonnull)asGAMRequest:(NSString *_Nonnull)adUnitId { NSMutableDictionary *targetingDictionary = [NSMutableDictionary dictionaryWithDictionary:self.customTargeting]; for (NSString *key in self.customTargetingLists) { - targetingDictionary[key] = - [self.customTargetingLists[key] componentsJoinedByString:@","]; + targetingDictionary[key] = [self.customTargetingLists[key] componentsJoinedByString:@","]; } request.customTargeting = targetingDictionary; [self addNetworkExtrasToGADRequest:request adUnitId:adUnitId]; @@ -374,10 +342,9 @@ - (instancetype)initWithAdUnitId:(NSString *_Nonnull)adUnitId return; } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] - initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; } return self; @@ -405,8 +372,7 @@ - (void)bannerViewDidReceiveAd:(GADBannerView *)bannerView { [manager onAdLoaded:self responseInfo:bannerView.responseInfo]; } -- (void)bannerView:(GADBannerView *)bannerView - didFailToReceiveAdWithError:(NSError *)error { +- (void)bannerView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(NSError *)error { [manager onAdFailedToLoad:self error:error]; } @@ -462,8 +428,7 @@ - (instancetype)initWithAdUnitId:(NSString *_Nonnull)adUnitId _bannerView.appEventDelegate = self; _bannerView.delegate = self; - NSMutableArray *validAdSizes = - [NSMutableArray arrayWithCapacity:sizes.count]; + NSMutableArray *validAdSizes = [NSMutableArray arrayWithCapacity:sizes.count]; for (FLTAdSize *size in sizes) { [validAdSizes addObject:NSValueFromGADAdSize(size.size)]; } @@ -475,10 +440,9 @@ - (instancetype)initWithAdUnitId:(NSString *_Nonnull)adUnitId return; } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] - initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; } return self; @@ -540,10 +504,9 @@ - (instancetype)initWithAdUnitId:(NSString *_Nonnull)adUnitId return; } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] - initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; } return self; @@ -570,27 +533,23 @@ - (nonnull UIView *)view { [scrollView addSubview:_bannerView]; _bannerView.translatesAutoresizingMaskIntoConstraints = false; - NSLayoutConstraint *width = - [NSLayoutConstraint constraintWithItem:_bannerView - attribute:NSLayoutAttributeWidth - relatedBy:0 - toItem:scrollView - attribute:NSLayoutAttributeWidth - multiplier:1.0 - constant:0]; + NSLayoutConstraint *width = [NSLayoutConstraint constraintWithItem:_bannerView + attribute:NSLayoutAttributeWidth + relatedBy:0 + toItem:scrollView + attribute:NSLayoutAttributeWidth + multiplier:1.0 + constant:0]; [scrollView addConstraint:width]; _containerView = scrollView; - [_bannerView.widthAnchor constraintEqualToAnchor:scrollView.widthAnchor] - .active = YES; - [_bannerView.topAnchor constraintEqualToAnchor:scrollView.topAnchor].active = - YES; + [_bannerView.widthAnchor constraintEqualToAnchor:scrollView.widthAnchor].active = YES; + [_bannerView.topAnchor constraintEqualToAnchor:scrollView.topAnchor].active = YES; return scrollView; } #pragma mark - GADAdSizeDelegate -- (void)adView:(GADBannerView *)bannerView - willChangeAdSizeTo:(GADAdSize)adSize { +- (void)adView:(GADBannerView *)bannerView willChangeAdSizeTo:(GADAdSize)adSize { CGFloat height = adSize.size.height; [self.manager onFluidAdHeightChanged:self height:height]; } @@ -614,16 +573,14 @@ @implementation FLTFullScreenAd { - (void)load { // Must be overridden by subclasses - [NSException - raise:NSInternalInconsistencyException - format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; + [NSException raise:NSInternalInconsistencyException + format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; } - (void)showFromRootViewController:(UIViewController *)rootViewController { // Must be overridden by subclasses - [NSException - raise:NSInternalInconsistencyException - format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; + [NSException raise:NSInternalInconsistencyException + format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; } - (void)ad:(nonnull id)ad @@ -631,30 +588,25 @@ - (void)ad:(nonnull id)ad [manager didFailToPresentFullScreenContentWithError:self error:error]; } -- (void)adWillPresentFullScreenContent: - (nonnull id)ad { +- (void)adWillPresentFullScreenContent:(nonnull id)ad { // Manually hide the status bar. This is a fix for // https://github.com/googleads/googleads-mobile-flutter/issues/191 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - _statusBarVisibilityBeforeAdShow = - UIApplication.sharedApplication.statusBarHidden; + _statusBarVisibilityBeforeAdShow = UIApplication.sharedApplication.statusBarHidden; [UIApplication.sharedApplication setStatusBarHidden:YES]; #pragma clang diagnostic pop [manager adWillPresentFullScreenContent:self]; } -- (void)adDidDismissFullScreenContent: - (nonnull id)ad { +- (void)adDidDismissFullScreenContent:(nonnull id)ad { [manager adDidDismissFullScreenContent:self]; } -- (void)adWillDismissFullScreenContent: - (nonnull id)ad { +- (void)adWillDismissFullScreenContent:(nonnull id)ad { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - [UIApplication.sharedApplication - setStatusBarHidden:_statusBarVisibilityBeforeAdShow]; + [UIApplication.sharedApplication setStatusBarHidden:_statusBarVisibilityBeforeAdShow]; #pragma clang diagnostic pop [manager adWillDismissFullScreenContent:self]; } @@ -698,32 +650,30 @@ - (NSString *_Nonnull)adUnitId { } - (void)load { - [GADInterstitialAd - loadWithAdUnitID:_adUnitId - request:[_adRequest asGADRequest:_adUnitId] - completionHandler:^(GADInterstitialAd *ad, NSError *error) { - if (error) { - [self.manager onAdFailedToLoad:self error:error]; - return; - } - - ad.fullScreenContentDelegate = self; - self->_interstitialView = ad; - __weak FLTInterstitialAd *weakSelf = self; - ad.paidEventHandler = ^(GADAdValue *_Nonnull value) { - if (weakSelf.manager == nil) { - return; - } - [weakSelf.manager - onPaidEvent:weakSelf - value:[[FLTAdValue alloc] - initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; - }; - - [self.manager onAdLoaded:self responseInfo:ad.responseInfo]; - }]; + [GADInterstitialAd loadWithAdUnitID:_adUnitId + request:[_adRequest asGADRequest:_adUnitId] + completionHandler:^(GADInterstitialAd *ad, NSError *error) { + if (error) { + [self.manager onAdFailedToLoad:self error:error]; + return; + } + + ad.fullScreenContentDelegate = self; + self->_interstitialView = ad; + __weak FLTInterstitialAd *weakSelf = self; + ad.paidEventHandler = ^(GADAdValue *_Nonnull value) { + if (weakSelf.manager == nil) { + return; + } + [weakSelf.manager + onPaidEvent:weakSelf + value:[[FLTAdValue alloc] initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; + }; + + [self.manager onAdLoaded:self responseInfo:ad.responseInfo]; + }]; } - (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewController { @@ -779,10 +729,9 @@ - (void)load { } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] - initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; self->_insterstitial = ad; @@ -844,8 +793,7 @@ - (void)load { [GADRewardedAd loadWithAdUnitID:_adUnitId request:request - completionHandler:^(GADRewardedAd *_Nullable rewardedAd, - NSError *_Nullable error) { + completionHandler:^(GADRewardedAd *_Nullable rewardedAd, NSError *_Nullable error) { if (error) { [self.manager onAdFailedToLoad:self error:error]; return; @@ -857,30 +805,26 @@ - (void)load { } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] - initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; rewardedAd.fullScreenContentDelegate = self; self->_rewardedView = rewardedAd; - [self.manager onAdLoaded:self - responseInfo:rewardedAd.responseInfo]; + [self.manager onAdLoaded:self responseInfo:rewardedAd.responseInfo]; }]; } - (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewController { if (self.rewardedAd) { - [self.rewardedAd - presentFromRootViewController:rootViewController - userDidEarnRewardHandler:^{ - GADAdReward *reward = self.rewardedAd.adReward; - FLTRewardItem *fltReward = - [[FLTRewardItem alloc] initWithAmount:reward.amount - type:reward.type]; - [self.manager onRewardedAdUserEarnedReward:self - reward:fltReward]; - }]; + [self.rewardedAd presentFromRootViewController:rootViewController + userDidEarnRewardHandler:^{ + GADAdReward *reward = self.rewardedAd.adReward; + FLTRewardItem *fltReward = + [[FLTRewardItem alloc] initWithAmount:reward.amount + type:reward.type]; + [self.manager onRewardedAdUserEarnedReward:self reward:fltReward]; + }]; } else { NSLog(@"RewardedAd failed to show because the ad was not ready."); } @@ -937,30 +881,25 @@ - (void)load { [GADRewardedInterstitialAd loadWithAdUnitID:_adUnitId request:request - completionHandler:^( - GADRewardedInterstitialAd *_Nullable rewardedInterstitialAd, - NSError *_Nullable error) { + completionHandler:^(GADRewardedInterstitialAd *_Nullable rewardedInterstitialAd, + NSError *_Nullable error) { if (error) { [self.manager onAdFailedToLoad:self error:error]; return; } __weak FLTRewardedInterstitialAd *weakSelf = self; - rewardedInterstitialAd.paidEventHandler = - ^(GADAdValue *_Nonnull value) { - if (weakSelf.manager == nil) { - return; - } - [weakSelf.manager - onPaidEvent:weakSelf - value:[[FLTAdValue alloc] - initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; - }; + rewardedInterstitialAd.paidEventHandler = ^(GADAdValue *_Nonnull value) { + if (weakSelf.manager == nil) { + return; + } + [weakSelf.manager onPaidEvent:weakSelf + value:[[FLTAdValue alloc] initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; + }; rewardedInterstitialAd.fullScreenContentDelegate = self; self->_rewardedInterstitialView = rewardedInterstitialAd; - [self.manager onAdLoaded:self - responseInfo:rewardedInterstitialAd.responseInfo]; + [self.manager onAdLoaded:self responseInfo:rewardedInterstitialAd.responseInfo]; }]; } @@ -970,16 +909,12 @@ - (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewControlle presentFromRootViewController:rootViewController userDidEarnRewardHandler:^{ GADAdReward *reward = self.rewardedInterstitialAd.adReward; - FLTRewardItem *fltReward = - [[FLTRewardItem alloc] initWithAmount:reward.amount - type:reward.type]; - [self.manager - onRewardedInterstitialAdUserEarnedReward:self - reward:fltReward]; + FLTRewardItem *fltReward = [[FLTRewardItem alloc] initWithAmount:reward.amount + type:reward.type]; + [self.manager onRewardedInterstitialAdUserEarnedReward:self reward:fltReward]; }]; } else { - NSLog( - @"RewardedInterstitialAd failed to show because the ad was not ready."); + NSLog(@"RewardedInterstitialAd failed to show because the ad was not ready."); } } @@ -1033,8 +968,7 @@ - (void)load { [GADAppOpenAd loadWithAdUnitID:_adUnitId request:request - completionHandler:^(GADAppOpenAd *_Nullable appOpenAd, - NSError *_Nullable error) { + completionHandler:^(GADAppOpenAd *_Nullable appOpenAd, NSError *_Nullable error) { if (error) { [self.manager onAdFailedToLoad:self error:error]; return; @@ -1046,16 +980,14 @@ - (void)load { } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] - initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; appOpenAd.fullScreenContentDelegate = self; self->_appOpenAd = appOpenAd; - [self.manager onAdLoaded:self - responseInfo:appOpenAd.responseInfo]; + [self.manager onAdLoaded:self responseInfo:appOpenAd.responseInfo]; }]; } @@ -1082,15 +1014,14 @@ @implementation FLTNativeAd { FLTNativeTemplateStyle *_nativeTemplateStyle; } -- (instancetype _Nonnull) - initWithAdUnitId:(NSString *_Nonnull)adUnitId - request:(FLTAdRequest *_Nonnull)request - nativeAdFactory:(NSObject *_Nonnull)nativeAdFactory - customOptions:(NSDictionary *_Nullable)customOptions - rootViewController:(UIViewController *_Nonnull)rootViewController - adId:(NSNumber *_Nonnull)adId - nativeAdOptions:(FLTNativeAdOptions *_Nullable)nativeAdOptions - nativeTemplateStyle:(FLTNativeTemplateStyle *_Nullable)nativeTemplateStyle { +- (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId + request:(FLTAdRequest *_Nonnull)request + nativeAdFactory:(NSObject *_Nonnull)nativeAdFactory + customOptions:(NSDictionary *_Nullable)customOptions + rootViewController:(UIViewController *_Nonnull)rootViewController + adId:(NSNumber *_Nonnull)adId + nativeAdOptions:(FLTNativeAdOptions *_Nullable)nativeAdOptions + nativeTemplateStyle:(FLTNativeTemplateStyle *_Nullable)nativeTemplateStyle { self = [super init]; if (self) { self.adId = adId; @@ -1103,11 +1034,10 @@ @implementation FLTNativeAd { ? @[] : nativeAdOptions.asGADAdLoaderOptions; - _adLoader = - [[GADAdLoader alloc] initWithAdUnitID:_adUnitId - rootViewController:rootViewController - adTypes:@[ GADAdLoaderAdTypeNative ] - options:adLoaderOptions]; + _adLoader = [[GADAdLoader alloc] initWithAdUnitID:_adUnitId + rootViewController:rootViewController + adTypes:@[ GADAdLoaderAdTypeNative ] + options:adLoaderOptions]; _nativeAdOptions = nativeAdOptions; _nativeTemplateStyle = nativeTemplateStyle; self.adLoader.delegate = self; @@ -1133,16 +1063,14 @@ - (void)load { #pragma mark - GADNativeAdLoaderDelegate -- (void)adLoader:(GADAdLoader *)adLoader - didReceiveNativeAd:(GADNativeAd *)nativeAd { +- (void)adLoader:(GADAdLoader *)adLoader didReceiveNativeAd:(GADNativeAd *)nativeAd { // Use Nil instead of Null to fix crash with Swift integrations. NSDictionary *customOptions = [[NSNull null] isEqual:_customOptions] ? nil : _customOptions; if ([FLTAdUtil isNotNull:_nativeTemplateStyle]) { _view = [_nativeTemplateStyle getDisplayedView:nativeAd]; } else if ([FLTAdUtil isNotNull:_nativeAdFactory]) { - _view = [_nativeAdFactory createNativeAd:nativeAd - customOptions:customOptions]; + _view = [_nativeAdFactory createNativeAd:nativeAd customOptions:customOptions]; } nativeAd.delegate = self; @@ -1152,17 +1080,15 @@ - (void)adLoader:(GADAdLoader *)adLoader if (weakSelf.manager == nil) { return; } - [weakSelf.manager - onPaidEvent:weakSelf - value:[[FLTAdValue alloc] initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + [weakSelf.manager onPaidEvent:weakSelf + value:[[FLTAdValue alloc] initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; [manager onAdLoaded:self responseInfo:nativeAd.responseInfo]; } -- (void)adLoader:(GADAdLoader *)adLoader - didFailToReceiveAdWithError:(NSError *)error { +- (void)adLoader:(GADAdLoader *)adLoader didFailToReceiveAdWithError:(NSError *)error { [manager onAdFailedToLoad:self error:error]; } @@ -1198,8 +1124,7 @@ - (UIView *)view { @end @implementation FLTRewardItem -- (instancetype _Nonnull)initWithAmount:(NSNumber *_Nonnull)amount - type:(NSString *_Nonnull)type { +- (instancetype _Nonnull)initWithAmount:(NSNumber *_Nonnull)amount type:(NSString *_Nonnull)type { self = [super init]; if (self) { _amount = amount; @@ -1231,8 +1156,7 @@ - (instancetype _Nonnull)initWithValue:(NSDecimalNumber *_Nonnull)value self = [super init]; if (self) { _valueMicros = - [value decimalNumberByMultiplyingBy:[[NSDecimalNumber alloc] - initWithInteger:1000000]]; + [value decimalNumberByMultiplyingBy:[[NSDecimalNumber alloc] initWithInteger:1000000]]; _precision = precision; _currencyCode = currencyCode; } @@ -1241,10 +1165,9 @@ - (instancetype _Nonnull)initWithValue:(NSDecimalNumber *_Nonnull)value @end @implementation FLTVideoOptions -- (instancetype _Nonnull) - initWithClickToExpandRequested:(NSNumber *_Nullable)clickToExpandRequested - customControlsRequested:(NSNumber *_Nullable)customControlsRequested - startMuted:(NSNumber *_Nullable)startMuted { +- (instancetype _Nonnull)initWithClickToExpandRequested:(NSNumber *_Nullable)clickToExpandRequested + customControlsRequested:(NSNumber *_Nullable)customControlsRequested + startMuted:(NSNumber *_Nullable)startMuted { self = [super init]; if (self) { _clickToExpandRequested = clickToExpandRequested; @@ -1271,15 +1194,13 @@ - (GADVideoOptions *_Nonnull)asGADVideoOptions { @end @implementation FLTNativeAdOptions -- (instancetype _Nonnull) - initWithAdChoicesPlacement:(NSNumber *_Nullable)adChoicesPlacement - mediaAspectRatio:(NSNumber *_Nullable)mediaAspectRatio - videoOptions:(FLTVideoOptions *_Nullable)videoOptions - requestCustomMuteThisAd:(NSNumber *_Nullable)requestCustomMuteThisAd - shouldRequestMultipleImages: - (NSNumber *_Nullable)shouldRequestMultipleImages - shouldReturnUrlsForImageAssets: - (NSNumber *_Nullable)shouldReturnUrlsForImageAssets { +- (instancetype _Nonnull)initWithAdChoicesPlacement:(NSNumber *_Nullable)adChoicesPlacement + mediaAspectRatio:(NSNumber *_Nullable)mediaAspectRatio + videoOptions:(FLTVideoOptions *_Nullable)videoOptions + requestCustomMuteThisAd:(NSNumber *_Nullable)requestCustomMuteThisAd + shouldRequestMultipleImages:(NSNumber *_Nullable)shouldRequestMultipleImages + shouldReturnUrlsForImageAssets: + (NSNumber *_Nullable)shouldReturnUrlsForImageAssets { self = [super init]; if (self) { _adChoicesPlacement = adChoicesPlacement; @@ -1295,69 +1216,60 @@ @implementation FLTNativeAdOptions - (NSArray *_Nonnull)asGADAdLoaderOptions { NSMutableArray *options = [NSMutableArray array]; - GADNativeAdImageAdLoaderOptions *imageOptions = - [[GADNativeAdImageAdLoaderOptions alloc] init]; + GADNativeAdImageAdLoaderOptions *imageOptions = [[GADNativeAdImageAdLoaderOptions alloc] init]; if ([FLTAdUtil isNotNull:_shouldReturnUrlsForImageAssets]) { - imageOptions.disableImageLoading = - _shouldReturnUrlsForImageAssets.boolValue; + imageOptions.disableImageLoading = _shouldReturnUrlsForImageAssets.boolValue; } if ([FLTAdUtil isNotNull:_shouldRequestMultipleImages]) { - imageOptions.shouldRequestMultipleImages = - _shouldRequestMultipleImages.boolValue; + imageOptions.shouldRequestMultipleImages = _shouldRequestMultipleImages.boolValue; } [options addObject:imageOptions]; if ([FLTAdUtil isNotNull:_adChoicesPlacement]) { - GADNativeAdViewAdOptions *adViewOptions = - [[GADNativeAdViewAdOptions alloc] init]; + GADNativeAdViewAdOptions *adViewOptions = [[GADNativeAdViewAdOptions alloc] init]; switch (_adChoicesPlacement.intValue) { - case 0: - adViewOptions.preferredAdChoicesPosition = - GADAdChoicesPositionTopRightCorner; - break; - case 1: - adViewOptions.preferredAdChoicesPosition = - GADAdChoicesPositionTopLeftCorner; - break; - case 2: - adViewOptions.preferredAdChoicesPosition = - GADAdChoicesPositionBottomRightCorner; - break; - case 3: - adViewOptions.preferredAdChoicesPosition = - GADAdChoicesPositionBottomLeftCorner; - break; - default: - NSLog(@"AdChoicesPlacement should be an int in the range [0, 3]: %d", - _adChoicesPlacement.intValue); - break; + case 0: + adViewOptions.preferredAdChoicesPosition = GADAdChoicesPositionTopRightCorner; + break; + case 1: + adViewOptions.preferredAdChoicesPosition = GADAdChoicesPositionTopLeftCorner; + break; + case 2: + adViewOptions.preferredAdChoicesPosition = GADAdChoicesPositionBottomRightCorner; + break; + case 3: + adViewOptions.preferredAdChoicesPosition = GADAdChoicesPositionBottomLeftCorner; + break; + default: + NSLog(@"AdChoicesPlacement should be an int in the range [0, 3]: %d", + _adChoicesPlacement.intValue); + break; } [options addObject:adViewOptions]; } if ([FLTAdUtil isNotNull:_mediaAspectRatio]) { - GADNativeAdMediaAdLoaderOptions *mediaOptions = - [[GADNativeAdMediaAdLoaderOptions alloc] init]; + GADNativeAdMediaAdLoaderOptions *mediaOptions = [[GADNativeAdMediaAdLoaderOptions alloc] init]; switch (_mediaAspectRatio.intValue) { - case 0: - mediaOptions.mediaAspectRatio = GADMediaAspectRatioUnknown; - break; - case 1: - mediaOptions.mediaAspectRatio = GADMediaAspectRatioAny; - break; - case 2: - mediaOptions.mediaAspectRatio = GADMediaAspectRatioLandscape; - break; - case 3: - mediaOptions.mediaAspectRatio = GADMediaAspectRatioPortrait; - break; - case 4: - mediaOptions.mediaAspectRatio = GADMediaAspectRatioSquare; - break; - default: - NSLog(@"MediaAspectRatio should be an int in the range [0, 4]: %d", - _mediaAspectRatio.intValue); - break; + case 0: + mediaOptions.mediaAspectRatio = GADMediaAspectRatioUnknown; + break; + case 1: + mediaOptions.mediaAspectRatio = GADMediaAspectRatioAny; + break; + case 2: + mediaOptions.mediaAspectRatio = GADMediaAspectRatioLandscape; + break; + case 3: + mediaOptions.mediaAspectRatio = GADMediaAspectRatioPortrait; + break; + case 4: + mediaOptions.mediaAspectRatio = GADMediaAspectRatioSquare; + break; + default: + NSLog(@"MediaAspectRatio should be an int in the range [0, 4]: %d", + _mediaAspectRatio.intValue); + break; } [options addObject:mediaOptions]; } diff --git a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m index d76165594..b872d164c 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m +++ b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m @@ -22,8 +22,7 @@ @interface FLTGoogleMobileAdsPlugin () @property(nonatomic, retain) FlutterMethodChannel *channel; -@property NSMutableDictionary> - *nativeAdFactories; +@property NSMutableDictionary> *nativeAdFactories; @end /// Initialization handler for GMASDK. Invokes result at most once. @@ -75,29 +74,26 @@ @implementation FLTGoogleMobileAdsPlugin { } + (void)registerWithRegistrar:(NSObject *)registrar { - FLTGoogleMobileAdsPlugin *instance = [[FLTGoogleMobileAdsPlugin alloc] - initWithBinaryMessenger:registrar.messenger]; + FLTGoogleMobileAdsPlugin *instance = + [[FLTGoogleMobileAdsPlugin alloc] initWithBinaryMessenger:registrar.messenger]; [registrar publish:instance]; - FLTGoogleMobileAdsReaderWriter *readerWriter = - [[FLTGoogleMobileAdsReaderWriter alloc] init]; + FLTGoogleMobileAdsReaderWriter *readerWriter = [[FLTGoogleMobileAdsReaderWriter alloc] init]; instance->_readerWriter = readerWriter; NSObject *codec = [FlutterStandardMethodCodec codecWithReaderWriter:readerWriter]; - FlutterMethodChannel *channel = [FlutterMethodChannel - methodChannelWithName:@"plugins.flutter.io/google_mobile_ads" - binaryMessenger:[registrar messenger] - codec:codec]; + FlutterMethodChannel *channel = + [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/google_mobile_ads" + binaryMessenger:[registrar messenger] + codec:codec]; [registrar addMethodCallDelegate:instance channel:channel]; FLTNewGoogleMobileAdsViewFactory *viewFactory = - [[FLTNewGoogleMobileAdsViewFactory alloc] - initWithManager:instance->_manager]; - [registrar - registerViewFactory:viewFactory - withId:@"plugins.flutter.io/google_mobile_ads/ad_widget"]; + [[FLTNewGoogleMobileAdsViewFactory alloc] initWithManager:instance->_manager]; + [registrar registerViewFactory:viewFactory + withId:@"plugins.flutter.io/google_mobile_ads/ad_widget"]; [registrar addApplicationDelegate:instance]; } @@ -112,32 +108,25 @@ - (BOOL)application:(UIApplication *)application return YES; } -- (instancetype)initWithBinaryMessenger: - (id)binaryMessenger { +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger { self = [self init]; if (self) { _nativeAdFactories = [NSMutableDictionary dictionary]; - _manager = - [[FLTAdInstanceManager alloc] initWithBinaryMessenger:binaryMessenger]; - _appStateNotifier = - [[FLTAppStateNotifier alloc] initWithBinaryMessenger:binaryMessenger]; - _userMessagingPlatformManager = [[FLTUserMessagingPlatformManager alloc] - initWithBinaryMessenger:binaryMessenger]; + _manager = [[FLTAdInstanceManager alloc] initWithBinaryMessenger:binaryMessenger]; + _appStateNotifier = [[FLTAppStateNotifier alloc] initWithBinaryMessenger:binaryMessenger]; + _userMessagingPlatformManager = + [[FLTUserMessagingPlatformManager alloc] initWithBinaryMessenger:binaryMessenger]; } return self; } + (BOOL)registerMediationNetworkExtrasProvider: - (id _Nonnull) - mediationNetworkExtrasProvider - registry: - (id _Nonnull) - registry { - NSString *pluginClassName = - NSStringFromClass([FLTGoogleMobileAdsPlugin class]); - FLTGoogleMobileAdsPlugin *adMobPlugin = (FLTGoogleMobileAdsPlugin *)[registry - valuePublishedByPlugin:pluginClassName]; + (id _Nonnull)mediationNetworkExtrasProvider + registry:(id _Nonnull)registry { + NSString *pluginClassName = NSStringFromClass([FLTGoogleMobileAdsPlugin class]); + FLTGoogleMobileAdsPlugin *adMobPlugin = + (FLTGoogleMobileAdsPlugin *)[registry valuePublishedByPlugin:pluginClassName]; if (!adMobPlugin) { NSLog(@"Could not find a %@ instance registering mediation extras " @"provider. The plugin may " @@ -147,18 +136,15 @@ + (BOOL)registerMediationNetworkExtrasProvider: } adMobPlugin->_mediationNetworkExtrasProvider = mediationNetworkExtrasProvider; - adMobPlugin->_readerWriter.mediationNetworkExtrasProvider = - mediationNetworkExtrasProvider; + adMobPlugin->_readerWriter.mediationNetworkExtrasProvider = mediationNetworkExtrasProvider; return YES; } -+ (void)unregisterMediationNetworkExtrasProvider: - (id _Nonnull)registry { - NSString *pluginClassName = - NSStringFromClass([FLTGoogleMobileAdsPlugin class]); - FLTGoogleMobileAdsPlugin *adMobPlugin = (FLTGoogleMobileAdsPlugin *)[registry - valuePublishedByPlugin:pluginClassName]; ++ (void)unregisterMediationNetworkExtrasProvider:(id _Nonnull)registry { + NSString *pluginClassName = NSStringFromClass([FLTGoogleMobileAdsPlugin class]); + FLTGoogleMobileAdsPlugin *adMobPlugin = + (FLTGoogleMobileAdsPlugin *)[registry valuePublishedByPlugin:pluginClassName]; if (!adMobPlugin) { NSLog(@"Could not find a %@ instance deregistering mediation extras " @"provider. The plugin may " @@ -174,23 +160,18 @@ + (void)unregisterMediationNetworkExtrasProvider: + (BOOL)registerNativeAdFactory:(id)registry factoryId:(NSString *)factoryId nativeAdFactory:(id)nativeAdFactory { - NSString *pluginClassName = - NSStringFromClass([FLTGoogleMobileAdsPlugin class]); - FLTGoogleMobileAdsPlugin *adMobPlugin = (FLTGoogleMobileAdsPlugin *)[registry - valuePublishedByPlugin:pluginClassName]; + NSString *pluginClassName = NSStringFromClass([FLTGoogleMobileAdsPlugin class]); + FLTGoogleMobileAdsPlugin *adMobPlugin = + (FLTGoogleMobileAdsPlugin *)[registry valuePublishedByPlugin:pluginClassName]; if (!adMobPlugin) { - NSString *reason = - [NSString stringWithFormat:@"Could not find a %@ instance. The plugin " - @"may have not been registered.", - pluginClassName]; - [NSException exceptionWithName:NSInvalidArgumentException - reason:reason - userInfo:nil]; + NSString *reason = [NSString stringWithFormat:@"Could not find a %@ instance. The plugin " + @"may have not been registered.", + pluginClassName]; + [NSException exceptionWithName:NSInvalidArgumentException reason:reason userInfo:nil]; } if (adMobPlugin.nativeAdFactories[factoryId]) { - NSLog(@"A NativeAdFactory with the following factoryId already exists: %@", - factoryId); + NSLog(@"A NativeAdFactory with the following factoryId already exists: %@", factoryId); return NO; } @@ -198,38 +179,36 @@ + (BOOL)registerNativeAdFactory:(id)registry return YES; } -+ (id)unregisterNativeAdFactory: - (id)registry ++ (id)unregisterNativeAdFactory:(id)registry factoryId:(NSString *)factoryId { FLTGoogleMobileAdsPlugin *adMobPlugin = (FLTGoogleMobileAdsPlugin *)[registry - valuePublishedByPlugin:NSStringFromClass( - [FLTGoogleMobileAdsPlugin class])]; + valuePublishedByPlugin:NSStringFromClass([FLTGoogleMobileAdsPlugin class])]; id factory = adMobPlugin.nativeAdFactories[factoryId]; - if (factory) - [adMobPlugin.nativeAdFactories removeObjectForKey:factoryId]; + if (factory) [adMobPlugin.nativeAdFactories removeObjectForKey:factoryId]; return factory; } - (UIViewController *)rootController { - UIViewController *root = - UIApplication.sharedApplication.delegate.window.rootViewController; + UIViewController *root = UIApplication.sharedApplication.delegate.window.rootViewController; if ([FLTAdUtil isNull:root]) { - // UIApplication.sharedApplication.delegate.window is not guaranteed to be - // set. Use the keyWindow in this case. - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wdeprecated-declarations" +// UIApplication.sharedApplication.delegate.window is not guaranteed to be +// set. Use the keyWindow in this case. +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" root = UIApplication.sharedApplication.keyWindow.rootViewController; - #pragma clang diagnostic pop +#pragma clang diagnostic pop } UIViewController *presentedViewController = root; - while (presentedViewController.presentedViewController && ![presentedViewController.presentedViewController isBeingDismissed]) { + while (presentedViewController.presentedViewController && + ![presentedViewController.presentedViewController isBeingDismissed]) { if ([presentedViewController isKindOfClass:[UITabBarController class]]) { - UITabBarController* tabBarController = (UITabBarController*)presentedViewController; + UITabBarController *tabBarController = (UITabBarController *)presentedViewController; presentedViewController = tabBarController.selectedViewController; } else if ([presentedViewController isKindOfClass:[UINavigationController class]]) { - UINavigationController* navigationController = (UINavigationController*)presentedViewController; + UINavigationController *navigationController = + (UINavigationController *)presentedViewController; presentedViewController = navigationController.visibleViewController; } else { presentedViewController = presentedViewController.presentedViewController; @@ -238,26 +217,26 @@ - (UIViewController *)rootController { return presentedViewController; } -- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController { +- (UIViewController *)topViewControllerWithRootViewController: + (UIViewController *)rootViewController { if ([rootViewController isKindOfClass:[UITabBarController class]]) { - UITabBarController* tabBarController = (UITabBarController*)rootViewController; + UITabBarController *tabBarController = (UITabBarController *)rootViewController; return [self topViewControllerWithRootViewController:tabBarController.selectedViewController]; } else if ([rootViewController isKindOfClass:[UINavigationController class]]) { - UINavigationController* navigationController = (UINavigationController*)rootViewController; - return [self topViewControllerWithRootViewController:navigationController.visibleViewController]; + UINavigationController *navigationController = (UINavigationController *)rootViewController; + return + [self topViewControllerWithRootViewController:navigationController.visibleViewController]; } else { return rootViewController; } } -- (void)handleMethodCall:(FlutterMethodCall *)call - result:(FlutterResult)result { +- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { NSLog(@"handleMethodCall %@", call.method); UIViewController *rootController = self.rootController; if ([call.method isEqualToString:@"MobileAds#initialize"]) { - FLTInitializationHandler *handler = - [[FLTInitializationHandler alloc] initWithResult:result]; + FLTInitializationHandler *handler = [[FLTInitializationHandler alloc] initWithResult:result]; [[GADMobileAds sharedInstance] startWithCompletionHandler:^(GADInitializationStatus *_Nonnull status) { [handler handleInitializationComplete:status]; @@ -266,35 +245,27 @@ - (void)handleMethodCall:(FlutterMethodCall *)call [_manager disposeAllAds]; result(nil); } else if ([call.method isEqualToString:@"MobileAds#setSameAppKeyEnabled"]) { - GADRequestConfiguration *requestConfig = - GADMobileAds.sharedInstance.requestConfiguration; + GADRequestConfiguration *requestConfig = GADMobileAds.sharedInstance.requestConfiguration; NSNumber *isEnabled = call.arguments[@"isEnabled"]; [requestConfig setPublisherFirstPartyIDEnabled:isEnabled.boolValue]; result(nil); } else if ([call.method isEqualToString:@"MobileAds#setAppMuted"]) { - GADMobileAds.sharedInstance.applicationMuted = - [call.arguments[@"muted"] boolValue]; + GADMobileAds.sharedInstance.applicationMuted = [call.arguments[@"muted"] boolValue]; result(nil); } else if ([call.method isEqualToString:@"MobileAds#setAppVolume"]) { - GADMobileAds.sharedInstance.applicationVolume = - [call.arguments[@"volume"] floatValue]; + GADMobileAds.sharedInstance.applicationVolume = [call.arguments[@"volume"] floatValue]; result(nil); - } else if ([call.method - isEqualToString:@"MobileAds#disableSDKCrashReporting"]) { + } else if ([call.method isEqualToString:@"MobileAds#disableSDKCrashReporting"]) { [GADMobileAds.sharedInstance disableSDKCrashReporting]; result(nil); - } else if ([call.method - isEqualToString:@"MobileAds#disableMediationInitialization"]) { + } else if ([call.method isEqualToString:@"MobileAds#disableMediationInitialization"]) { [GADMobileAds.sharedInstance disableMediationInitialization]; result(nil); } else if ([call.method isEqualToString:@"MobileAds#openDebugMenu"]) { NSString *adUnitId = call.arguments[@"adUnitId"]; GADDebugOptionsViewController *debugOptionsViewController = - [GADDebugOptionsViewController - debugOptionsViewControllerWithAdUnitID:adUnitId]; - [rootController presentViewController:debugOptionsViewController - animated:YES - completion:nil]; + [GADDebugOptionsViewController debugOptionsViewControllerWithAdUnitID:adUnitId]; + [rootController presentViewController:debugOptionsViewController animated:YES completion:nil]; result(nil); } else if ([call.method isEqualToString:@"MobileAds#openAdInspector"]) { [GADMobileAds.sharedInstance @@ -302,8 +273,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call completionHandler:^(NSError *error) { if (error) { result([FlutterError - errorWithCode:[[NSString alloc] - initWithInt:error.code] + errorWithCode:[[NSString alloc] initWithInt:error.code] message:error.localizedDescription details:error.domain]); } else { @@ -311,28 +281,22 @@ - (void)handleMethodCall:(FlutterMethodCall *)call } }]; } else if ([call.method isEqualToString:@"MobileAds#getVersionString"]) { - result(GADGetStringFromVersionNumber( - GADMobileAds.sharedInstance.versionNumber)); - } else if ([call.method - isEqualToString:@"MobileAds#getRequestConfiguration"]) { + result(GADGetStringFromVersionNumber(GADMobileAds.sharedInstance.versionNumber)); + } else if ([call.method isEqualToString:@"MobileAds#getRequestConfiguration"]) { result(GADMobileAds.sharedInstance.requestConfiguration); } else if ([call.method isEqualToString:@"MobileAds#registerWebView"]) { if (!_appDelegate) { NSLog(@"App delegate is null in MobileAds#registerWebView, skipping"); } else { NSNumber *webViewId = call.arguments[@"webViewId"]; - WKWebView *webView = [FLTAdUtil getWebView:webViewId - flutterPluginRegistry:_appDelegate]; + WKWebView *webView = [FLTAdUtil getWebView:webViewId flutterPluginRegistry:_appDelegate]; [GADMobileAds.sharedInstance registerWebView:webView]; } result(nil); - } else if ([call.method - isEqualToString:@"MobileAds#updateRequestConfiguration"]) { + } else if ([call.method isEqualToString:@"MobileAds#updateRequestConfiguration"]) { NSString *maxAdContentRating = call.arguments[@"maxAdContentRating"]; - NSNumber *tagForChildDirectedTreatment = - call.arguments[@"tagForChildDirectedTreatment"]; - NSNumber *tagForUnderAgeOfConsent = - call.arguments[@"tagForUnderAgeOfConsent"]; + NSNumber *tagForChildDirectedTreatment = call.arguments[@"tagForChildDirectedTreatment"]; + NSNumber *tagForUnderAgeOfConsent = call.arguments[@"tagForUnderAgeOfConsent"]; NSArray *testDeviceIds = call.arguments[@"testDeviceIds"]; if (maxAdContentRating != NULL && maxAdContentRating != (id)[NSNull null]) { @@ -350,76 +314,63 @@ - (void)handleMethodCall:(FlutterMethodCall *)call GADMaxAdContentRatingMatureAudience; } } - if (tagForChildDirectedTreatment != NULL && - tagForChildDirectedTreatment != (id)[NSNull null]) { + if (tagForChildDirectedTreatment != NULL && tagForChildDirectedTreatment != (id)[NSNull null]) { switch ([tagForChildDirectedTreatment intValue]) { - case 0: - GADMobileAds.sharedInstance.requestConfiguration - .tagForChildDirectedTreatment = @NO; - break; - case 1: - GADMobileAds.sharedInstance.requestConfiguration - .tagForChildDirectedTreatment = @YES; - break; + case 0: + GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment = @NO; + break; + case 1: + GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment = @YES; + break; } } - if (tagForUnderAgeOfConsent != NULL && - tagForUnderAgeOfConsent != (id)[NSNull null]) { + if (tagForUnderAgeOfConsent != NULL && tagForUnderAgeOfConsent != (id)[NSNull null]) { switch ([tagForUnderAgeOfConsent intValue]) { - case 0: - GADMobileAds.sharedInstance.requestConfiguration - .tagForUnderAgeOfConsent = @NO; - break; - case 1: - GADMobileAds.sharedInstance.requestConfiguration - .tagForUnderAgeOfConsent = @YES; - break; + case 0: + GADMobileAds.sharedInstance.requestConfiguration.tagForUnderAgeOfConsent = @NO; + break; + case 1: + GADMobileAds.sharedInstance.requestConfiguration.tagForUnderAgeOfConsent = @YES; + break; } } if (testDeviceIds != NULL && testDeviceIds != (id)[NSNull null]) { - GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = - testDeviceIds; + GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = testDeviceIds; } result(nil); } else if ([call.method isEqualToString:@"loadBannerAd"]) { - FLTBannerAd *ad = - [[FLTBannerAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - size:call.arguments[@"size"] - request:call.arguments[@"request"] - rootViewController:rootController - adId:call.arguments[@"adId"]]; + FLTBannerAd *ad = [[FLTBannerAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + size:call.arguments[@"size"] + request:call.arguments[@"request"] + rootViewController:rootController + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadAdManagerBannerAd"]) { - FLTGAMBannerAd *ad = - [[FLTGAMBannerAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - sizes:call.arguments[@"sizes"] - request:call.arguments[@"request"] - rootViewController:rootController - adId:call.arguments[@"adId"]]; + FLTGAMBannerAd *ad = [[FLTGAMBannerAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + sizes:call.arguments[@"sizes"] + request:call.arguments[@"request"] + rootViewController:rootController + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadFluidAd"]) { - FLTFluidGAMBannerAd *ad = [[FLTFluidGAMBannerAd alloc] - initWithAdUnitId:call.arguments[@"adUnitId"] - request:call.arguments[@"request"] - rootViewController:rootController - adId:call.arguments[@"adId"]]; + FLTFluidGAMBannerAd *ad = + [[FLTFluidGAMBannerAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + request:call.arguments[@"request"] + rootViewController:rootController + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadNativeAd"]) { NSString *factoryId = call.arguments[@"factoryId"]; id factory = _nativeAdFactories[factoryId]; - FLTNativeTemplateStyle *templateStyle = - call.arguments[@"nativeTemplateStyle"]; + FLTNativeTemplateStyle *templateStyle = call.arguments[@"nativeTemplateStyle"]; if ([FLTAdUtil isNull:factory] && [FLTAdUtil isNull:templateStyle]) { - NSString *message = - [NSString stringWithFormat:@"Can't find NativeAdFactory with id: %@ " - @"and nativeTemplateStyle is null", - factoryId]; - result([FlutterError errorWithCode:@"NativeAdError" - message:message - details:nil]); + NSString *message = [NSString stringWithFormat:@"Can't find NativeAdFactory with id: %@ " + @"and nativeTemplateStyle is null", + factoryId]; + result([FlutterError errorWithCode:@"NativeAdError" message:message details:nil]); return; } @@ -430,29 +381,27 @@ - (void)handleMethodCall:(FlutterMethodCall *)call request = call.arguments[@"adManagerRequest"]; } - FLTNativeAd *ad = [[FLTNativeAd alloc] - initWithAdUnitId:call.arguments[@"adUnitId"] - request:request - nativeAdFactory:(id)factory - customOptions:call.arguments[@"customOptions"] - rootViewController:rootController - adId:call.arguments[@"adId"] - nativeAdOptions:call.arguments[@"nativeAdOptions"] - nativeTemplateStyle:call.arguments[@"nativeTemplateStyle"]]; + FLTNativeAd *ad = [[FLTNativeAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + request:request + nativeAdFactory:(id)factory + customOptions:call.arguments[@"customOptions"] + rootViewController:rootController + adId:call.arguments[@"adId"] + nativeAdOptions:call.arguments[@"nativeAdOptions"] + nativeTemplateStyle:call.arguments[@"nativeTemplateStyle"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadInterstitialAd"]) { - FLTInterstitialAd *ad = - [[FLTInterstitialAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - request:call.arguments[@"request"] - adId:call.arguments[@"adId"]]; + FLTInterstitialAd *ad = [[FLTInterstitialAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + request:call.arguments[@"request"] + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadAdManagerInterstitialAd"]) { - FLTGAMInterstitialAd *ad = [[FLTGAMInterstitialAd alloc] - initWithAdUnitId:call.arguments[@"adUnitId"] - request:call.arguments[@"request"] - adId:call.arguments[@"adId"]]; + FLTGAMInterstitialAd *ad = + [[FLTGAMInterstitialAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + request:call.arguments[@"request"] + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadRewardedAd"]) { @@ -462,17 +411,15 @@ - (void)handleMethodCall:(FlutterMethodCall *)call } else if ([FLTAdUtil isNotNull:call.arguments[@"adManagerRequest"]]) { request = call.arguments[@"adManagerRequest"]; } else { - result([FlutterError - errorWithCode:@"InvalidRequest" - message:@"A null or invalid ad request was provided." - details:nil]); + result([FlutterError errorWithCode:@"InvalidRequest" + message:@"A null or invalid ad request was provided." + details:nil]); return; } - FLTRewardedAd *ad = - [[FLTRewardedAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - request:request - adId:call.arguments[@"adId"]]; + FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + request:request + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadRewardedInterstitialAd"]) { @@ -482,17 +429,16 @@ - (void)handleMethodCall:(FlutterMethodCall *)call } else if ([FLTAdUtil isNotNull:call.arguments[@"adManagerRequest"]]) { request = call.arguments[@"adManagerRequest"]; } else { - result([FlutterError - errorWithCode:@"InvalidRequest" - message:@"A null or invalid ad request was provided." - details:nil]); + result([FlutterError errorWithCode:@"InvalidRequest" + message:@"A null or invalid ad request was provided." + details:nil]); return; } - FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] - initWithAdUnitId:call.arguments[@"adUnitId"] - request:request - adId:call.arguments[@"adId"]]; + FLTRewardedInterstitialAd *ad = + [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + request:request + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadAppOpenAd"]) { @@ -502,31 +448,27 @@ - (void)handleMethodCall:(FlutterMethodCall *)call } else if ([FLTAdUtil isNotNull:call.arguments[@"adManagerRequest"]]) { request = call.arguments[@"adManagerRequest"]; } else { - result([FlutterError - errorWithCode:@"InvalidRequest" - message:@"A null or invalid ad request was provided." - details:nil]); + result([FlutterError errorWithCode:@"InvalidRequest" + message:@"A null or invalid ad request was provided." + details:nil]); return; } - FLTAppOpenAd *ad = - [[FLTAppOpenAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - request:request - adId:call.arguments[@"adId"]]; + FLTAppOpenAd *ad = [[FLTAppOpenAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + request:request + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"disposeAd"]) { [_manager dispose:call.arguments[@"adId"]]; result(nil); } else if ([call.method isEqualToString:@"showAdWithoutView"]) { - [_manager showAdWithID:call.arguments[@"adId"] - rootViewController:rootController]; + [_manager showAdWithID:call.arguments[@"adId"] rootViewController:rootController]; result(nil); - } else if ([call.method - isEqualToString:@"AdSize#getAnchoredAdaptiveBannerAdSize"]) { - FLTAnchoredAdaptiveBannerSize *size = [[FLTAnchoredAdaptiveBannerSize alloc] - initWithFactory:[[FLTAdSizeFactory alloc] init] - orientation:call.arguments[@"orientation"] - width:call.arguments[@"width"]]; + } else if ([call.method isEqualToString:@"AdSize#getAnchoredAdaptiveBannerAdSize"]) { + FLTAnchoredAdaptiveBannerSize *size = + [[FLTAnchoredAdaptiveBannerSize alloc] initWithFactory:[[FLTAdSizeFactory alloc] init] + orientation:call.arguments[@"orientation"] + width:call.arguments[@"width"]]; if (IsGADAdSizeValid(size.size)) { result(size.height); } else { @@ -544,17 +486,14 @@ - (void)handleMethodCall:(FlutterMethodCall *)call } else { result(FlutterMethodNotImplemented); } - } else if ([call.method - isEqualToString:@"setServerSideVerificationOptions"]) { + } else if ([call.method isEqualToString:@"setServerSideVerificationOptions"]) { id ad = [_manager adFor:call.arguments[@"adId"]]; - FLTServerSideVerificationOptions *options = - call.arguments[@"serverSideVerificationOptions"]; + FLTServerSideVerificationOptions *options = call.arguments[@"serverSideVerificationOptions"]; if ([ad isKindOfClass:[FLTRewardedAd class]]) { FLTRewardedAd *rewardedAd = (FLTRewardedAd *)ad; [rewardedAd setServerSideVerificationOptions:options]; } else if ([ad isKindOfClass:[FLTRewardedInterstitialAd class]]) { - FLTRewardedInterstitialAd *rewardedInterstitialAd = - (FLTRewardedInterstitialAd *)ad; + FLTRewardedInterstitialAd *rewardedInterstitialAd = (FLTRewardedInterstitialAd *)ad; [rewardedInterstitialAd setServerSideVerificationOptions:options]; } else { NSLog(@"Error - setServerSideVerificationOptions called on missing or " From f1f4a215c0b1e0c9fbc337ce4cd02d737339671f Mon Sep 17 00:00:00 2001 From: Aldo Becerril Date: Fri, 9 Aug 2024 12:48:48 -0700 Subject: [PATCH 07/15] Revert "format fix" This reverts commit 64f1d6d7d3e0ac4c34b769c3d4ee5ee667192233. --- .../ios/RunnerTests/FLTAppOpenAdTest.m | 73 +-- .../RunnerTests/FLTGamInterstitialAdTest.m | 91 ++-- .../ios/RunnerTests/FLTGoogleMobileAdsTest.m | 336 ++++++------ .../ios/RunnerTests/FLTInterstitialAdTest.m | 77 +-- .../ios/RunnerTests/FLTRewardedAdTest.m | 89 ++-- .../FLTRewardedInterstitialAdTest.m | 122 +++-- .../Classes/FLTAdInstanceManager_Internal.h | 19 +- .../Classes/FLTAdInstanceManager_Internal.m | 36 +- .../ios/Classes/FLTAd_Internal.h | 108 ++-- .../ios/Classes/FLTAd_Internal.m | 490 +++++++++++------- .../ios/Classes/FLTGoogleMobileAdsPlugin.m | 357 +++++++------ 11 files changed, 1051 insertions(+), 747 deletions(-) diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m index 93286f3cb..dfc65a59d 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m @@ -47,7 +47,8 @@ - (void)testLoadShowGAMRequest { OCMClassMock([FLTServerSideVerificationOptions class]); GADServerSideVerificationOptions *gadOptions = OCMClassMock([GADServerSideVerificationOptions class]); - OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]).andReturn(gadOptions); + OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]) + .andReturn(gadOptions); [self testLoadShowAppOpenAd:request gadOrGAMRequest:gamRequest]; } @@ -55,8 +56,12 @@ - (void)testLoadShowGAMRequest { // Helper method for testing with FLTAdRequest and FLTGAMAdRequest. - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request gadOrGAMRequest:(GADRequest *)gadOrGAMRequest { - UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); - FLTAppOpenAd *ad = [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" request:request adId:@1]; + UIViewController *mockRootViewController = + OCMClassMock([UIViewController class]); + FLTAppOpenAd *ad = + [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; // Stub the load call to invoke successful load callback. @@ -81,7 +86,8 @@ - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request [delegate adDidDismissFullScreenContent:appOpenClassMock]; [delegate adWillPresentFullScreenContent:appOpenClassMock]; [delegate adWillDismissFullScreenContent:appOpenClassMock]; - [delegate ad:appOpenClassMock didFailToPresentFullScreenContentWithError:error]; + [delegate ad:appOpenClassMock + didFailToPresentFullScreenContentWithError:error]; }); GADResponseInfo *responseInfo = OCMClassMock([GADResponseInfo class]); OCMStub([appOpenClassMock responseInfo]).andReturn(responseInfo); @@ -91,36 +97,40 @@ - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request OCMStub([adValue value]).andReturn(NSDecimalNumber.one); OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated); OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); - OCMStub([appOpenClassMock setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - GADPaidEventHandler handler = obj; - handler(adValue); - return YES; - }]]); + OCMStub([appOpenClassMock + setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + GADPaidEventHandler handler = obj; + handler(adValue); + return YES; + }]]); // Call load and check expected interactions with mocks. [ad load]; - OCMVerify(ClassMethod([appOpenClassMock loadWithAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadOrGAMRequest] - completionHandler:[OCMArg any]])); + OCMVerify(ClassMethod([appOpenClassMock + loadWithAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadOrGAMRequest] + completionHandler:[OCMArg any]])); OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad] responseInfo:[OCMArg isEqual:responseInfo]]); - OCMVerify([appOpenClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); + OCMVerify( + [appOpenClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); XCTAssertEqual(ad.appOpenAd, appOpenClassMock); - OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager + onPaidEvent:[OCMArg isEqual:ad] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); [ad showFromRootViewController:mockRootViewController]; - OCMVerify( - [appOpenClassMock presentFromRootViewController:[OCMArg isEqual:mockRootViewController]]); + OCMVerify([appOpenClassMock + presentFromRootViewController:[OCMArg isEqual:mockRootViewController]]); // Verify full screen callbacks. OCMVerify([mockManager adWillPresentFullScreenContent:[OCMArg isEqual:ad]]); @@ -128,8 +138,9 @@ - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request OCMVerify([mockManager adWillDismissFullScreenContent:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordImpression:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:ad]]); - OCMVerify([mockManager didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager + didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); } - (void)testFailedToLoadGADRequest { @@ -150,7 +161,10 @@ - (void)testFailedToLoadGAMRequest { // Helper for testing failed to load. - (void)testFailedToLoad:(FLTAdRequest *)request { - FLTAppOpenAd *ad = [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" request:request adId:@1]; + FLTAppOpenAd *ad = + [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id appOpenClassMock = OCMClassMock([GADAppOpenAd class]); @@ -169,7 +183,8 @@ - (void)testFailedToLoad:(FLTAdRequest *)request { OCMVerify(ClassMethod([appOpenClassMock loadWithAdUnitID:[OCMArg any] request:[OCMArg any] completionHandler:[OCMArg any]])); - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m index 3cc61b069..c3d55f8d7 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m @@ -35,16 +35,19 @@ - (void)testLoadShowInterstitialAd { GAMRequest *gadRequest = OCMClassMock([GAMRequest class]); OCMStub([request asGAMRequest:[OCMArg any]]).andReturn(gadRequest); - UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); - FLTGAMInterstitialAd *ad = [[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + UIViewController *mockRootViewController = + OCMClassMock([UIViewController class]); + FLTGAMInterstitialAd *ad = + [[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id interstitialClassMock = OCMClassMock([GAMInterstitialAd class]); - OCMStub(ClassMethod([interstitialClassMock loadWithAdManagerAdUnitID:[OCMArg any] - request:[OCMArg any] - completionHandler:[OCMArg any]])) + OCMStub(ClassMethod([interstitialClassMock + loadWithAdManagerAdUnitID:[OCMArg any] + request:[OCMArg any] + completionHandler:[OCMArg any]])) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(GAMInterstitialAd *ad, NSError *error); [invocation getArgument:&completionHandler atIndex:4]; @@ -61,7 +64,8 @@ - (void)testLoadShowInterstitialAd { [delegate adDidDismissFullScreenContent:interstitialClassMock]; [delegate adWillPresentFullScreenContent:interstitialClassMock]; [delegate adWillDismissFullScreenContent:interstitialClassMock]; - [delegate ad:interstitialClassMock didFailToPresentFullScreenContentWithError:error]; + [delegate ad:interstitialClassMock + didFailToPresentFullScreenContentWithError:error]; }); OCMStub([interstitialClassMock setAppEventDelegate:[OCMArg any]]) @@ -82,31 +86,35 @@ - (void)testLoadShowInterstitialAd { OCMStub([adValue value]).andReturn(NSDecimalNumber.one); OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated); OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); - OCMStub([interstitialClassMock setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - GADPaidEventHandler handler = obj; - handler(adValue); - return YES; - }]]); + OCMStub([interstitialClassMock + setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + GADPaidEventHandler handler = obj; + handler(adValue); + return YES; + }]]); // Call load and verify interactions with mocks. [ad load]; - OCMVerify(ClassMethod([interstitialClassMock loadWithAdManagerAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadRequest] - completionHandler:[OCMArg any]])); + OCMVerify(ClassMethod([interstitialClassMock + loadWithAdManagerAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadRequest] + completionHandler:[OCMArg any]])); OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad] responseInfo:[OCMArg isEqual:responseInfo]]); - OCMVerify([interstitialClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); + OCMVerify( + [interstitialClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); XCTAssertEqual(ad.interstitial, interstitialClassMock); - OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager + onPaidEvent:[OCMArg isEqual:ad] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); // Show the ad [ad showFromRootViewController:mockRootViewController]; @@ -120,8 +128,9 @@ - (void)testLoadShowInterstitialAd { OCMVerify([mockManager adWillDismissFullScreenContent:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordImpression:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:ad]]); - OCMVerify([mockManager didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager + didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); // Verify app event OCMVerify([mockManager onAppEvent:ad @@ -135,16 +144,18 @@ - (void)testFailToLoad { GAMRequest *gadRequest = OCMClassMock([GAMRequest class]); OCMStub([request asGAMRequest:[OCMArg any]]).andReturn(gadRequest); - FLTGAMInterstitialAd *ad = [[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + FLTGAMInterstitialAd *ad = + [[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id interstitialClassMock = OCMClassMock([GAMInterstitialAd class]); NSError *error = OCMClassMock([NSError class]); - OCMStub(ClassMethod([interstitialClassMock loadWithAdManagerAdUnitID:[OCMArg any] - request:[OCMArg any] - completionHandler:[OCMArg any]])) + OCMStub(ClassMethod([interstitialClassMock + loadWithAdManagerAdUnitID:[OCMArg any] + request:[OCMArg any] + completionHandler:[OCMArg any]])) .andDo(^(NSInvocation *invocation) { void (^completionHandler)(GAMInterstitialAd *ad, NSError *error); [invocation getArgument:&completionHandler atIndex:4]; @@ -153,10 +164,12 @@ - (void)testFailToLoad { [ad load]; - OCMVerify(ClassMethod([interstitialClassMock loadWithAdManagerAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadRequest] - completionHandler:[OCMArg any]])); - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]); + OCMVerify(ClassMethod([interstitialClassMock + loadWithAdManagerAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadRequest] + completionHandler:[OCMArg any]])); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m index fbebd24e7..5cccc781f 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m @@ -35,19 +35,20 @@ @implementation FLTGoogleMobileAdsTest { - (void)setUp { _mockMessenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger)); - _manager = [[FLTAdInstanceManager alloc] initWithBinaryMessenger:_mockMessenger]; + _manager = + [[FLTAdInstanceManager alloc] initWithBinaryMessenger:_mockMessenger]; _methodCodec = [FlutterStandardMethodCodec codecWithReaderWriter:[[FLTGoogleMobileAdsReaderWriter alloc] init]]; } - (void)testAdInstanceManagerLoadAd { FLTAdSize *size = [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)]; - FLTBannerAd *bannerAd = - [[FLTBannerAd alloc] initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@1]; + FLTBannerAd *bannerAd = [[FLTBannerAd alloc] + initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@1]; FLTBannerAd *mockBannerAd = OCMPartialMock(bannerAd); OCMStub([mockBannerAd load]); @@ -61,12 +62,12 @@ - (void)testAdInstanceManagerLoadAd { - (void)testAdInstanceManagerDisposeAd { FLTAdSize *size = [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)]; - FLTBannerAd *bannerAd = - [[FLTBannerAd alloc] initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@1]; + FLTBannerAd *bannerAd = [[FLTBannerAd alloc] + initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@1]; FLTBannerAd *mockBannerAd = OCMPartialMock(bannerAd); OCMStub([mockBannerAd load]); @@ -79,21 +80,21 @@ - (void)testAdInstanceManagerDisposeAd { - (void)testAdInstanceManagerDisposeAllAds { FLTAdSize *size = [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)]; - FLTBannerAd *bannerAd1 = - [[FLTBannerAd alloc] initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@1]; + FLTBannerAd *bannerAd1 = [[FLTBannerAd alloc] + initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@1]; FLTBannerAd *mockBannerAd1 = OCMPartialMock(bannerAd1); OCMStub([mockBannerAd1 load]); - FLTBannerAd *bannerAd2 = - [[FLTBannerAd alloc] initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@2]; + FLTBannerAd *bannerAd2 = [[FLTBannerAd alloc] + initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@2]; FLTBannerAd *mockBannerAd2 = OCMPartialMock(bannerAd2); OCMStub([mockBannerAd2 load]); @@ -108,15 +109,15 @@ - (void)testAdInstanceManagerDisposeAllAds { } - (void)testAdInstanceManagerOnAdLoaded { - FLTNativeAd *ad = - [[FLTNativeAd alloc] initWithAdUnitId:@"testAdUnitId" - request:[[FLTAdRequest alloc] init] - nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) - customOptions:nil - rootViewController:OCMClassMock([UIViewController class]) - adId:@1 - nativeAdOptions:nil - nativeTemplateStyle:nil]; + FLTNativeAd *ad = [[FLTNativeAd alloc] + initWithAdUnitId:@"testAdUnitId" + request:[[FLTAdRequest alloc] init] + nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) + customOptions:nil + rootViewController:OCMClassMock([UIViewController class]) + adId:@1 + nativeAdOptions:nil + nativeTemplateStyle:nil]; [_manager loadAd:ad]; GADResponseInfo *responseInfo = OCMClassMock([GADResponseInfo class]); @@ -124,25 +125,26 @@ - (void)testAdInstanceManagerOnAdLoaded { [[FLTGADResponseInfo alloc] initWithResponseInfo:responseInfo]; [_manager onAdLoaded:ad responseInfo:responseInfo]; NSData *data = [_methodCodec - encodeMethodCall:[FlutterMethodCall methodCallWithMethodName:@"onAdEvent" - arguments:@{ - @"adId" : @1, - @"eventName" : @"onAdLoaded", - @"responseInfo" : fltResponseInfo, - }]]; + encodeMethodCall:[FlutterMethodCall + methodCallWithMethodName:@"onAdEvent" + arguments:@{ + @"adId" : @1, + @"eventName" : @"onAdLoaded", + @"responseInfo" : fltResponseInfo, + }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); } - (void)testAdInstanceManagerOnAdFailedToLoad { - FLTNativeAd *ad = - [[FLTNativeAd alloc] initWithAdUnitId:@"testAdUnitId" - request:[[FLTAdRequest alloc] init] - nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) - customOptions:nil - rootViewController:OCMClassMock([UIViewController class]) - adId:@1 - nativeAdOptions:nil - nativeTemplateStyle:nil]; + FLTNativeAd *ad = [[FLTNativeAd alloc] + initWithAdUnitId:@"testAdUnitId" + request:[[FLTAdRequest alloc] init] + nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) + customOptions:nil + rootViewController:OCMClassMock([UIViewController class]) + adId:@1 + nativeAdOptions:nil + nativeTemplateStyle:nil]; [_manager loadAd:ad]; NSDictionary *userInfo = @{NSLocalizedDescriptionKey : @"message"}; @@ -151,12 +153,13 @@ - (void)testAdInstanceManagerOnAdFailedToLoad { FLTLoadAdError *loadAdError = [[FLTLoadAdError alloc] initWithError:error]; [_manager onAdFailedToLoad:ad error:error]; NSData *data = [_methodCodec - encodeMethodCall:[FlutterMethodCall methodCallWithMethodName:@"onAdEvent" - arguments:@{ - @"adId" : @1, - @"eventName" : @"onAdFailedToLoad", - @"loadAdError" : loadAdError, - }]]; + encodeMethodCall:[FlutterMethodCall + methodCallWithMethodName:@"onAdEvent" + arguments:@{ + @"adId" : @1, + @"eventName" : @"onAdFailedToLoad", + @"loadAdError" : loadAdError, + }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); } @@ -174,44 +177,50 @@ - (void)testAdInstanceManagerOnAdFailedToShow { methodCallWithMethodName:@"onAdEvent" arguments:@{ @"adId" : @1, - @"eventName" : @"didFailToPresentFullScreenCon" - @"tentWithError", + @"eventName" : + @"didFailToPresentFullScreenCon" + @"tentWithError", @"error" : error, }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); } - (void)testAdInstanceManagerOnAppEvent { - FLTNativeAd *ad = - [[FLTNativeAd alloc] initWithAdUnitId:@"testAdUnitId" - request:[[FLTAdRequest alloc] init] - nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) - customOptions:nil - rootViewController:OCMClassMock([UIViewController class]) - adId:@1 - nativeAdOptions:nil - nativeTemplateStyle:nil]; - FlutterMethodChannel *mockMethodChannel = OCMClassMock([FlutterMethodChannel class]); + FLTNativeAd *ad = [[FLTNativeAd alloc] + initWithAdUnitId:@"testAdUnitId" + request:[[FLTAdRequest alloc] init] + nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) + customOptions:nil + rootViewController:OCMClassMock([UIViewController class]) + adId:@1 + nativeAdOptions:nil + nativeTemplateStyle:nil]; + FlutterMethodChannel *mockMethodChannel = + OCMClassMock([FlutterMethodChannel class]); [_manager setValue:mockMethodChannel forKey:@"_channel"]; [_manager loadAd:ad]; [_manager onAppEvent:ad name:@"color" data:@"red"]; - NSDictionary *arguments = - @{@"adId" : @1, @"eventName" : @"onAppEvent", @"name" : @"color", @"data" : @"red"}; + NSDictionary *arguments = @{ + @"adId" : @1, + @"eventName" : @"onAppEvent", + @"name" : @"color", + @"data" : @"red" + }; OCMVerify([mockMethodChannel invokeMethod:@"onAdEvent" arguments:arguments]); } - (void)testAdInstanceManagerOnNativeAdEvents { - FLTNativeAd *ad = - [[FLTNativeAd alloc] initWithAdUnitId:@"testAdUnitId" - request:[[FLTAdRequest alloc] init] - nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) - customOptions:nil - rootViewController:OCMClassMock([UIViewController class]) - adId:@1 - nativeAdOptions:nil - nativeTemplateStyle:nil]; + FLTNativeAd *ad = [[FLTNativeAd alloc] + initWithAdUnitId:@"testAdUnitId" + request:[[FLTAdRequest alloc] init] + nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) + customOptions:nil + rootViewController:OCMClassMock([UIViewController class]) + adId:@1 + nativeAdOptions:nil + nativeTemplateStyle:nil]; [_manager loadAd:ad]; [_manager adDidRecordClick:ad]; @@ -219,78 +228,89 @@ - (void)testAdInstanceManagerOnNativeAdEvents { OCMVerify([_mockMessenger sendOnChannel:channel message:clickData]); [_manager onNativeAdImpression:ad]; - NSData *impressionData = [self getDataForEvent:@"onNativeAdImpression" adId:@1]; + NSData *impressionData = [self getDataForEvent:@"onNativeAdImpression" + adId:@1]; OCMVerify([_mockMessenger sendOnChannel:channel message:impressionData]); [_manager onNativeAdWillPresentScreen:ad]; - NSData *presentScreenData = [self getDataForEvent:@"onNativeAdWillPresentScreen" adId:@1]; + NSData *presentScreenData = + [self getDataForEvent:@"onNativeAdWillPresentScreen" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:presentScreenData])); [_manager onNativeAdDidDismissScreen:ad]; - NSData *didDismissData = [self getDataForEvent:@"onNativeAdDidDismissScreen" adId:@1]; + NSData *didDismissData = [self getDataForEvent:@"onNativeAdDidDismissScreen" + adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didDismissData])); [_manager onNativeAdWillDismissScreen:ad]; - NSData *willDismissData = [self getDataForEvent:@"onNativeAdWillDismissScreen" adId:@1]; + NSData *willDismissData = [self getDataForEvent:@"onNativeAdWillDismissScreen" + adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:willDismissData])); } - (void)testAdInstanceManagerOnRewardedAdUserEarnedReward { - FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + FLTRewardedAd *ad = [[FLTRewardedAd alloc] + initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager loadAd:ad]; [_manager onRewardedAdUserEarnedReward:ad - reward:[[FLTRewardItem alloc] initWithAmount:@(1) type:@"type"]]; + reward:[[FLTRewardItem alloc] + initWithAmount:@(1) + type:@"type"]]; NSData *data = [_methodCodec encodeMethodCall:[FlutterMethodCall methodCallWithMethodName:@"onAdEvent" arguments:@{ @"adId" : @1, - @"eventName" : @"onRewardedAdUserEarnedReward", + @"eventName" : + @"onRewardedAdUserEarnedReward", @"rewardItem" : - [[FLTRewardItem alloc] initWithAmount:@(1) - type:@"type"] + [[FLTRewardItem alloc] + initWithAmount:@(1) + type:@"type"] }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); } - (void)testAdInstanceManagerOnRewardedInterstitialAdUserEarnedReward { - FLTRewardedInterstitialAd *ad = - [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] + initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager loadAd:ad]; [_manager onRewardedInterstitialAdUserEarnedReward:ad - reward:[[FLTRewardItem alloc] initWithAmount:@(1) - type:@"type"]]; + reward:[[FLTRewardItem alloc] + initWithAmount:@(1) + type:@"type"]]; NSData *data = [_methodCodec - encodeMethodCall:[FlutterMethodCall - methodCallWithMethodName:@"onAdEvent" - arguments:@{ - @"adId" : @1, - @"eventName" : - @"onRewardedInterstitialAdUserEarnedReward", - @"rewardItem" : - [[FLTRewardItem alloc] initWithAmount:@(1) - type:@"type"] - }]]; + encodeMethodCall: + [FlutterMethodCall + methodCallWithMethodName:@"onAdEvent" + arguments:@{ + @"adId" : @1, + @"eventName" : + @"onRewardedInterstitialAdUserEarnedReward", + @"rewardItem" : [[FLTRewardItem alloc] + initWithAmount:@(1) + type:@"type"] + }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); } - (void)testAdInstanceManagerOnPaidEvent { - FLTNativeAd *ad = - [[FLTNativeAd alloc] initWithAdUnitId:@"testAdUnitId" - request:[[FLTAdRequest alloc] init] - nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) - customOptions:nil - rootViewController:OCMClassMock([UIViewController class]) - adId:@1 - nativeAdOptions:nil - nativeTemplateStyle:nil]; + FLTNativeAd *ad = [[FLTNativeAd alloc] + initWithAdUnitId:@"testAdUnitId" + request:[[FLTAdRequest alloc] init] + nativeAdFactory:OCMProtocolMock(@protocol(FLTNativeAdFactory)) + customOptions:nil + rootViewController:OCMClassMock([UIViewController class]) + adId:@1 + nativeAdOptions:nil + nativeTemplateStyle:nil]; [_manager loadAd:ad]; NSDecimalNumber *valueDecimal = [[NSDecimalNumber alloc] initWithInt:1]; @@ -306,7 +326,8 @@ - (void)testAdInstanceManagerOnPaidEvent { @"adId" : @1, @"eventName" : @"onPaidEvent", @"valueMicros" : value.valueMicros, - @"precision" : [NSNumber numberWithInteger:12], + @"precision" : + [NSNumber numberWithInteger:12], @"currencyCode" : @"code" }]]; OCMVerify([_mockMessenger sendOnChannel:channel message:data]); @@ -314,11 +335,12 @@ - (void)testAdInstanceManagerOnPaidEvent { - (void)testBannerEvents { FLTAdSize *size = [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)]; - FLTBannerAd *ad = [[FLTBannerAd alloc] initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@1]; + FLTBannerAd *ad = [[FLTBannerAd alloc] + initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@1]; FLTBannerAd *mockBannerAd = OCMPartialMock(ad); OCMStub([mockBannerAd load]); @@ -329,73 +351,86 @@ - (void)testBannerEvents { OCMVerify(([_mockMessenger sendOnChannel:channel message:impressionData])); [_manager onBannerWillDismissScreen:ad]; - NSData *willDismissData = [self getDataForEvent:@"onBannerWillDismissScreen" adId:@1]; + NSData *willDismissData = [self getDataForEvent:@"onBannerWillDismissScreen" + adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:willDismissData])); [_manager onBannerDidDismissScreen:ad]; - NSData *didDismissData = [self getDataForEvent:@"onBannerDidDismissScreen" adId:@1]; + NSData *didDismissData = [self getDataForEvent:@"onBannerDidDismissScreen" + adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didDismissData])); [_manager onBannerWillPresentScreen:ad]; - NSData *willPresentData = [self getDataForEvent:@"onBannerWillPresentScreen" adId:@1]; + NSData *willPresentData = [self getDataForEvent:@"onBannerWillPresentScreen" + adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:willPresentData])); } - (void)testFullScreenEventsRewardedAd { - FLTRewardedAd *rewardedAd = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + FLTRewardedAd *rewardedAd = [[FLTRewardedAd alloc] + initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager loadAd:rewardedAd]; [_manager adWillPresentFullScreenContent:rewardedAd]; - NSData *didPresentData = [self getDataForEvent:@"adWillPresentFullScreenContent" adId:@1]; + NSData *didPresentData = + [self getDataForEvent:@"adWillPresentFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didPresentData])); [_manager adDidDismissFullScreenContent:rewardedAd]; - NSData *didDismissData = [self getDataForEvent:@"adDidDismissFullScreenContent" adId:@1]; + NSData *didDismissData = + [self getDataForEvent:@"adDidDismissFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didDismissData])); [_manager adWillDismissFullScreenContent:rewardedAd]; - NSData *willDismissData = [self getDataForEvent:@"adWillDismissFullScreenContent" adId:@1]; + NSData *willDismissData = + [self getDataForEvent:@"adWillDismissFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:willDismissData])); [_manager adDidRecordImpression:rewardedAd]; - NSData *impressionData = [self getDataForEvent:@"adDidRecordImpression" adId:@1]; + NSData *impressionData = [self getDataForEvent:@"adDidRecordImpression" + adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:impressionData])); } - (void)testFullScreenEventsRewardedInterstitialAd { FLTRewardedInterstitialAd *rewardedInterstitialAd = - [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + [[FLTRewardedInterstitialAd alloc] + initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager loadAd:rewardedInterstitialAd]; [_manager adWillPresentFullScreenContent:rewardedInterstitialAd]; - NSData *didPresentData = [self getDataForEvent:@"adWillPresentFullScreenContent" adId:@1]; + NSData *didPresentData = + [self getDataForEvent:@"adWillPresentFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didPresentData])); [_manager adDidDismissFullScreenContent:rewardedInterstitialAd]; - NSData *didDismissData = [self getDataForEvent:@"adDidDismissFullScreenContent" adId:@1]; + NSData *didDismissData = + [self getDataForEvent:@"adDidDismissFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:didDismissData])); [_manager adWillDismissFullScreenContent:rewardedInterstitialAd]; - NSData *willDismissData = [self getDataForEvent:@"adWillDismissFullScreenContent" adId:@1]; + NSData *willDismissData = + [self getDataForEvent:@"adWillDismissFullScreenContent" adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:willDismissData])); [_manager adDidRecordImpression:rewardedInterstitialAd]; - NSData *impressionData = [self getDataForEvent:@"adDidRecordImpression" adId:@1]; + NSData *impressionData = [self getDataForEvent:@"adDidRecordImpression" + adId:@1]; OCMVerify(([_mockMessenger sendOnChannel:channel message:impressionData])); } - (void)testEventSentForDisposedAd { FLTAdSize *size = [[FLTAdSize alloc] initWithWidth:@(1) height:@(2)]; - FLTBannerAd *bannerAd = - [[FLTBannerAd alloc] initWithAdUnitId:@"testId" - size:size - request:[[FLTAdRequest alloc] init] - rootViewController:OCMClassMock([UIViewController class]) - adId:@1]; + FLTBannerAd *bannerAd = [[FLTBannerAd alloc] + initWithAdUnitId:@"testId" + size:size + request:[[FLTAdRequest alloc] init] + rootViewController:OCMClassMock([UIViewController class]) + adId:@1]; FLTBannerAd *mockBannerAd = OCMPartialMock(bannerAd); OCMStub([mockBannerAd load]); @@ -415,16 +450,19 @@ - (void)testEventSentForDisposedAd { // Helper method to create encoded data for an event and ad id. - (NSData *)getDataForEvent:(NSString *)name adId:(NSNumber *)adId { return [_methodCodec - encodeMethodCall:[FlutterMethodCall - methodCallWithMethodName:@"onAdEvent" - arguments:@{@"adId" : @1, @"eventName" : name}]]; + encodeMethodCall:[FlutterMethodCall methodCallWithMethodName:@"onAdEvent" + arguments:@{ + @"adId" : @1, + @"eventName" : name + }]]; } - (void)testAdClick { FLTRewardedInterstitialAd *rewardedInterstitialAd = - [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + [[FLTRewardedInterstitialAd alloc] + initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager adDidRecordClick:rewardedInterstitialAd]; NSData *impressionData = [self getDataForEvent:@"adDidRecordClick" adId:@1]; diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m index 6b4bf4654..02819d7f3 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m @@ -35,10 +35,12 @@ - (void)testLoadShowInterstitialAd { GADRequest *gadRequest = OCMClassMock([GADRequest class]); OCMStub([request asGADRequest:[OCMArg any]]).andReturn(gadRequest); - UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); - FLTInterstitialAd *ad = [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + UIViewController *mockRootViewController = + OCMClassMock([UIViewController class]); + FLTInterstitialAd *ad = + [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id interstitialClassMock = OCMClassMock([GADInterstitialAd class]); @@ -61,7 +63,8 @@ - (void)testLoadShowInterstitialAd { [delegate adDidDismissFullScreenContent:interstitialClassMock]; [delegate adWillPresentFullScreenContent:interstitialClassMock]; [delegate adWillDismissFullScreenContent:interstitialClassMock]; - [delegate ad:interstitialClassMock didFailToPresentFullScreenContentWithError:error]; + [delegate ad:interstitialClassMock + didFailToPresentFullScreenContentWithError:error]; }); GADResponseInfo *mockResponseInfo = OCMClassMock([GADResponseInfo class]); @@ -72,31 +75,35 @@ - (void)testLoadShowInterstitialAd { OCMStub([adValue value]).andReturn(NSDecimalNumber.one); OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated); OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); - OCMStub([interstitialClassMock setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - GADPaidEventHandler handler = obj; - handler(adValue); - return YES; - }]]); + OCMStub([interstitialClassMock + setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + GADPaidEventHandler handler = obj; + handler(adValue); + return YES; + }]]); // Call load and verify interactions with mocks. [ad load]; - OCMVerify(ClassMethod([interstitialClassMock loadWithAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadRequest] - completionHandler:[OCMArg any]])); + OCMVerify(ClassMethod([interstitialClassMock + loadWithAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadRequest] + completionHandler:[OCMArg any]])); OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad] responseInfo:[OCMArg isEqual:mockResponseInfo]]); - OCMVerify([interstitialClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); + OCMVerify( + [interstitialClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); XCTAssertEqual(ad.interstitial, interstitialClassMock); - OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager + onPaidEvent:[OCMArg isEqual:ad] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); // Show the ad [ad showFromRootViewController:mockRootViewController]; @@ -110,8 +117,9 @@ - (void)testLoadShowInterstitialAd { OCMVerify([mockManager adWillDismissFullScreenContent:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordImpression:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:ad]]); - OCMVerify([mockManager didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager + didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); } - (void)testFailedToLoad { @@ -120,9 +128,10 @@ - (void)testFailedToLoad { GADRequest *gadRequest = OCMClassMock([GADRequest class]); OCMStub([request asGADRequest:[OCMArg any]]).andReturn(gadRequest); - FLTInterstitialAd *ad = [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + FLTInterstitialAd *ad = + [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id interstitialClassMock = OCMClassMock([GADInterstitialAd class]); @@ -138,10 +147,12 @@ - (void)testFailedToLoad { [ad load]; - OCMVerify(ClassMethod([interstitialClassMock loadWithAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadRequest] - completionHandler:[OCMArg any]])); - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]); + OCMVerify(ClassMethod([interstitialClassMock + loadWithAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadRequest] + completionHandler:[OCMArg any]])); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m index d7c36cfc4..a64936b57 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m @@ -50,8 +50,12 @@ - (void)testLoadShowRewardedAdGAMRequest { // Helper method for testing with FLTAdRequest and FLTGAMAdRequest. - (void)testLoadShowRewardedAd:(FLTAdRequest *)request gadOrGAMRequest:(GADRequest *)gadOrGAMRequest { - UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); - FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" request:request adId:@1]; + UIViewController *mockRootViewController = + OCMClassMock([UIViewController class]); + FLTRewardedAd *ad = + [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; // Stub the load call to invoke successful load callback. @@ -92,11 +96,12 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request OCMStub([adValue value]).andReturn(NSDecimalNumber.one); OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated); OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); - OCMStub([rewardedClassMock setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - GADPaidEventHandler handler = obj; - handler(adValue); - return YES; - }]]); + OCMStub([rewardedClassMock + setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + GADPaidEventHandler handler = obj; + handler(adValue); + return YES; + }]]); // Setup mock for UIApplication.sharedInstance id uiApplicationClassMock = OCMClassMock([UIApplication class]); @@ -106,40 +111,46 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request // Call load and check expected interactions with mocks. [ad load]; - OCMVerify(ClassMethod([rewardedClassMock loadWithAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadOrGAMRequest] - completionHandler:[OCMArg any]])); + OCMVerify(ClassMethod([rewardedClassMock + loadWithAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadOrGAMRequest] + completionHandler:[OCMArg any]])); OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad] responseInfo:[OCMArg isEqual:responseInfo]]); - OCMVerify([rewardedClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); + OCMVerify( + [rewardedClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); XCTAssertEqual(ad.rewardedAd, rewardedClassMock); - OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([mockManager + onPaidEvent:[OCMArg isEqual:ad] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); // Set SSV and verify interactions with mocks FLTServerSideVerificationOptions *serverSideVerificationOptions = OCMClassMock([FLTServerSideVerificationOptions class]); GADServerSideVerificationOptions *gadOptions = OCMClassMock([GADServerSideVerificationOptions class]); - OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]).andReturn(gadOptions); + OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]) + .andReturn(gadOptions); [ad setServerSideVerificationOptions:serverSideVerificationOptions]; - OCMVerify([rewardedClassMock setServerSideVerificationOptions:[OCMArg isEqual:gadOptions]]); + OCMVerify([rewardedClassMock + setServerSideVerificationOptions:[OCMArg isEqual:gadOptions]]); // Show the ad and verify callbacks invoked [ad showFromRootViewController:mockRootViewController]; - OCMVerify([rewardedClassMock presentFromRootViewController:[OCMArg isEqual:mockRootViewController] - userDidEarnRewardHandler:[OCMArg any]]); + OCMVerify([rewardedClassMock + presentFromRootViewController:[OCMArg isEqual:mockRootViewController] + userDidEarnRewardHandler:[OCMArg any]]); [fullScreenContentDelegate adWillPresentFullScreenContent:rewardedClassMock]; OCMVerify([mockManager adWillPresentFullScreenContent:[OCMArg isEqual:ad]]); @@ -166,17 +177,19 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request #pragma clang diagnostic pop [ad ad:rewardedClassMock didFailToPresentFullScreenContentWithError:error]; - OCMVerify([mockManager didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager + didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); // Verify reward callback. - OCMVerify([mockManager onRewardedAdUserEarnedReward:[OCMArg isEqual:ad] - reward:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTRewardItem *reward = (FLTRewardItem *)obj; - XCTAssertEqual(reward.amount, @1.0); - XCTAssertEqual(reward.type, @"type"); - return true; - }]]); + OCMVerify([mockManager + onRewardedAdUserEarnedReward:[OCMArg isEqual:ad] + reward:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTRewardItem *reward = (FLTRewardItem *)obj; + XCTAssertEqual(reward.amount, @1.0); + XCTAssertEqual(reward.type, @"type"); + return true; + }]]); // Explicitly stop mocking. There is an issue when running tests on Github // actions where the mock does not get deallocated properly, so without this @@ -202,7 +215,10 @@ - (void)testFailedToLoadGAMRequest { // Helper for testing failed to load. - (void)testFailedToLoad:(FLTAdRequest *)request { - FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" request:request adId:@1]; + FLTRewardedAd *ad = + [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id rewardedClassMock = OCMClassMock([GADRewardedAd class]); @@ -221,7 +237,8 @@ - (void)testFailedToLoad:(FLTAdRequest *)request { OCMVerify(ClassMethod([rewardedClassMock loadWithAdUnitID:[OCMArg any] request:[OCMArg any] completionHandler:[OCMArg any]])); - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); } @end diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m index a732ef9b8..261a9e049 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m @@ -50,25 +50,31 @@ - (void)testLoadShowRewardedInterstitialAdGAMRequest { // Helper method for testing with FLTAdRequest and FLTGAMAdRequest. - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request gadOrGAMRequest:(GADRequest *)gadOrGAMRequest { - UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); - FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + UIViewController *mockRootViewController = + OCMClassMock([UIViewController class]); + FLTRewardedInterstitialAd *ad = + [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; // Stub the load call to invoke successful load callback. - id rewardedInterstitialClassMock = OCMClassMock([GADRewardedInterstitialAd class]); - OCMStub(ClassMethod([rewardedInterstitialClassMock loadWithAdUnitID:[OCMArg any] - request:[OCMArg any] - completionHandler:[OCMArg any]])) + id rewardedInterstitialClassMock = + OCMClassMock([GADRewardedInterstitialAd class]); + OCMStub(ClassMethod([rewardedInterstitialClassMock + loadWithAdUnitID:[OCMArg any] + request:[OCMArg any] + completionHandler:[OCMArg any]])) .andDo(^(NSInvocation *invocation) { - void (^completionHandler)(GADRewardedInterstitialAd *ad, NSError *error); + void (^completionHandler)(GADRewardedInterstitialAd *ad, + NSError *error); [invocation getArgument:&completionHandler atIndex:4]; completionHandler(rewardedInterstitialClassMock, nil); }); // Stub setting of FullScreenContentDelegate to invoke delegate callbacks. NSError *error = OCMClassMock([NSError class]); - OCMStub([rewardedInterstitialClassMock setFullScreenContentDelegate:[OCMArg any]]) + OCMStub( + [rewardedInterstitialClassMock setFullScreenContentDelegate:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { id delegate; [invocation getArgument:&delegate atIndex:2]; @@ -88,8 +94,9 @@ - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request OCMStub([mockReward amount]).andReturn(@1.0); OCMStub([mockReward type]).andReturn(@"type"); OCMStub([rewardedInterstitialClassMock adReward]).andReturn(mockReward); - OCMStub([rewardedInterstitialClassMock presentFromRootViewController:[OCMArg any] - userDidEarnRewardHandler:[OCMArg any]]) + OCMStub([rewardedInterstitialClassMock + presentFromRootViewController:[OCMArg any] + userDidEarnRewardHandler:[OCMArg any]]) .andDo(^(NSInvocation *invocation) { GADUserDidEarnRewardHandler rewardHandler; [invocation getArgument:&rewardHandler atIndex:3]; @@ -101,43 +108,47 @@ - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request OCMStub([adValue value]).andReturn(NSDecimalNumber.one); OCMStub([adValue precision]).andReturn(GADAdValuePrecisionEstimated); OCMStub([adValue currencyCode]).andReturn(@"currencyCode"); - OCMStub([rewardedInterstitialClassMock setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { - GADPaidEventHandler handler = obj; - handler(adValue); - return YES; - }]]); + OCMStub([rewardedInterstitialClassMock + setPaidEventHandler:[OCMArg checkWithBlock:^BOOL(id obj) { + GADPaidEventHandler handler = obj; + handler(adValue); + return YES; + }]]); // Call load and check expected interactions with mocks. [ad load]; - OCMVerify( - ClassMethod([rewardedInterstitialClassMock loadWithAdUnitID:[OCMArg isEqual:@"testId"] - request:[OCMArg isEqual:gadOrGAMRequest] - completionHandler:[OCMArg any]])); + OCMVerify(ClassMethod([rewardedInterstitialClassMock + loadWithAdUnitID:[OCMArg isEqual:@"testId"] + request:[OCMArg isEqual:gadOrGAMRequest] + completionHandler:[OCMArg any]])); OCMVerify([mockManager onAdLoaded:[OCMArg isEqual:ad] responseInfo:[OCMArg isEqual:responseInfo]]); - OCMVerify([rewardedInterstitialClassMock setFullScreenContentDelegate:[OCMArg isEqual:ad]]); - OCMVerify([mockManager onPaidEvent:[OCMArg isEqual:ad] - value:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTAdValue *adValue = obj; - XCTAssertEqualObjects( - adValue.valueMicros, - [[NSDecimalNumber alloc] initWithInt:1000000]); - XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); - XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); - return TRUE; - }]]); + OCMVerify([rewardedInterstitialClassMock + setFullScreenContentDelegate:[OCMArg isEqual:ad]]); + OCMVerify([mockManager + onPaidEvent:[OCMArg isEqual:ad] + value:[OCMArg checkWithBlock:^BOOL(id obj) { + FLTAdValue *adValue = obj; + XCTAssertEqualObjects( + adValue.valueMicros, + [[NSDecimalNumber alloc] initWithInt:1000000]); + XCTAssertEqual(adValue.precision, GADAdValuePrecisionEstimated); + XCTAssertEqualObjects(adValue.currencyCode, @"currencyCode"); + return TRUE; + }]]); // Set SSV and verify interactions with mocks FLTServerSideVerificationOptions *serverSideVerificationOptions = OCMClassMock([FLTServerSideVerificationOptions class]); GADServerSideVerificationOptions *gadOptions = OCMClassMock([GADServerSideVerificationOptions class]); - OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]).andReturn(gadOptions); + OCMStub([serverSideVerificationOptions asGADServerSideVerificationOptions]) + .andReturn(gadOptions); [ad setServerSideVerificationOptions:serverSideVerificationOptions]; - OCMVerify( - [rewardedInterstitialClassMock setServerSideVerificationOptions:[OCMArg isEqual:gadOptions]]); + OCMVerify([rewardedInterstitialClassMock + setServerSideVerificationOptions:[OCMArg isEqual:gadOptions]]); // Show the ad and verify callbacks are invoked [ad showFromRootViewController:mockRootViewController]; @@ -152,14 +163,17 @@ - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request OCMVerify([mockManager adWillDismissFullScreenContent:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordImpression:[OCMArg isEqual:ad]]); OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:ad]]); - OCMVerify([mockManager didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] - error:[OCMArg isEqual:error]]); + OCMVerify([mockManager + didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); // Verify reward callback. OCMVerify([mockManager onRewardedInterstitialAdUserEarnedReward:[OCMArg isEqual:ad] - reward:[OCMArg checkWithBlock:^BOOL(id obj) { - FLTRewardItem *reward = (FLTRewardItem *)obj; + reward:[OCMArg checkWithBlock:^BOOL( + id obj) { + FLTRewardItem *reward = + (FLTRewardItem *)obj; XCTAssertEqual(reward.amount, @1.0); XCTAssertEqual(reward.type, @"type"); return true; @@ -187,28 +201,34 @@ - (void)testFailedToLoadGAMRequest { // Helper for testing failed to load. - (void)testFailedToLoad:(FLTAdRequest *)request { - FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + FLTRewardedInterstitialAd *ad = + [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; - id rewardedInterstitialClassMock = OCMClassMock([GADRewardedInterstitialAd class]); + id rewardedInterstitialClassMock = + OCMClassMock([GADRewardedInterstitialAd class]); NSError *error = OCMClassMock([NSError class]); - OCMStub(ClassMethod([rewardedInterstitialClassMock loadWithAdUnitID:[OCMArg any] - request:[OCMArg any] - completionHandler:[OCMArg any]])) + OCMStub(ClassMethod([rewardedInterstitialClassMock + loadWithAdUnitID:[OCMArg any] + request:[OCMArg any] + completionHandler:[OCMArg any]])) .andDo(^(NSInvocation *invocation) { - void (^completionHandler)(GADRewardedInterstitialAd *ad, NSError *error); + void (^completionHandler)(GADRewardedInterstitialAd *ad, + NSError *error); [invocation getArgument:&completionHandler atIndex:4]; completionHandler(nil, error); }); [ad load]; - OCMVerify(ClassMethod([rewardedInterstitialClassMock loadWithAdUnitID:[OCMArg any] - request:[OCMArg any] - completionHandler:[OCMArg any]])); - OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] error:[OCMArg isEqual:error]]); + OCMVerify(ClassMethod([rewardedInterstitialClassMock + loadWithAdUnitID:[OCMArg any] + request:[OCMArg any] + completionHandler:[OCMArg any]])); + OCMVerify([mockManager onAdFailedToLoad:[OCMArg isEqual:ad] + error:[OCMArg isEqual:error]]); } @end diff --git a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h index 2f3662c9e..1ddf4096e 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h +++ b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import #import "FLTAd_Internal.h" #import "FLTGoogleMobileAdsCollection_Internal.h" #import "FLTGoogleMobileAdsReaderWriter_Internal.h" +#import @protocol FLTAd; @class FLTBannerAd; @@ -33,8 +33,9 @@ - (void)loadAd:(id _Nonnull)ad; - (void)dispose:(NSNumber *_Nonnull)adId; - (void)showAdWithID:(NSNumber *_Nonnull)adId - rootViewController:(UIViewController *_Nonnull)rootViewController; -- (void)onAdLoaded:(id _Nonnull)ad responseInfo:(GADResponseInfo *_Nonnull)responseInfo; + rootViewController:(UIViewController *_Nonnull)rootViewController; +- (void)onAdLoaded:(id _Nonnull)ad + responseInfo:(GADResponseInfo *_Nonnull)responseInfo; - (void)onAdFailedToLoad:(id _Nonnull)ad error:(NSError *_Nonnull)error; - (void)onAppEvent:(id _Nonnull)ad name:(NSString *_Nullable)name @@ -45,8 +46,10 @@ - (void)onNativeAdWillDismissScreen:(FLTNativeAd *_Nonnull)ad; - (void)onRewardedAdUserEarnedReward:(FLTRewardedAd *_Nonnull)ad reward:(FLTRewardItem *_Nonnull)reward; -- (void)onRewardedInterstitialAdUserEarnedReward:(FLTRewardedInterstitialAd *_Nonnull)ad - reward:(FLTRewardItem *_Nonnull)reward; +- (void)onRewardedInterstitialAdUserEarnedReward: + (FLTRewardedInterstitialAd *_Nonnull)ad + reward: + (FLTRewardItem *_Nonnull)reward; - (void)onPaidEvent:(id _Nonnull)ad value:(FLTAdValue *_Nonnull)value; - (void)onBannerImpression:(FLTBannerAd *_Nonnull)ad; - (void)onBannerWillDismissScreen:(FLTBannerAd *_Nonnull)ad; @@ -64,7 +67,9 @@ - (void)disposeAllAds; @end -@interface FLTNewGoogleMobileAdsViewFactory : NSObject +@interface FLTNewGoogleMobileAdsViewFactory + : NSObject @property(readonly) FLTAdInstanceManager *_Nonnull manager; -- (instancetype _Nonnull)initWithManager:(FLTAdInstanceManager *_Nonnull)manager; +- (instancetype _Nonnull)initWithManager: + (FLTAdInstanceManager *_Nonnull)manager; @end diff --git a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m index e384dc1dd..2ec069c95 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m @@ -26,9 +26,10 @@ - (instancetype _Nonnull)initWithBinaryMessenger: _ads = [[FLTGoogleMobileAdsCollection alloc] init]; NSObject *methodCodec = [FlutterStandardMethodCodec codecWithReaderWriter:[[FLTGoogleMobileAdsReaderWriter alloc] init]]; - _channel = [[FlutterMethodChannel alloc] initWithName:@"plugins.flutter.io/google_mobile_ads" - binaryMessenger:binaryMessenger - codec:methodCodec]; + _channel = [[FlutterMethodChannel alloc] + initWithName:@"plugins.flutter.io/google_mobile_ads" + binaryMessenger:binaryMessenger + codec:methodCodec]; } return self; } @@ -67,7 +68,7 @@ - (void)disposeAllAds { } - (void)showAdWithID:(NSNumber *_Nonnull)adId - rootViewController:(UIViewController *_Nonnull)rootViewController { + rootViewController:(UIViewController *_Nonnull)rootViewController{ id ad = (id)[self adFor:adId]; if (!ad) { @@ -78,12 +79,14 @@ - (void)showAdWithID:(NSNumber *_Nonnull)adId [ad showFromRootViewController:rootViewController]; } -- (void)onAdLoaded:(id _Nonnull)ad responseInfo:(GADResponseInfo *_Nonnull)responseInfo { +- (void)onAdLoaded:(id _Nonnull)ad + responseInfo:(GADResponseInfo *_Nonnull)responseInfo { [_channel invokeMethod:@"onAdEvent" arguments:@{ @"adId" : ad.adId, @"eventName" : @"onAdLoaded", - @"responseInfo" : [[FLTGADResponseInfo alloc] initWithResponseInfo:responseInfo] + @"responseInfo" : [[FLTGADResponseInfo alloc] + initWithResponseInfo:responseInfo] }]; } @@ -96,7 +99,9 @@ - (void)onAdFailedToLoad:(id _Nonnull)ad error:(NSError *_Nonnull)error { }]; } -- (void)onAppEvent:(id _Nonnull)ad name:(NSString *)name data:(NSString *)data { +- (void)onAppEvent:(id _Nonnull)ad + name:(NSString *)name + data:(NSString *)data { [_channel invokeMethod:@"onAdEvent" arguments:@{ @"adId" : ad.adId, @@ -132,8 +137,10 @@ - (void)onRewardedAdUserEarnedReward:(FLTRewardedAd *_Nonnull)ad }]; } -- (void)onRewardedInterstitialAdUserEarnedReward:(FLTRewardedInterstitialAd *_Nonnull)ad - reward:(FLTRewardItem *_Nonnull)reward { +- (void)onRewardedInterstitialAdUserEarnedReward: + (FLTRewardedInterstitialAd *_Nonnull)ad + reward: + (FLTRewardItem *_Nonnull)reward { [_channel invokeMethod:@"onAdEvent" arguments:@{ @"adId" : ad.adId, @@ -232,12 +239,17 @@ - (instancetype)initWithManager:(FLTAdInstanceManager *_Nonnull)manager { viewIdentifier:(int64_t)viewId arguments:(id _Nullable)args { NSNumber *adId = args; - NSObject *view = (NSObject *)[_manager adFor:adId]; + NSObject *view = + (NSObject *)[_manager adFor:adId]; if (!view) { NSString *reason = [NSString - stringWithFormat:@"Could not find an ad with id: %@. Was this ad already disposed?", adId]; - @throw [NSException exceptionWithName:NSInvalidArgumentException reason:reason userInfo:nil]; + stringWithFormat: + @"Could not find an ad with id: %@. Was this ad already disposed?", + adId]; + @throw [NSException exceptionWithName:NSInvalidArgumentException + reason:reason + userInfo:nil]; } return view; } diff --git a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h index 09e571ee3..2f3264a56 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h +++ b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#import -#import #import "FLTAdInstanceManager_Internal.h" #import "FLTGoogleMobileAdsPlugin.h" #import "FLTMediationExtras.h" @@ -21,6 +19,8 @@ #import "FLTMobileAds_Internal.h" #import "FLTNativeTemplateStyle.h" #import "GADTTemplateView.h" +#import +#import @class FLTAdInstanceManager; @protocol FLTNativeAdFactory; @@ -29,7 +29,8 @@ @property(readonly) GADAdSize size; @property(readonly) NSNumber *_Nonnull width; @property(readonly) NSNumber *_Nonnull height; -- (instancetype _Nonnull)initWithWidth:(NSNumber *_Nonnull)width height:(NSNumber *_Nonnull)height; +- (instancetype _Nonnull)initWithWidth:(NSNumber *_Nonnull)width + height:(NSNumber *_Nonnull)height; - (instancetype _Nonnull)initWithAdSize:(GADAdSize)size; @end @@ -38,14 +39,22 @@ * Plugin. */ @interface FLTAdSizeFactory : NSObject -- (GADAdSize)portraitAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width; -- (GADAdSize)landscapeAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width; -- (GADAdSize)currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width; -- (GADAdSize)currentOrientationInlineAdaptiveBannerSizeWithWidth:(NSNumber *_Nonnull)width; -- (GADAdSize)portraitOrientationInlineAdaptiveBannerSizeWithWidth:(NSNumber *_Nonnull)width; -- (GADAdSize)landscapeInlineAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width; -- (GADAdSize)inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:(NSNumber *_Nonnull)width - maxHeight:(NSNumber *_Nonnull)maxHeight; +- (GADAdSize)portraitAnchoredAdaptiveBannerAdSizeWithWidth: + (NSNumber *_Nonnull)width; +- (GADAdSize)landscapeAnchoredAdaptiveBannerAdSizeWithWidth: + (NSNumber *_Nonnull)width; +- (GADAdSize)currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth: + (NSNumber *_Nonnull)width; +- (GADAdSize)currentOrientationInlineAdaptiveBannerSizeWithWidth: + (NSNumber *_Nonnull)width; +- (GADAdSize)portraitOrientationInlineAdaptiveBannerSizeWithWidth: + (NSNumber *_Nonnull)width; +- (GADAdSize)landscapeInlineAdaptiveBannerAdSizeWithWidth: + (NSNumber *_Nonnull)width; +- (GADAdSize) + inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:(NSNumber *_Nonnull)width + maxHeight: + (NSNumber *_Nonnull)maxHeight; @end @@ -78,9 +87,10 @@ @property NSString *_Nullable contentURL; @property BOOL nonPersonalizedAds; @property NSArray *_Nullable neighboringContentURLs; -@property NSString *_Nullable mediationExtrasIdentifier DEPRECATED_MSG_ATTRIBUTE( - "Use mediationExtras instead."); -@property id _Nullable mediationNetworkExtrasProvider +@property NSString *_Nullable mediationExtrasIdentifier + DEPRECATED_MSG_ATTRIBUTE("Use mediationExtras instead."); +@property id< + FLTMediationNetworkExtrasProvider> _Nullable mediationNetworkExtrasProvider DEPRECATED_MSG_ATTRIBUTE("Use mediationExtras instead."); @property NSDictionary *_Nullable adMobExtras; @property NSString *_Nonnull requestAgent; @@ -104,7 +114,8 @@ @property NSString *_Nullable adSourceName; @property NSString *_Nullable adSourceInstanceName; -- (instancetype _Nonnull)initWithResponseInfo:(GADAdNetworkResponseInfo *_Nonnull)responseInfo; +- (instancetype _Nonnull)initWithResponseInfo: + (GADAdNetworkResponseInfo *_Nonnull)responseInfo; @end /** @@ -117,7 +128,8 @@ @property FLTGADAdNetworkResponseInfo *_Nullable loadedAdNetworkResponseInfo; @property NSDictionary *_Nullable extrasDictionary; -- (instancetype _Nonnull)initWithResponseInfo:(GADResponseInfo *_Nonnull)responseInfo; +- (instancetype _Nonnull)initWithResponseInfo: + (GADResponseInfo *_Nonnull)responseInfo; @end /** @@ -138,7 +150,8 @@ */ @interface FLTGAMAdRequest : FLTAdRequest @property NSDictionary *_Nullable customTargeting; -@property NSDictionary *> *_Nullable customTargetingLists; +@property NSDictionary *> + *_Nullable customTargetingLists; @property NSString *_Nullable pubProvidedID; - (GAMRequest *_Nonnull)asGAMRequest:(NSString *_Nonnull)adUnitId; @@ -158,11 +171,13 @@ @property(readonly) NSNumber *_Nonnull adId; @end -@interface FLTBannerAd : FLTBaseAd +@interface FLTBannerAd + : FLTBaseAd - (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId size:(FLTAdSize *_Nonnull)size request:(FLTAdRequest *_Nonnull)request - rootViewController:(UIViewController *_Nonnull)rootViewController + rootViewController: + (UIViewController *_Nonnull)rootViewController adId:(NSNumber *_Nonnull)adId; - (FLTAdSize *_Nullable)getAdSize; - (GADBannerView *_Nonnull)bannerView; @@ -175,7 +190,8 @@ - (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId sizes:(NSArray *_Nonnull)sizes request:(FLTGAMAdRequest *_Nonnull)request - rootViewController:(UIViewController *_Nonnull)rootViewController + rootViewController: + (UIViewController *_Nonnull)rootViewController adId:(NSNumber *_Nonnull)adId; @end @@ -186,11 +202,13 @@ @interface FLTFluidGAMBannerAd : FLTGAMBannerAd - (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId request:(FLTGAMAdRequest *_Nonnull)request - rootViewController:(UIViewController *_Nonnull)rootViewController + rootViewController: + (UIViewController *_Nonnull)rootViewController adId:(NSNumber *_Nonnull)adId; @end -@interface FLTFullScreenAd : FLTBaseAd +@interface FLTFullScreenAd + : FLTBaseAd @end @interface FLTInterstitialAd : FLTFullScreenAd @@ -238,9 +256,10 @@ @property(readonly) NSNumber *_Nullable clickToExpandRequested; @property(readonly) NSNumber *_Nullable customControlsRequested; @property(readonly) NSNumber *_Nullable startMuted; -- (instancetype _Nonnull)initWithClickToExpandRequested:(NSNumber *_Nullable)clickToExpandRequested - customControlsRequested:(NSNumber *_Nullable)customControlsRequested - startMuted:(NSNumber *_Nullable)startMuted; +- (instancetype _Nonnull) + initWithClickToExpandRequested:(NSNumber *_Nullable)clickToExpandRequested + customControlsRequested:(NSNumber *_Nullable)customControlsRequested + startMuted:(NSNumber *_Nullable)startMuted; - (GADVideoOptions *_Nonnull)asGADVideoOptions; @end @@ -253,34 +272,39 @@ @property(readonly) NSNumber *_Nullable shouldRequestMultipleImages; @property(readonly) NSNumber *_Nullable shouldReturnUrlsForImageAssets; -- (instancetype _Nonnull)initWithAdChoicesPlacement:(NSNumber *_Nullable)adChoicesPlacement - mediaAspectRatio:(NSNumber *_Nullable)mediaAspectRatio - videoOptions:(FLTVideoOptions *_Nullable)videoOptions - requestCustomMuteThisAd:(NSNumber *_Nullable)requestCustomMuteThisAd - shouldRequestMultipleImages:(NSNumber *_Nullable)shouldRequestMultipleImages - shouldReturnUrlsForImageAssets: - (NSNumber *_Nullable)shouldReturnUrlsForImageAssets; +- (instancetype _Nonnull) + initWithAdChoicesPlacement:(NSNumber *_Nullable)adChoicesPlacement + mediaAspectRatio:(NSNumber *_Nullable)mediaAspectRatio + videoOptions:(FLTVideoOptions *_Nullable)videoOptions + requestCustomMuteThisAd:(NSNumber *_Nullable)requestCustomMuteThisAd + shouldRequestMultipleImages: + (NSNumber *_Nullable)shouldRequestMultipleImages + shouldReturnUrlsForImageAssets: + (NSNumber *_Nullable)shouldReturnUrlsForImageAssets; - (NSArray *_Nonnull)asGADAdLoaderOptions; @end @interface FLTNativeAd - : FLTBaseAd -- (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId - request:(FLTAdRequest *_Nonnull)request - nativeAdFactory:(NSObject *_Nonnull)nativeAdFactory - customOptions:(NSDictionary *_Nullable)customOptions - rootViewController:(UIViewController *_Nonnull)rootViewController - adId:(NSNumber *_Nonnull)adId - nativeAdOptions:(FLTNativeAdOptions *_Nullable)nativeAdOptions - nativeTemplateStyle:(FLTNativeTemplateStyle *_Nullable)nativeTemplateStyle; + : FLTBaseAd +- (instancetype _Nonnull) + initWithAdUnitId:(NSString *_Nonnull)adUnitId + request:(FLTAdRequest *_Nonnull)request + nativeAdFactory:(NSObject *_Nonnull)nativeAdFactory + customOptions:(NSDictionary *_Nullable)customOptions + rootViewController:(UIViewController *_Nonnull)rootViewController + adId:(NSNumber *_Nonnull)adId + nativeAdOptions:(FLTNativeAdOptions *_Nullable)nativeAdOptions + nativeTemplateStyle:(FLTNativeTemplateStyle *_Nullable)nativeTemplateStyle; - (GADAdLoader *_Nonnull)adLoader; @end @interface FLTRewardItem : NSObject @property(readonly) NSNumber *_Nonnull amount; @property(readonly) NSString *_Nonnull type; -- (instancetype _Nonnull)initWithAmount:(NSNumber *_Nonnull)amount type:(NSString *_Nonnull)type; +- (instancetype _Nonnull)initWithAmount:(NSNumber *_Nonnull)amount + type:(NSString *_Nonnull)type; @end @interface FLTAdValue : NSObject diff --git a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m index a2c2d36ea..12ae3348a 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m @@ -17,9 +17,10 @@ #import "FLTNativeTemplateStyle.h" @implementation FLTAdSize -- (instancetype _Nonnull)initWithWidth:(NSNumber *_Nonnull)width height:(NSNumber *_Nonnull)height { - return - [self initWithAdSize:GADAdSizeFromCGSize(CGSizeMake(width.doubleValue, height.doubleValue))]; +- (instancetype _Nonnull)initWithWidth:(NSNumber *_Nonnull)width + height:(NSNumber *_Nonnull)height { + return [self initWithAdSize:GADAdSizeFromCGSize(CGSizeMake( + width.doubleValue, height.doubleValue))]; } - (instancetype _Nonnull)initWithAdSize:(GADAdSize)size { @@ -34,31 +35,42 @@ - (instancetype _Nonnull)initWithAdSize:(GADAdSize)size { @end @implementation FLTAdSizeFactory -- (GADAdSize)portraitAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width { +- (GADAdSize)portraitAnchoredAdaptiveBannerAdSizeWithWidth: + (NSNumber *_Nonnull)width { return GADPortraitAnchoredAdaptiveBannerAdSizeWithWidth(width.doubleValue); } -- (GADAdSize)landscapeAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width { +- (GADAdSize)landscapeAnchoredAdaptiveBannerAdSizeWithWidth: + (NSNumber *_Nonnull)width { return GADLandscapeAnchoredAdaptiveBannerAdSizeWithWidth(width.doubleValue); } -- (GADAdSize)currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width { - return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(width.doubleValue); +- (GADAdSize)currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth: + (NSNumber *_Nonnull)width { + return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth( + width.doubleValue); } -- (GADAdSize)currentOrientationInlineAdaptiveBannerSizeWithWidth:(NSNumber *_Nonnull)width { - return GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(width.floatValue); +- (GADAdSize)currentOrientationInlineAdaptiveBannerSizeWithWidth: + (NSNumber *_Nonnull)width { + return GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth( + width.floatValue); } -- (GADAdSize)portraitOrientationInlineAdaptiveBannerSizeWithWidth:(NSNumber *_Nonnull)width { +- (GADAdSize)portraitOrientationInlineAdaptiveBannerSizeWithWidth: + (NSNumber *_Nonnull)width { return GADPortraitInlineAdaptiveBannerAdSizeWithWidth(width.floatValue); } -- (GADAdSize)landscapeInlineAdaptiveBannerAdSizeWithWidth:(NSNumber *_Nonnull)width { +- (GADAdSize)landscapeInlineAdaptiveBannerAdSizeWithWidth: + (NSNumber *_Nonnull)width { return GADLandscapeInlineAdaptiveBannerAdSizeWithWidth(width.floatValue); } -- (GADAdSize)inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:(NSNumber *_Nonnull)width - maxHeight:(NSNumber *_Nonnull)maxHeight { - return GADInlineAdaptiveBannerAdSizeWithWidthAndMaxHeight(width.floatValue, maxHeight.floatValue); +- (GADAdSize) + inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:(NSNumber *_Nonnull)width + maxHeight: + (NSNumber *_Nonnull)maxHeight { + return GADInlineAdaptiveBannerAdSizeWithWidthAndMaxHeight( + width.floatValue, maxHeight.floatValue); } @end @@ -69,7 +81,8 @@ - (instancetype _Nonnull)initWithFactory:(FLTAdSizeFactory *_Nonnull)factory width:(NSNumber *_Nonnull)width { GADAdSize size; if ([FLTAdUtil isNull:orientation]) { - size = [factory currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:width]; + size = + [factory currentOrientationAnchoredAdaptiveBannerAdSizeWithWidth:width]; } else if ([orientation isEqualToString:@"portrait"]) { size = [factory portraitAnchoredAdaptiveBannerAdSizeWithWidth:width]; } else if ([orientation isEqualToString:@"landscape"]) { @@ -94,13 +107,18 @@ - (instancetype _Nonnull)initWithFactory:(FLTAdSizeFactory *_Nonnull)factory orientation:(NSNumber *_Nullable)orientation { GADAdSize gadAdSize; if ([FLTAdUtil isNotNull:orientation]) { - gadAdSize = orientation.intValue == 0 - ? [factory portraitOrientationInlineAdaptiveBannerSizeWithWidth:width] - : [factory landscapeInlineAdaptiveBannerAdSizeWithWidth:width]; + gadAdSize = + orientation.intValue == 0 + ? [factory + portraitOrientationInlineAdaptiveBannerSizeWithWidth:width] + : [factory landscapeInlineAdaptiveBannerAdSizeWithWidth:width]; } else if ([FLTAdUtil isNotNull:maxHeight]) { - gadAdSize = [factory inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:width maxHeight:maxHeight]; + gadAdSize = + [factory inlineAdaptiveBannerAdSizeWithWidthAndMaxHeight:width + maxHeight:maxHeight]; } else { - gadAdSize = [factory currentOrientationInlineAdaptiveBannerSizeWithWidth:width]; + gadAdSize = + [factory currentOrientationInlineAdaptiveBannerSizeWithWidth:width]; } self = [self initWithAdSize:gadAdSize]; if (self) { @@ -122,7 +140,8 @@ - (instancetype _Nonnull)initWithOrientation:(NSString *_Nonnull)orientation { size = kGADAdSizeSmartBannerLandscape; #pragma clang diagnostic pop } else { - NSLog(@"SmartBanner orientation should be 'portrait' or 'landscape': %@", orientation); + NSLog(@"SmartBanner orientation should be 'portrait' or 'landscape': %@", + orientation); return nil; } @@ -150,18 +169,21 @@ - (void)addNetworkExtrasToGADRequest:(GADRequest *_Nonnull)request @implementation FLTAdRequest -- (void)addNetworkExtrasToGADRequest:(GADRequest *)request adUnitId:(NSString *_Nonnull)adUnitId { +- (void)addNetworkExtrasToGADRequest:(GADRequest *)request + adUnitId:(NSString *_Nonnull)adUnitId { NSArray> *extras; if (_mediationExtras != NULL) { - NSMutableArray> *flutterExtras = [NSMutableArray array]; + NSMutableArray> *flutterExtras = + [NSMutableArray array]; for (id extra in _mediationExtras) { [flutterExtras addObject:[extra getMediationExtras]]; } extras = [NSArray arrayWithArray:flutterExtras]; } else { - extras = [_mediationNetworkExtrasProvider getMediationExtras:adUnitId - mediationExtrasIdentifier:_mediationExtrasIdentifier]; + extras = [_mediationNetworkExtrasProvider + getMediationExtras:adUnitId + mediationExtrasIdentifier:_mediationExtrasIdentifier]; } BOOL addedNpaToGADExtras = false; @@ -170,8 +192,8 @@ - (void)addNetworkExtrasToGADRequest:(GADRequest *)request adUnitId:(NSString *_ // If GADExtras are present and npa is true, add npa = 1 to the GADExtras if ([extra isKindOfClass:[GADExtras class]] && _nonPersonalizedAds) { GADExtras *gadExtras = (GADExtras *)extra; - NSMutableDictionary *newParams = - [[NSMutableDictionary alloc] initWithDictionary:gadExtras.additionalParameters]; + NSMutableDictionary *newParams = [[NSMutableDictionary alloc] + initWithDictionary:gadExtras.additionalParameters]; newParams[@"npa"] = @"1"; gadExtras.additionalParameters = newParams; [request registerAdNetworkExtras:gadExtras]; @@ -218,20 +240,25 @@ - (GADRequest *_Nonnull)asGADRequest:(NSString *_Nonnull)adUnitId { @implementation FLTGADResponseInfo -- (instancetype _Nonnull)initWithResponseInfo:(GADResponseInfo *_Nonnull)responseInfo { +- (instancetype _Nonnull)initWithResponseInfo: + (GADResponseInfo *_Nonnull)responseInfo { self = [super init]; if (self) { _responseIdentifier = responseInfo.responseIdentifier; - _adNetworkClassName = responseInfo.loadedAdNetworkResponseInfo.adNetworkClassName; - NSMutableArray *infoArray = [[NSMutableArray alloc] init]; - for (GADAdNetworkResponseInfo *adNetworkInfo in responseInfo.adNetworkInfoArray) { - [infoArray - addObject:[[FLTGADAdNetworkResponseInfo alloc] initWithResponseInfo:adNetworkInfo]]; + _adNetworkClassName = + responseInfo.loadedAdNetworkResponseInfo.adNetworkClassName; + NSMutableArray *infoArray = + [[NSMutableArray alloc] init]; + for (GADAdNetworkResponseInfo *adNetworkInfo in responseInfo + .adNetworkInfoArray) { + [infoArray addObject:[[FLTGADAdNetworkResponseInfo alloc] + initWithResponseInfo:adNetworkInfo]]; } _adNetworkInfoArray = infoArray; _loadedAdNetworkResponseInfo = [[FLTGADAdNetworkResponseInfo alloc] initWithResponseInfo:responseInfo.loadedAdNetworkResponseInfo]; - _extrasDictionary = responseInfo.extrasDictionary ? responseInfo.extrasDictionary : @{}; + _extrasDictionary = + responseInfo.extrasDictionary ? responseInfo.extrasDictionary : @{}; } return self; } @@ -239,11 +266,13 @@ - (instancetype _Nonnull)initWithResponseInfo:(GADResponseInfo *_Nonnull)respons @implementation FLTGADAdNetworkResponseInfo -- (instancetype _Nonnull)initWithResponseInfo:(GADAdNetworkResponseInfo *_Nonnull)responseInfo { +- (instancetype _Nonnull)initWithResponseInfo: + (GADAdNetworkResponseInfo *_Nonnull)responseInfo { self = [super init]; if (self) { _adNetworkClassName = responseInfo.adNetworkClassName; - NSNumber *timeInMillis = [[NSNumber alloc] initWithDouble:responseInfo.latency * 1000]; + NSNumber *timeInMillis = + [[NSNumber alloc] initWithDouble:responseInfo.latency * 1000]; _latency = @(timeInMillis.longValue); _dictionaryDescription = responseInfo.dictionaryRepresentation.description; _adUnitMapping = [[NSMutableDictionary alloc] init]; @@ -274,9 +303,11 @@ - (instancetype _Nonnull)initWithError:(NSError *_Nonnull)error { _code = error.code; _domain = error.domain; _message = error.localizedDescription; - GADResponseInfo *responseInfo = error.userInfo[GADErrorUserInfoKeyResponseInfo]; + GADResponseInfo *responseInfo = + error.userInfo[GADErrorUserInfoKeyResponseInfo]; if (responseInfo) { - _responseInfo = [[FLTGADResponseInfo alloc] initWithResponseInfo:responseInfo]; + _responseInfo = + [[FLTGADResponseInfo alloc] initWithResponseInfo:responseInfo]; } } return self; @@ -297,7 +328,8 @@ - (GADRequest *_Nonnull)asGAMRequest:(NSString *_Nonnull)adUnitId { NSMutableDictionary *targetingDictionary = [NSMutableDictionary dictionaryWithDictionary:self.customTargeting]; for (NSString *key in self.customTargetingLists) { - targetingDictionary[key] = [self.customTargetingLists[key] componentsJoinedByString:@","]; + targetingDictionary[key] = + [self.customTargetingLists[key] componentsJoinedByString:@","]; } request.customTargeting = targetingDictionary; [self addNetworkExtrasToGADRequest:request adUnitId:adUnitId]; @@ -342,9 +374,10 @@ - (instancetype)initWithAdUnitId:(NSString *_Nonnull)adUnitId return; } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] + initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; } return self; @@ -372,7 +405,8 @@ - (void)bannerViewDidReceiveAd:(GADBannerView *)bannerView { [manager onAdLoaded:self responseInfo:bannerView.responseInfo]; } -- (void)bannerView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(NSError *)error { +- (void)bannerView:(GADBannerView *)bannerView + didFailToReceiveAdWithError:(NSError *)error { [manager onAdFailedToLoad:self error:error]; } @@ -428,7 +462,8 @@ - (instancetype)initWithAdUnitId:(NSString *_Nonnull)adUnitId _bannerView.appEventDelegate = self; _bannerView.delegate = self; - NSMutableArray *validAdSizes = [NSMutableArray arrayWithCapacity:sizes.count]; + NSMutableArray *validAdSizes = + [NSMutableArray arrayWithCapacity:sizes.count]; for (FLTAdSize *size in sizes) { [validAdSizes addObject:NSValueFromGADAdSize(size.size)]; } @@ -440,9 +475,10 @@ - (instancetype)initWithAdUnitId:(NSString *_Nonnull)adUnitId return; } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] + initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; } return self; @@ -504,9 +540,10 @@ - (instancetype)initWithAdUnitId:(NSString *_Nonnull)adUnitId return; } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] + initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; } return self; @@ -533,23 +570,27 @@ - (nonnull UIView *)view { [scrollView addSubview:_bannerView]; _bannerView.translatesAutoresizingMaskIntoConstraints = false; - NSLayoutConstraint *width = [NSLayoutConstraint constraintWithItem:_bannerView - attribute:NSLayoutAttributeWidth - relatedBy:0 - toItem:scrollView - attribute:NSLayoutAttributeWidth - multiplier:1.0 - constant:0]; + NSLayoutConstraint *width = + [NSLayoutConstraint constraintWithItem:_bannerView + attribute:NSLayoutAttributeWidth + relatedBy:0 + toItem:scrollView + attribute:NSLayoutAttributeWidth + multiplier:1.0 + constant:0]; [scrollView addConstraint:width]; _containerView = scrollView; - [_bannerView.widthAnchor constraintEqualToAnchor:scrollView.widthAnchor].active = YES; - [_bannerView.topAnchor constraintEqualToAnchor:scrollView.topAnchor].active = YES; + [_bannerView.widthAnchor constraintEqualToAnchor:scrollView.widthAnchor] + .active = YES; + [_bannerView.topAnchor constraintEqualToAnchor:scrollView.topAnchor].active = + YES; return scrollView; } #pragma mark - GADAdSizeDelegate -- (void)adView:(GADBannerView *)bannerView willChangeAdSizeTo:(GADAdSize)adSize { +- (void)adView:(GADBannerView *)bannerView + willChangeAdSizeTo:(GADAdSize)adSize { CGFloat height = adSize.size.height; [self.manager onFluidAdHeightChanged:self height:height]; } @@ -573,14 +614,16 @@ @implementation FLTFullScreenAd { - (void)load { // Must be overridden by subclasses - [NSException raise:NSInternalInconsistencyException - format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; + [NSException + raise:NSInternalInconsistencyException + format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; } - (void)showFromRootViewController:(UIViewController *)rootViewController { // Must be overridden by subclasses - [NSException raise:NSInternalInconsistencyException - format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; + [NSException + raise:NSInternalInconsistencyException + format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; } - (void)ad:(nonnull id)ad @@ -588,25 +631,30 @@ - (void)ad:(nonnull id)ad [manager didFailToPresentFullScreenContentWithError:self error:error]; } -- (void)adWillPresentFullScreenContent:(nonnull id)ad { +- (void)adWillPresentFullScreenContent: + (nonnull id)ad { // Manually hide the status bar. This is a fix for // https://github.com/googleads/googleads-mobile-flutter/issues/191 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - _statusBarVisibilityBeforeAdShow = UIApplication.sharedApplication.statusBarHidden; + _statusBarVisibilityBeforeAdShow = + UIApplication.sharedApplication.statusBarHidden; [UIApplication.sharedApplication setStatusBarHidden:YES]; #pragma clang diagnostic pop [manager adWillPresentFullScreenContent:self]; } -- (void)adDidDismissFullScreenContent:(nonnull id)ad { +- (void)adDidDismissFullScreenContent: + (nonnull id)ad { [manager adDidDismissFullScreenContent:self]; } -- (void)adWillDismissFullScreenContent:(nonnull id)ad { +- (void)adWillDismissFullScreenContent: + (nonnull id)ad { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - [UIApplication.sharedApplication setStatusBarHidden:_statusBarVisibilityBeforeAdShow]; + [UIApplication.sharedApplication + setStatusBarHidden:_statusBarVisibilityBeforeAdShow]; #pragma clang diagnostic pop [manager adWillDismissFullScreenContent:self]; } @@ -650,30 +698,32 @@ - (NSString *_Nonnull)adUnitId { } - (void)load { - [GADInterstitialAd loadWithAdUnitID:_adUnitId - request:[_adRequest asGADRequest:_adUnitId] - completionHandler:^(GADInterstitialAd *ad, NSError *error) { - if (error) { - [self.manager onAdFailedToLoad:self error:error]; - return; - } - - ad.fullScreenContentDelegate = self; - self->_interstitialView = ad; - __weak FLTInterstitialAd *weakSelf = self; - ad.paidEventHandler = ^(GADAdValue *_Nonnull value) { - if (weakSelf.manager == nil) { - return; - } - [weakSelf.manager - onPaidEvent:weakSelf - value:[[FLTAdValue alloc] initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; - }; - - [self.manager onAdLoaded:self responseInfo:ad.responseInfo]; - }]; + [GADInterstitialAd + loadWithAdUnitID:_adUnitId + request:[_adRequest asGADRequest:_adUnitId] + completionHandler:^(GADInterstitialAd *ad, NSError *error) { + if (error) { + [self.manager onAdFailedToLoad:self error:error]; + return; + } + + ad.fullScreenContentDelegate = self; + self->_interstitialView = ad; + __weak FLTInterstitialAd *weakSelf = self; + ad.paidEventHandler = ^(GADAdValue *_Nonnull value) { + if (weakSelf.manager == nil) { + return; + } + [weakSelf.manager + onPaidEvent:weakSelf + value:[[FLTAdValue alloc] + initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; + }; + + [self.manager onAdLoaded:self responseInfo:ad.responseInfo]; + }]; } - (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewController { @@ -729,9 +779,10 @@ - (void)load { } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] + initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; self->_insterstitial = ad; @@ -793,7 +844,8 @@ - (void)load { [GADRewardedAd loadWithAdUnitID:_adUnitId request:request - completionHandler:^(GADRewardedAd *_Nullable rewardedAd, NSError *_Nullable error) { + completionHandler:^(GADRewardedAd *_Nullable rewardedAd, + NSError *_Nullable error) { if (error) { [self.manager onAdFailedToLoad:self error:error]; return; @@ -805,26 +857,30 @@ - (void)load { } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] + initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; rewardedAd.fullScreenContentDelegate = self; self->_rewardedView = rewardedAd; - [self.manager onAdLoaded:self responseInfo:rewardedAd.responseInfo]; + [self.manager onAdLoaded:self + responseInfo:rewardedAd.responseInfo]; }]; } - (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewController { if (self.rewardedAd) { - [self.rewardedAd presentFromRootViewController:rootViewController - userDidEarnRewardHandler:^{ - GADAdReward *reward = self.rewardedAd.adReward; - FLTRewardItem *fltReward = - [[FLTRewardItem alloc] initWithAmount:reward.amount - type:reward.type]; - [self.manager onRewardedAdUserEarnedReward:self reward:fltReward]; - }]; + [self.rewardedAd + presentFromRootViewController:rootViewController + userDidEarnRewardHandler:^{ + GADAdReward *reward = self.rewardedAd.adReward; + FLTRewardItem *fltReward = + [[FLTRewardItem alloc] initWithAmount:reward.amount + type:reward.type]; + [self.manager onRewardedAdUserEarnedReward:self + reward:fltReward]; + }]; } else { NSLog(@"RewardedAd failed to show because the ad was not ready."); } @@ -881,25 +937,30 @@ - (void)load { [GADRewardedInterstitialAd loadWithAdUnitID:_adUnitId request:request - completionHandler:^(GADRewardedInterstitialAd *_Nullable rewardedInterstitialAd, - NSError *_Nullable error) { + completionHandler:^( + GADRewardedInterstitialAd *_Nullable rewardedInterstitialAd, + NSError *_Nullable error) { if (error) { [self.manager onAdFailedToLoad:self error:error]; return; } __weak FLTRewardedInterstitialAd *weakSelf = self; - rewardedInterstitialAd.paidEventHandler = ^(GADAdValue *_Nonnull value) { - if (weakSelf.manager == nil) { - return; - } - [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; - }; + rewardedInterstitialAd.paidEventHandler = + ^(GADAdValue *_Nonnull value) { + if (weakSelf.manager == nil) { + return; + } + [weakSelf.manager + onPaidEvent:weakSelf + value:[[FLTAdValue alloc] + initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; + }; rewardedInterstitialAd.fullScreenContentDelegate = self; self->_rewardedInterstitialView = rewardedInterstitialAd; - [self.manager onAdLoaded:self responseInfo:rewardedInterstitialAd.responseInfo]; + [self.manager onAdLoaded:self + responseInfo:rewardedInterstitialAd.responseInfo]; }]; } @@ -909,12 +970,16 @@ - (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewControlle presentFromRootViewController:rootViewController userDidEarnRewardHandler:^{ GADAdReward *reward = self.rewardedInterstitialAd.adReward; - FLTRewardItem *fltReward = [[FLTRewardItem alloc] initWithAmount:reward.amount - type:reward.type]; - [self.manager onRewardedInterstitialAdUserEarnedReward:self reward:fltReward]; + FLTRewardItem *fltReward = + [[FLTRewardItem alloc] initWithAmount:reward.amount + type:reward.type]; + [self.manager + onRewardedInterstitialAdUserEarnedReward:self + reward:fltReward]; }]; } else { - NSLog(@"RewardedInterstitialAd failed to show because the ad was not ready."); + NSLog( + @"RewardedInterstitialAd failed to show because the ad was not ready."); } } @@ -968,7 +1033,8 @@ - (void)load { [GADAppOpenAd loadWithAdUnitID:_adUnitId request:request - completionHandler:^(GADAppOpenAd *_Nullable appOpenAd, NSError *_Nullable error) { + completionHandler:^(GADAppOpenAd *_Nullable appOpenAd, + NSError *_Nullable error) { if (error) { [self.manager onAdFailedToLoad:self error:error]; return; @@ -980,14 +1046,16 @@ - (void)load { } [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + value:[[FLTAdValue alloc] + initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; appOpenAd.fullScreenContentDelegate = self; self->_appOpenAd = appOpenAd; - [self.manager onAdLoaded:self responseInfo:appOpenAd.responseInfo]; + [self.manager onAdLoaded:self + responseInfo:appOpenAd.responseInfo]; }]; } @@ -1014,14 +1082,15 @@ @implementation FLTNativeAd { FLTNativeTemplateStyle *_nativeTemplateStyle; } -- (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId - request:(FLTAdRequest *_Nonnull)request - nativeAdFactory:(NSObject *_Nonnull)nativeAdFactory - customOptions:(NSDictionary *_Nullable)customOptions - rootViewController:(UIViewController *_Nonnull)rootViewController - adId:(NSNumber *_Nonnull)adId - nativeAdOptions:(FLTNativeAdOptions *_Nullable)nativeAdOptions - nativeTemplateStyle:(FLTNativeTemplateStyle *_Nullable)nativeTemplateStyle { +- (instancetype _Nonnull) + initWithAdUnitId:(NSString *_Nonnull)adUnitId + request:(FLTAdRequest *_Nonnull)request + nativeAdFactory:(NSObject *_Nonnull)nativeAdFactory + customOptions:(NSDictionary *_Nullable)customOptions + rootViewController:(UIViewController *_Nonnull)rootViewController + adId:(NSNumber *_Nonnull)adId + nativeAdOptions:(FLTNativeAdOptions *_Nullable)nativeAdOptions + nativeTemplateStyle:(FLTNativeTemplateStyle *_Nullable)nativeTemplateStyle { self = [super init]; if (self) { self.adId = adId; @@ -1034,10 +1103,11 @@ - (instancetype _Nonnull)initWithAdUnitId:(NSString *_Nonnull)adUnitId ? @[] : nativeAdOptions.asGADAdLoaderOptions; - _adLoader = [[GADAdLoader alloc] initWithAdUnitID:_adUnitId - rootViewController:rootViewController - adTypes:@[ GADAdLoaderAdTypeNative ] - options:adLoaderOptions]; + _adLoader = + [[GADAdLoader alloc] initWithAdUnitID:_adUnitId + rootViewController:rootViewController + adTypes:@[ GADAdLoaderAdTypeNative ] + options:adLoaderOptions]; _nativeAdOptions = nativeAdOptions; _nativeTemplateStyle = nativeTemplateStyle; self.adLoader.delegate = self; @@ -1063,14 +1133,16 @@ - (void)load { #pragma mark - GADNativeAdLoaderDelegate -- (void)adLoader:(GADAdLoader *)adLoader didReceiveNativeAd:(GADNativeAd *)nativeAd { +- (void)adLoader:(GADAdLoader *)adLoader + didReceiveNativeAd:(GADNativeAd *)nativeAd { // Use Nil instead of Null to fix crash with Swift integrations. NSDictionary *customOptions = [[NSNull null] isEqual:_customOptions] ? nil : _customOptions; if ([FLTAdUtil isNotNull:_nativeTemplateStyle]) { _view = [_nativeTemplateStyle getDisplayedView:nativeAd]; } else if ([FLTAdUtil isNotNull:_nativeAdFactory]) { - _view = [_nativeAdFactory createNativeAd:nativeAd customOptions:customOptions]; + _view = [_nativeAdFactory createNativeAd:nativeAd + customOptions:customOptions]; } nativeAd.delegate = self; @@ -1080,15 +1152,17 @@ - (void)adLoader:(GADAdLoader *)adLoader didReceiveNativeAd:(GADNativeAd *)nativ if (weakSelf.manager == nil) { return; } - [weakSelf.manager onPaidEvent:weakSelf - value:[[FLTAdValue alloc] initWithValue:value.value - precision:(NSInteger)value.precision - currencyCode:value.currencyCode]]; + [weakSelf.manager + onPaidEvent:weakSelf + value:[[FLTAdValue alloc] initWithValue:value.value + precision:(NSInteger)value.precision + currencyCode:value.currencyCode]]; }; [manager onAdLoaded:self responseInfo:nativeAd.responseInfo]; } -- (void)adLoader:(GADAdLoader *)adLoader didFailToReceiveAdWithError:(NSError *)error { +- (void)adLoader:(GADAdLoader *)adLoader + didFailToReceiveAdWithError:(NSError *)error { [manager onAdFailedToLoad:self error:error]; } @@ -1124,7 +1198,8 @@ - (UIView *)view { @end @implementation FLTRewardItem -- (instancetype _Nonnull)initWithAmount:(NSNumber *_Nonnull)amount type:(NSString *_Nonnull)type { +- (instancetype _Nonnull)initWithAmount:(NSNumber *_Nonnull)amount + type:(NSString *_Nonnull)type { self = [super init]; if (self) { _amount = amount; @@ -1156,7 +1231,8 @@ - (instancetype _Nonnull)initWithValue:(NSDecimalNumber *_Nonnull)value self = [super init]; if (self) { _valueMicros = - [value decimalNumberByMultiplyingBy:[[NSDecimalNumber alloc] initWithInteger:1000000]]; + [value decimalNumberByMultiplyingBy:[[NSDecimalNumber alloc] + initWithInteger:1000000]]; _precision = precision; _currencyCode = currencyCode; } @@ -1165,9 +1241,10 @@ - (instancetype _Nonnull)initWithValue:(NSDecimalNumber *_Nonnull)value @end @implementation FLTVideoOptions -- (instancetype _Nonnull)initWithClickToExpandRequested:(NSNumber *_Nullable)clickToExpandRequested - customControlsRequested:(NSNumber *_Nullable)customControlsRequested - startMuted:(NSNumber *_Nullable)startMuted { +- (instancetype _Nonnull) + initWithClickToExpandRequested:(NSNumber *_Nullable)clickToExpandRequested + customControlsRequested:(NSNumber *_Nullable)customControlsRequested + startMuted:(NSNumber *_Nullable)startMuted { self = [super init]; if (self) { _clickToExpandRequested = clickToExpandRequested; @@ -1194,13 +1271,15 @@ - (GADVideoOptions *_Nonnull)asGADVideoOptions { @end @implementation FLTNativeAdOptions -- (instancetype _Nonnull)initWithAdChoicesPlacement:(NSNumber *_Nullable)adChoicesPlacement - mediaAspectRatio:(NSNumber *_Nullable)mediaAspectRatio - videoOptions:(FLTVideoOptions *_Nullable)videoOptions - requestCustomMuteThisAd:(NSNumber *_Nullable)requestCustomMuteThisAd - shouldRequestMultipleImages:(NSNumber *_Nullable)shouldRequestMultipleImages - shouldReturnUrlsForImageAssets: - (NSNumber *_Nullable)shouldReturnUrlsForImageAssets { +- (instancetype _Nonnull) + initWithAdChoicesPlacement:(NSNumber *_Nullable)adChoicesPlacement + mediaAspectRatio:(NSNumber *_Nullable)mediaAspectRatio + videoOptions:(FLTVideoOptions *_Nullable)videoOptions + requestCustomMuteThisAd:(NSNumber *_Nullable)requestCustomMuteThisAd + shouldRequestMultipleImages: + (NSNumber *_Nullable)shouldRequestMultipleImages + shouldReturnUrlsForImageAssets: + (NSNumber *_Nullable)shouldReturnUrlsForImageAssets { self = [super init]; if (self) { _adChoicesPlacement = adChoicesPlacement; @@ -1216,60 +1295,69 @@ - (instancetype _Nonnull)initWithAdChoicesPlacement:(NSNumber *_Nullable)adChoic - (NSArray *_Nonnull)asGADAdLoaderOptions { NSMutableArray *options = [NSMutableArray array]; - GADNativeAdImageAdLoaderOptions *imageOptions = [[GADNativeAdImageAdLoaderOptions alloc] init]; + GADNativeAdImageAdLoaderOptions *imageOptions = + [[GADNativeAdImageAdLoaderOptions alloc] init]; if ([FLTAdUtil isNotNull:_shouldReturnUrlsForImageAssets]) { - imageOptions.disableImageLoading = _shouldReturnUrlsForImageAssets.boolValue; + imageOptions.disableImageLoading = + _shouldReturnUrlsForImageAssets.boolValue; } if ([FLTAdUtil isNotNull:_shouldRequestMultipleImages]) { - imageOptions.shouldRequestMultipleImages = _shouldRequestMultipleImages.boolValue; + imageOptions.shouldRequestMultipleImages = + _shouldRequestMultipleImages.boolValue; } [options addObject:imageOptions]; if ([FLTAdUtil isNotNull:_adChoicesPlacement]) { - GADNativeAdViewAdOptions *adViewOptions = [[GADNativeAdViewAdOptions alloc] init]; + GADNativeAdViewAdOptions *adViewOptions = + [[GADNativeAdViewAdOptions alloc] init]; switch (_adChoicesPlacement.intValue) { - case 0: - adViewOptions.preferredAdChoicesPosition = GADAdChoicesPositionTopRightCorner; - break; - case 1: - adViewOptions.preferredAdChoicesPosition = GADAdChoicesPositionTopLeftCorner; - break; - case 2: - adViewOptions.preferredAdChoicesPosition = GADAdChoicesPositionBottomRightCorner; - break; - case 3: - adViewOptions.preferredAdChoicesPosition = GADAdChoicesPositionBottomLeftCorner; - break; - default: - NSLog(@"AdChoicesPlacement should be an int in the range [0, 3]: %d", - _adChoicesPlacement.intValue); - break; + case 0: + adViewOptions.preferredAdChoicesPosition = + GADAdChoicesPositionTopRightCorner; + break; + case 1: + adViewOptions.preferredAdChoicesPosition = + GADAdChoicesPositionTopLeftCorner; + break; + case 2: + adViewOptions.preferredAdChoicesPosition = + GADAdChoicesPositionBottomRightCorner; + break; + case 3: + adViewOptions.preferredAdChoicesPosition = + GADAdChoicesPositionBottomLeftCorner; + break; + default: + NSLog(@"AdChoicesPlacement should be an int in the range [0, 3]: %d", + _adChoicesPlacement.intValue); + break; } [options addObject:adViewOptions]; } if ([FLTAdUtil isNotNull:_mediaAspectRatio]) { - GADNativeAdMediaAdLoaderOptions *mediaOptions = [[GADNativeAdMediaAdLoaderOptions alloc] init]; + GADNativeAdMediaAdLoaderOptions *mediaOptions = + [[GADNativeAdMediaAdLoaderOptions alloc] init]; switch (_mediaAspectRatio.intValue) { - case 0: - mediaOptions.mediaAspectRatio = GADMediaAspectRatioUnknown; - break; - case 1: - mediaOptions.mediaAspectRatio = GADMediaAspectRatioAny; - break; - case 2: - mediaOptions.mediaAspectRatio = GADMediaAspectRatioLandscape; - break; - case 3: - mediaOptions.mediaAspectRatio = GADMediaAspectRatioPortrait; - break; - case 4: - mediaOptions.mediaAspectRatio = GADMediaAspectRatioSquare; - break; - default: - NSLog(@"MediaAspectRatio should be an int in the range [0, 4]: %d", - _mediaAspectRatio.intValue); - break; + case 0: + mediaOptions.mediaAspectRatio = GADMediaAspectRatioUnknown; + break; + case 1: + mediaOptions.mediaAspectRatio = GADMediaAspectRatioAny; + break; + case 2: + mediaOptions.mediaAspectRatio = GADMediaAspectRatioLandscape; + break; + case 3: + mediaOptions.mediaAspectRatio = GADMediaAspectRatioPortrait; + break; + case 4: + mediaOptions.mediaAspectRatio = GADMediaAspectRatioSquare; + break; + default: + NSLog(@"MediaAspectRatio should be an int in the range [0, 4]: %d", + _mediaAspectRatio.intValue); + break; } [options addObject:mediaOptions]; } diff --git a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m index b872d164c..d76165594 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m +++ b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m @@ -22,7 +22,8 @@ @interface FLTGoogleMobileAdsPlugin () @property(nonatomic, retain) FlutterMethodChannel *channel; -@property NSMutableDictionary> *nativeAdFactories; +@property NSMutableDictionary> + *nativeAdFactories; @end /// Initialization handler for GMASDK. Invokes result at most once. @@ -74,26 +75,29 @@ @implementation FLTGoogleMobileAdsPlugin { } + (void)registerWithRegistrar:(NSObject *)registrar { - FLTGoogleMobileAdsPlugin *instance = - [[FLTGoogleMobileAdsPlugin alloc] initWithBinaryMessenger:registrar.messenger]; + FLTGoogleMobileAdsPlugin *instance = [[FLTGoogleMobileAdsPlugin alloc] + initWithBinaryMessenger:registrar.messenger]; [registrar publish:instance]; - FLTGoogleMobileAdsReaderWriter *readerWriter = [[FLTGoogleMobileAdsReaderWriter alloc] init]; + FLTGoogleMobileAdsReaderWriter *readerWriter = + [[FLTGoogleMobileAdsReaderWriter alloc] init]; instance->_readerWriter = readerWriter; NSObject *codec = [FlutterStandardMethodCodec codecWithReaderWriter:readerWriter]; - FlutterMethodChannel *channel = - [FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/google_mobile_ads" - binaryMessenger:[registrar messenger] - codec:codec]; + FlutterMethodChannel *channel = [FlutterMethodChannel + methodChannelWithName:@"plugins.flutter.io/google_mobile_ads" + binaryMessenger:[registrar messenger] + codec:codec]; [registrar addMethodCallDelegate:instance channel:channel]; FLTNewGoogleMobileAdsViewFactory *viewFactory = - [[FLTNewGoogleMobileAdsViewFactory alloc] initWithManager:instance->_manager]; - [registrar registerViewFactory:viewFactory - withId:@"plugins.flutter.io/google_mobile_ads/ad_widget"]; + [[FLTNewGoogleMobileAdsViewFactory alloc] + initWithManager:instance->_manager]; + [registrar + registerViewFactory:viewFactory + withId:@"plugins.flutter.io/google_mobile_ads/ad_widget"]; [registrar addApplicationDelegate:instance]; } @@ -108,25 +112,32 @@ - (BOOL)application:(UIApplication *)application return YES; } -- (instancetype)initWithBinaryMessenger:(id)binaryMessenger { +- (instancetype)initWithBinaryMessenger: + (id)binaryMessenger { self = [self init]; if (self) { _nativeAdFactories = [NSMutableDictionary dictionary]; - _manager = [[FLTAdInstanceManager alloc] initWithBinaryMessenger:binaryMessenger]; - _appStateNotifier = [[FLTAppStateNotifier alloc] initWithBinaryMessenger:binaryMessenger]; - _userMessagingPlatformManager = - [[FLTUserMessagingPlatformManager alloc] initWithBinaryMessenger:binaryMessenger]; + _manager = + [[FLTAdInstanceManager alloc] initWithBinaryMessenger:binaryMessenger]; + _appStateNotifier = + [[FLTAppStateNotifier alloc] initWithBinaryMessenger:binaryMessenger]; + _userMessagingPlatformManager = [[FLTUserMessagingPlatformManager alloc] + initWithBinaryMessenger:binaryMessenger]; } return self; } + (BOOL)registerMediationNetworkExtrasProvider: - (id _Nonnull)mediationNetworkExtrasProvider - registry:(id _Nonnull)registry { - NSString *pluginClassName = NSStringFromClass([FLTGoogleMobileAdsPlugin class]); - FLTGoogleMobileAdsPlugin *adMobPlugin = - (FLTGoogleMobileAdsPlugin *)[registry valuePublishedByPlugin:pluginClassName]; + (id _Nonnull) + mediationNetworkExtrasProvider + registry: + (id _Nonnull) + registry { + NSString *pluginClassName = + NSStringFromClass([FLTGoogleMobileAdsPlugin class]); + FLTGoogleMobileAdsPlugin *adMobPlugin = (FLTGoogleMobileAdsPlugin *)[registry + valuePublishedByPlugin:pluginClassName]; if (!adMobPlugin) { NSLog(@"Could not find a %@ instance registering mediation extras " @"provider. The plugin may " @@ -136,15 +147,18 @@ + (BOOL)registerMediationNetworkExtrasProvider: } adMobPlugin->_mediationNetworkExtrasProvider = mediationNetworkExtrasProvider; - adMobPlugin->_readerWriter.mediationNetworkExtrasProvider = mediationNetworkExtrasProvider; + adMobPlugin->_readerWriter.mediationNetworkExtrasProvider = + mediationNetworkExtrasProvider; return YES; } -+ (void)unregisterMediationNetworkExtrasProvider:(id _Nonnull)registry { - NSString *pluginClassName = NSStringFromClass([FLTGoogleMobileAdsPlugin class]); - FLTGoogleMobileAdsPlugin *adMobPlugin = - (FLTGoogleMobileAdsPlugin *)[registry valuePublishedByPlugin:pluginClassName]; ++ (void)unregisterMediationNetworkExtrasProvider: + (id _Nonnull)registry { + NSString *pluginClassName = + NSStringFromClass([FLTGoogleMobileAdsPlugin class]); + FLTGoogleMobileAdsPlugin *adMobPlugin = (FLTGoogleMobileAdsPlugin *)[registry + valuePublishedByPlugin:pluginClassName]; if (!adMobPlugin) { NSLog(@"Could not find a %@ instance deregistering mediation extras " @"provider. The plugin may " @@ -160,18 +174,23 @@ + (void)unregisterMediationNetworkExtrasProvider:(id _Non + (BOOL)registerNativeAdFactory:(id)registry factoryId:(NSString *)factoryId nativeAdFactory:(id)nativeAdFactory { - NSString *pluginClassName = NSStringFromClass([FLTGoogleMobileAdsPlugin class]); - FLTGoogleMobileAdsPlugin *adMobPlugin = - (FLTGoogleMobileAdsPlugin *)[registry valuePublishedByPlugin:pluginClassName]; + NSString *pluginClassName = + NSStringFromClass([FLTGoogleMobileAdsPlugin class]); + FLTGoogleMobileAdsPlugin *adMobPlugin = (FLTGoogleMobileAdsPlugin *)[registry + valuePublishedByPlugin:pluginClassName]; if (!adMobPlugin) { - NSString *reason = [NSString stringWithFormat:@"Could not find a %@ instance. The plugin " - @"may have not been registered.", - pluginClassName]; - [NSException exceptionWithName:NSInvalidArgumentException reason:reason userInfo:nil]; + NSString *reason = + [NSString stringWithFormat:@"Could not find a %@ instance. The plugin " + @"may have not been registered.", + pluginClassName]; + [NSException exceptionWithName:NSInvalidArgumentException + reason:reason + userInfo:nil]; } if (adMobPlugin.nativeAdFactories[factoryId]) { - NSLog(@"A NativeAdFactory with the following factoryId already exists: %@", factoryId); + NSLog(@"A NativeAdFactory with the following factoryId already exists: %@", + factoryId); return NO; } @@ -179,36 +198,38 @@ + (BOOL)registerNativeAdFactory:(id)registry return YES; } -+ (id)unregisterNativeAdFactory:(id)registry ++ (id)unregisterNativeAdFactory: + (id)registry factoryId:(NSString *)factoryId { FLTGoogleMobileAdsPlugin *adMobPlugin = (FLTGoogleMobileAdsPlugin *)[registry - valuePublishedByPlugin:NSStringFromClass([FLTGoogleMobileAdsPlugin class])]; + valuePublishedByPlugin:NSStringFromClass( + [FLTGoogleMobileAdsPlugin class])]; id factory = adMobPlugin.nativeAdFactories[factoryId]; - if (factory) [adMobPlugin.nativeAdFactories removeObjectForKey:factoryId]; + if (factory) + [adMobPlugin.nativeAdFactories removeObjectForKey:factoryId]; return factory; } - (UIViewController *)rootController { - UIViewController *root = UIApplication.sharedApplication.delegate.window.rootViewController; + UIViewController *root = + UIApplication.sharedApplication.delegate.window.rootViewController; if ([FLTAdUtil isNull:root]) { -// UIApplication.sharedApplication.delegate.window is not guaranteed to be -// set. Use the keyWindow in this case. -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" + // UIApplication.sharedApplication.delegate.window is not guaranteed to be + // set. Use the keyWindow in this case. + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdeprecated-declarations" root = UIApplication.sharedApplication.keyWindow.rootViewController; -#pragma clang diagnostic pop + #pragma clang diagnostic pop } UIViewController *presentedViewController = root; - while (presentedViewController.presentedViewController && - ![presentedViewController.presentedViewController isBeingDismissed]) { + while (presentedViewController.presentedViewController && ![presentedViewController.presentedViewController isBeingDismissed]) { if ([presentedViewController isKindOfClass:[UITabBarController class]]) { - UITabBarController *tabBarController = (UITabBarController *)presentedViewController; + UITabBarController* tabBarController = (UITabBarController*)presentedViewController; presentedViewController = tabBarController.selectedViewController; } else if ([presentedViewController isKindOfClass:[UINavigationController class]]) { - UINavigationController *navigationController = - (UINavigationController *)presentedViewController; + UINavigationController* navigationController = (UINavigationController*)presentedViewController; presentedViewController = navigationController.visibleViewController; } else { presentedViewController = presentedViewController.presentedViewController; @@ -217,26 +238,26 @@ - (UIViewController *)rootController { return presentedViewController; } -- (UIViewController *)topViewControllerWithRootViewController: - (UIViewController *)rootViewController { +- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController { if ([rootViewController isKindOfClass:[UITabBarController class]]) { - UITabBarController *tabBarController = (UITabBarController *)rootViewController; + UITabBarController* tabBarController = (UITabBarController*)rootViewController; return [self topViewControllerWithRootViewController:tabBarController.selectedViewController]; } else if ([rootViewController isKindOfClass:[UINavigationController class]]) { - UINavigationController *navigationController = (UINavigationController *)rootViewController; - return - [self topViewControllerWithRootViewController:navigationController.visibleViewController]; + UINavigationController* navigationController = (UINavigationController*)rootViewController; + return [self topViewControllerWithRootViewController:navigationController.visibleViewController]; } else { return rootViewController; } } -- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { +- (void)handleMethodCall:(FlutterMethodCall *)call + result:(FlutterResult)result { NSLog(@"handleMethodCall %@", call.method); UIViewController *rootController = self.rootController; if ([call.method isEqualToString:@"MobileAds#initialize"]) { - FLTInitializationHandler *handler = [[FLTInitializationHandler alloc] initWithResult:result]; + FLTInitializationHandler *handler = + [[FLTInitializationHandler alloc] initWithResult:result]; [[GADMobileAds sharedInstance] startWithCompletionHandler:^(GADInitializationStatus *_Nonnull status) { [handler handleInitializationComplete:status]; @@ -245,27 +266,35 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result [_manager disposeAllAds]; result(nil); } else if ([call.method isEqualToString:@"MobileAds#setSameAppKeyEnabled"]) { - GADRequestConfiguration *requestConfig = GADMobileAds.sharedInstance.requestConfiguration; + GADRequestConfiguration *requestConfig = + GADMobileAds.sharedInstance.requestConfiguration; NSNumber *isEnabled = call.arguments[@"isEnabled"]; [requestConfig setPublisherFirstPartyIDEnabled:isEnabled.boolValue]; result(nil); } else if ([call.method isEqualToString:@"MobileAds#setAppMuted"]) { - GADMobileAds.sharedInstance.applicationMuted = [call.arguments[@"muted"] boolValue]; + GADMobileAds.sharedInstance.applicationMuted = + [call.arguments[@"muted"] boolValue]; result(nil); } else if ([call.method isEqualToString:@"MobileAds#setAppVolume"]) { - GADMobileAds.sharedInstance.applicationVolume = [call.arguments[@"volume"] floatValue]; + GADMobileAds.sharedInstance.applicationVolume = + [call.arguments[@"volume"] floatValue]; result(nil); - } else if ([call.method isEqualToString:@"MobileAds#disableSDKCrashReporting"]) { + } else if ([call.method + isEqualToString:@"MobileAds#disableSDKCrashReporting"]) { [GADMobileAds.sharedInstance disableSDKCrashReporting]; result(nil); - } else if ([call.method isEqualToString:@"MobileAds#disableMediationInitialization"]) { + } else if ([call.method + isEqualToString:@"MobileAds#disableMediationInitialization"]) { [GADMobileAds.sharedInstance disableMediationInitialization]; result(nil); } else if ([call.method isEqualToString:@"MobileAds#openDebugMenu"]) { NSString *adUnitId = call.arguments[@"adUnitId"]; GADDebugOptionsViewController *debugOptionsViewController = - [GADDebugOptionsViewController debugOptionsViewControllerWithAdUnitID:adUnitId]; - [rootController presentViewController:debugOptionsViewController animated:YES completion:nil]; + [GADDebugOptionsViewController + debugOptionsViewControllerWithAdUnitID:adUnitId]; + [rootController presentViewController:debugOptionsViewController + animated:YES + completion:nil]; result(nil); } else if ([call.method isEqualToString:@"MobileAds#openAdInspector"]) { [GADMobileAds.sharedInstance @@ -273,7 +302,8 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result completionHandler:^(NSError *error) { if (error) { result([FlutterError - errorWithCode:[[NSString alloc] initWithInt:error.code] + errorWithCode:[[NSString alloc] + initWithInt:error.code] message:error.localizedDescription details:error.domain]); } else { @@ -281,22 +311,28 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result } }]; } else if ([call.method isEqualToString:@"MobileAds#getVersionString"]) { - result(GADGetStringFromVersionNumber(GADMobileAds.sharedInstance.versionNumber)); - } else if ([call.method isEqualToString:@"MobileAds#getRequestConfiguration"]) { + result(GADGetStringFromVersionNumber( + GADMobileAds.sharedInstance.versionNumber)); + } else if ([call.method + isEqualToString:@"MobileAds#getRequestConfiguration"]) { result(GADMobileAds.sharedInstance.requestConfiguration); } else if ([call.method isEqualToString:@"MobileAds#registerWebView"]) { if (!_appDelegate) { NSLog(@"App delegate is null in MobileAds#registerWebView, skipping"); } else { NSNumber *webViewId = call.arguments[@"webViewId"]; - WKWebView *webView = [FLTAdUtil getWebView:webViewId flutterPluginRegistry:_appDelegate]; + WKWebView *webView = [FLTAdUtil getWebView:webViewId + flutterPluginRegistry:_appDelegate]; [GADMobileAds.sharedInstance registerWebView:webView]; } result(nil); - } else if ([call.method isEqualToString:@"MobileAds#updateRequestConfiguration"]) { + } else if ([call.method + isEqualToString:@"MobileAds#updateRequestConfiguration"]) { NSString *maxAdContentRating = call.arguments[@"maxAdContentRating"]; - NSNumber *tagForChildDirectedTreatment = call.arguments[@"tagForChildDirectedTreatment"]; - NSNumber *tagForUnderAgeOfConsent = call.arguments[@"tagForUnderAgeOfConsent"]; + NSNumber *tagForChildDirectedTreatment = + call.arguments[@"tagForChildDirectedTreatment"]; + NSNumber *tagForUnderAgeOfConsent = + call.arguments[@"tagForUnderAgeOfConsent"]; NSArray *testDeviceIds = call.arguments[@"testDeviceIds"]; if (maxAdContentRating != NULL && maxAdContentRating != (id)[NSNull null]) { @@ -314,63 +350,76 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result GADMaxAdContentRatingMatureAudience; } } - if (tagForChildDirectedTreatment != NULL && tagForChildDirectedTreatment != (id)[NSNull null]) { + if (tagForChildDirectedTreatment != NULL && + tagForChildDirectedTreatment != (id)[NSNull null]) { switch ([tagForChildDirectedTreatment intValue]) { - case 0: - GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment = @NO; - break; - case 1: - GADMobileAds.sharedInstance.requestConfiguration.tagForChildDirectedTreatment = @YES; - break; + case 0: + GADMobileAds.sharedInstance.requestConfiguration + .tagForChildDirectedTreatment = @NO; + break; + case 1: + GADMobileAds.sharedInstance.requestConfiguration + .tagForChildDirectedTreatment = @YES; + break; } } - if (tagForUnderAgeOfConsent != NULL && tagForUnderAgeOfConsent != (id)[NSNull null]) { + if (tagForUnderAgeOfConsent != NULL && + tagForUnderAgeOfConsent != (id)[NSNull null]) { switch ([tagForUnderAgeOfConsent intValue]) { - case 0: - GADMobileAds.sharedInstance.requestConfiguration.tagForUnderAgeOfConsent = @NO; - break; - case 1: - GADMobileAds.sharedInstance.requestConfiguration.tagForUnderAgeOfConsent = @YES; - break; + case 0: + GADMobileAds.sharedInstance.requestConfiguration + .tagForUnderAgeOfConsent = @NO; + break; + case 1: + GADMobileAds.sharedInstance.requestConfiguration + .tagForUnderAgeOfConsent = @YES; + break; } } if (testDeviceIds != NULL && testDeviceIds != (id)[NSNull null]) { - GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = testDeviceIds; + GADMobileAds.sharedInstance.requestConfiguration.testDeviceIdentifiers = + testDeviceIds; } result(nil); } else if ([call.method isEqualToString:@"loadBannerAd"]) { - FLTBannerAd *ad = [[FLTBannerAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - size:call.arguments[@"size"] - request:call.arguments[@"request"] - rootViewController:rootController - adId:call.arguments[@"adId"]]; + FLTBannerAd *ad = + [[FLTBannerAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + size:call.arguments[@"size"] + request:call.arguments[@"request"] + rootViewController:rootController + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadAdManagerBannerAd"]) { - FLTGAMBannerAd *ad = [[FLTGAMBannerAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - sizes:call.arguments[@"sizes"] - request:call.arguments[@"request"] - rootViewController:rootController - adId:call.arguments[@"adId"]]; + FLTGAMBannerAd *ad = + [[FLTGAMBannerAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + sizes:call.arguments[@"sizes"] + request:call.arguments[@"request"] + rootViewController:rootController + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadFluidAd"]) { - FLTFluidGAMBannerAd *ad = - [[FLTFluidGAMBannerAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - request:call.arguments[@"request"] - rootViewController:rootController - adId:call.arguments[@"adId"]]; + FLTFluidGAMBannerAd *ad = [[FLTFluidGAMBannerAd alloc] + initWithAdUnitId:call.arguments[@"adUnitId"] + request:call.arguments[@"request"] + rootViewController:rootController + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadNativeAd"]) { NSString *factoryId = call.arguments[@"factoryId"]; id factory = _nativeAdFactories[factoryId]; - FLTNativeTemplateStyle *templateStyle = call.arguments[@"nativeTemplateStyle"]; + FLTNativeTemplateStyle *templateStyle = + call.arguments[@"nativeTemplateStyle"]; if ([FLTAdUtil isNull:factory] && [FLTAdUtil isNull:templateStyle]) { - NSString *message = [NSString stringWithFormat:@"Can't find NativeAdFactory with id: %@ " - @"and nativeTemplateStyle is null", - factoryId]; - result([FlutterError errorWithCode:@"NativeAdError" message:message details:nil]); + NSString *message = + [NSString stringWithFormat:@"Can't find NativeAdFactory with id: %@ " + @"and nativeTemplateStyle is null", + factoryId]; + result([FlutterError errorWithCode:@"NativeAdError" + message:message + details:nil]); return; } @@ -381,27 +430,29 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result request = call.arguments[@"adManagerRequest"]; } - FLTNativeAd *ad = [[FLTNativeAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - request:request - nativeAdFactory:(id)factory - customOptions:call.arguments[@"customOptions"] - rootViewController:rootController - adId:call.arguments[@"adId"] - nativeAdOptions:call.arguments[@"nativeAdOptions"] - nativeTemplateStyle:call.arguments[@"nativeTemplateStyle"]]; + FLTNativeAd *ad = [[FLTNativeAd alloc] + initWithAdUnitId:call.arguments[@"adUnitId"] + request:request + nativeAdFactory:(id)factory + customOptions:call.arguments[@"customOptions"] + rootViewController:rootController + adId:call.arguments[@"adId"] + nativeAdOptions:call.arguments[@"nativeAdOptions"] + nativeTemplateStyle:call.arguments[@"nativeTemplateStyle"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadInterstitialAd"]) { - FLTInterstitialAd *ad = [[FLTInterstitialAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - request:call.arguments[@"request"] - adId:call.arguments[@"adId"]]; + FLTInterstitialAd *ad = + [[FLTInterstitialAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + request:call.arguments[@"request"] + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadAdManagerInterstitialAd"]) { - FLTGAMInterstitialAd *ad = - [[FLTGAMInterstitialAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - request:call.arguments[@"request"] - adId:call.arguments[@"adId"]]; + FLTGAMInterstitialAd *ad = [[FLTGAMInterstitialAd alloc] + initWithAdUnitId:call.arguments[@"adUnitId"] + request:call.arguments[@"request"] + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadRewardedAd"]) { @@ -411,15 +462,17 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result } else if ([FLTAdUtil isNotNull:call.arguments[@"adManagerRequest"]]) { request = call.arguments[@"adManagerRequest"]; } else { - result([FlutterError errorWithCode:@"InvalidRequest" - message:@"A null or invalid ad request was provided." - details:nil]); + result([FlutterError + errorWithCode:@"InvalidRequest" + message:@"A null or invalid ad request was provided." + details:nil]); return; } - FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - request:request - adId:call.arguments[@"adId"]]; + FLTRewardedAd *ad = + [[FLTRewardedAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + request:request + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadRewardedInterstitialAd"]) { @@ -429,16 +482,17 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result } else if ([FLTAdUtil isNotNull:call.arguments[@"adManagerRequest"]]) { request = call.arguments[@"adManagerRequest"]; } else { - result([FlutterError errorWithCode:@"InvalidRequest" - message:@"A null or invalid ad request was provided." - details:nil]); + result([FlutterError + errorWithCode:@"InvalidRequest" + message:@"A null or invalid ad request was provided." + details:nil]); return; } - FLTRewardedInterstitialAd *ad = - [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - request:request - adId:call.arguments[@"adId"]]; + FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] + initWithAdUnitId:call.arguments[@"adUnitId"] + request:request + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadAppOpenAd"]) { @@ -448,27 +502,31 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result } else if ([FLTAdUtil isNotNull:call.arguments[@"adManagerRequest"]]) { request = call.arguments[@"adManagerRequest"]; } else { - result([FlutterError errorWithCode:@"InvalidRequest" - message:@"A null or invalid ad request was provided." - details:nil]); + result([FlutterError + errorWithCode:@"InvalidRequest" + message:@"A null or invalid ad request was provided." + details:nil]); return; } - FLTAppOpenAd *ad = [[FLTAppOpenAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] - request:request - adId:call.arguments[@"adId"]]; + FLTAppOpenAd *ad = + [[FLTAppOpenAd alloc] initWithAdUnitId:call.arguments[@"adUnitId"] + request:request + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"disposeAd"]) { [_manager dispose:call.arguments[@"adId"]]; result(nil); } else if ([call.method isEqualToString:@"showAdWithoutView"]) { - [_manager showAdWithID:call.arguments[@"adId"] rootViewController:rootController]; + [_manager showAdWithID:call.arguments[@"adId"] + rootViewController:rootController]; result(nil); - } else if ([call.method isEqualToString:@"AdSize#getAnchoredAdaptiveBannerAdSize"]) { - FLTAnchoredAdaptiveBannerSize *size = - [[FLTAnchoredAdaptiveBannerSize alloc] initWithFactory:[[FLTAdSizeFactory alloc] init] - orientation:call.arguments[@"orientation"] - width:call.arguments[@"width"]]; + } else if ([call.method + isEqualToString:@"AdSize#getAnchoredAdaptiveBannerAdSize"]) { + FLTAnchoredAdaptiveBannerSize *size = [[FLTAnchoredAdaptiveBannerSize alloc] + initWithFactory:[[FLTAdSizeFactory alloc] init] + orientation:call.arguments[@"orientation"] + width:call.arguments[@"width"]]; if (IsGADAdSizeValid(size.size)) { result(size.height); } else { @@ -486,14 +544,17 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result } else { result(FlutterMethodNotImplemented); } - } else if ([call.method isEqualToString:@"setServerSideVerificationOptions"]) { + } else if ([call.method + isEqualToString:@"setServerSideVerificationOptions"]) { id ad = [_manager adFor:call.arguments[@"adId"]]; - FLTServerSideVerificationOptions *options = call.arguments[@"serverSideVerificationOptions"]; + FLTServerSideVerificationOptions *options = + call.arguments[@"serverSideVerificationOptions"]; if ([ad isKindOfClass:[FLTRewardedAd class]]) { FLTRewardedAd *rewardedAd = (FLTRewardedAd *)ad; [rewardedAd setServerSideVerificationOptions:options]; } else if ([ad isKindOfClass:[FLTRewardedInterstitialAd class]]) { - FLTRewardedInterstitialAd *rewardedInterstitialAd = (FLTRewardedInterstitialAd *)ad; + FLTRewardedInterstitialAd *rewardedInterstitialAd = + (FLTRewardedInterstitialAd *)ad; [rewardedInterstitialAd setServerSideVerificationOptions:options]; } else { NSLog(@"Error - setServerSideVerificationOptions called on missing or " From 3020ed8fd1922efef2fff0d5ddf323c2f1ade555 Mon Sep 17 00:00:00 2001 From: Aldo Becerril Date: Fri, 9 Aug 2024 13:21:05 -0700 Subject: [PATCH 08/15] format fix --- .../ios/RunnerTests/FLTAppOpenAdTest.m | 14 ++++---- .../ios/RunnerTests/FLTGoogleMobileAdsTest.m | 34 +++++++++--------- .../ios/RunnerTests/FLTInterstitialAdTest.m | 14 ++++---- .../ios/RunnerTests/FLTRewardedAdTest.m | 14 ++++---- .../Classes/FLTAdInstanceManager_Internal.h | 2 +- .../Classes/FLTAdInstanceManager_Internal.m | 2 +- .../ios/Classes/FLTAd_Internal.h | 3 +- .../ios/Classes/FLTAd_Internal.m | 15 +++++--- .../ios/Classes/FLTGoogleMobileAdsPlugin.m | 36 ++++++++----------- 9 files changed, 63 insertions(+), 71 deletions(-) diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m index dfc65a59d..efdbfd921 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m @@ -58,10 +58,9 @@ - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request gadOrGAMRequest:(GADRequest *)gadOrGAMRequest { UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); - FLTAppOpenAd *ad = - [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + FLTAppOpenAd *ad = [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; // Stub the load call to invoke successful load callback. @@ -161,10 +160,9 @@ - (void)testFailedToLoadGAMRequest { // Helper for testing failed to load. - (void)testFailedToLoad:(FLTAdRequest *)request { - FLTAppOpenAd *ad = - [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + FLTAppOpenAd *ad = [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id appOpenClassMock = OCMClassMock([GADAppOpenAd class]); diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m index 5cccc781f..427b5e3df 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m @@ -249,10 +249,10 @@ - (void)testAdInstanceManagerOnNativeAdEvents { } - (void)testAdInstanceManagerOnRewardedAdUserEarnedReward { - FLTRewardedAd *ad = [[FLTRewardedAd alloc] - initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + FLTRewardedAd *ad = + [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager loadAd:ad]; [_manager onRewardedAdUserEarnedReward:ad @@ -276,9 +276,9 @@ - (void)testAdInstanceManagerOnRewardedAdUserEarnedReward { - (void)testAdInstanceManagerOnRewardedInterstitialAdUserEarnedReward { FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] - initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager loadAd:ad]; [_manager @@ -367,10 +367,10 @@ - (void)testBannerEvents { } - (void)testFullScreenEventsRewardedAd { - FLTRewardedAd *rewardedAd = [[FLTRewardedAd alloc] - initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + FLTRewardedAd *rewardedAd = + [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager loadAd:rewardedAd]; [_manager adWillPresentFullScreenContent:rewardedAd]; @@ -397,9 +397,9 @@ - (void)testFullScreenEventsRewardedAd { - (void)testFullScreenEventsRewardedInterstitialAd { FLTRewardedInterstitialAd *rewardedInterstitialAd = [[FLTRewardedInterstitialAd alloc] - initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager loadAd:rewardedInterstitialAd]; [_manager adWillPresentFullScreenContent:rewardedInterstitialAd]; @@ -460,9 +460,9 @@ - (NSData *)getDataForEvent:(NSString *)name adId:(NSNumber *)adId { - (void)testAdClick { FLTRewardedInterstitialAd *rewardedInterstitialAd = [[FLTRewardedInterstitialAd alloc] - initWithAdUnitId:@"testId" - request:[[FLTAdRequest alloc] init] - adId:@1]; + initWithAdUnitId:@"testId" + request:[[FLTAdRequest alloc] init] + adId:@1]; [_manager adDidRecordClick:rewardedInterstitialAd]; NSData *impressionData = [self getDataForEvent:@"adDidRecordClick" adId:@1]; diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m index 02819d7f3..16fbf3cd8 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m @@ -37,10 +37,9 @@ - (void)testLoadShowInterstitialAd { UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); - FLTInterstitialAd *ad = - [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + FLTInterstitialAd *ad = [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id interstitialClassMock = OCMClassMock([GADInterstitialAd class]); @@ -128,10 +127,9 @@ - (void)testFailedToLoad { GADRequest *gadRequest = OCMClassMock([GADRequest class]); OCMStub([request asGADRequest:[OCMArg any]]).andReturn(gadRequest); - FLTInterstitialAd *ad = - [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + FLTInterstitialAd *ad = [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id interstitialClassMock = OCMClassMock([GADInterstitialAd class]); diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m index a64936b57..9da13d63a 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m @@ -52,10 +52,9 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request gadOrGAMRequest:(GADRequest *)gadOrGAMRequest { UIViewController *mockRootViewController = OCMClassMock([UIViewController class]); - FLTRewardedAd *ad = - [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; // Stub the load call to invoke successful load callback. @@ -215,10 +214,9 @@ - (void)testFailedToLoadGAMRequest { // Helper for testing failed to load. - (void)testFailedToLoad:(FLTAdRequest *)request { - FLTRewardedAd *ad = - [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" - request:request - adId:@1]; + FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" + request:request + adId:@1]; ad.manager = mockManager; id rewardedClassMock = OCMClassMock([GADRewardedAd class]); diff --git a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h index 1ddf4096e..26701a8ea 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h +++ b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h @@ -33,7 +33,7 @@ - (void)loadAd:(id _Nonnull)ad; - (void)dispose:(NSNumber *_Nonnull)adId; - (void)showAdWithID:(NSNumber *_Nonnull)adId - rootViewController:(UIViewController *_Nonnull)rootViewController; + rootViewController:(UIViewController *_Nonnull)rootViewController; - (void)onAdLoaded:(id _Nonnull)ad responseInfo:(GADResponseInfo *_Nonnull)responseInfo; - (void)onAdFailedToLoad:(id _Nonnull)ad error:(NSError *_Nonnull)error; diff --git a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m index 2ec069c95..e77d73f7c 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m @@ -68,7 +68,7 @@ - (void)disposeAllAds { } - (void)showAdWithID:(NSNumber *_Nonnull)adId - rootViewController:(UIViewController *_Nonnull)rootViewController{ + rootViewController:(UIViewController *_Nonnull)rootViewController{ id ad = (id)[self adFor:adId]; if (!ad) { diff --git a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h index 2f3264a56..a1f32b8b5 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h +++ b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h @@ -164,7 +164,8 @@ @end @protocol FLTAdWithoutView -- (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewController; +- (void)showFromRootViewController: + (UIViewController *_Nonnull)rootViewController; @end @interface FLTBaseAd : NSObject diff --git a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m index 12ae3348a..cce9efe02 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m @@ -726,7 +726,8 @@ - (void)load { }]; } -- (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewController { +- (void)showFromRootViewController: + (UIViewController *_Nonnull)rootViewController { if (self.interstitial) { [self.interstitial presentFromRootViewController:rootViewController]; } else { @@ -789,7 +790,8 @@ - (void)load { }]; } -- (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewController { +- (void)showFromRootViewController: + (UIViewController *_Nonnull)rootViewController { if (self.interstitial) { [self.interstitial presentFromRootViewController:rootViewController]; } else { @@ -869,7 +871,8 @@ - (void)load { }]; } -- (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewController { +- (void)showFromRootViewController: + (UIViewController *_Nonnull)rootViewController { if (self.rewardedAd) { [self.rewardedAd presentFromRootViewController:rootViewController @@ -964,7 +967,8 @@ - (void)load { }]; } -- (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewController { +- (void)showFromRootViewController: + (UIViewController *_Nonnull)rootViewController { if (self.rewardedInterstitialAd) { [self.rewardedInterstitialAd presentFromRootViewController:rootViewController @@ -1059,7 +1063,8 @@ - (void)load { }]; } -- (void)showFromRootViewController:(UIViewController *_Nonnull)rootViewController { +- (void)showFromRootViewController: + (UIViewController *_Nonnull)rootViewController { if (self.appOpenAd) { [self.appOpenAd presentFromRootViewController:rootViewController]; } else { diff --git a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m index d76165594..bfcdb4b71 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m +++ b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m @@ -213,23 +213,27 @@ + (BOOL)registerNativeAdFactory:(id)registry - (UIViewController *)rootController { UIViewController *root = - UIApplication.sharedApplication.delegate.window.rootViewController; + UIApplication.sharedApplication.delegate.window.rootViewController; if ([FLTAdUtil isNull:root]) { - // UIApplication.sharedApplication.delegate.window is not guaranteed to be - // set. Use the keyWindow in this case. - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wdeprecated-declarations" +// UIApplication.sharedApplication.delegate.window is not guaranteed to be +// set. Use the keyWindow in this case. +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" root = UIApplication.sharedApplication.keyWindow.rootViewController; - #pragma clang diagnostic pop +#pragma clang diagnostic pop } UIViewController *presentedViewController = root; - while (presentedViewController.presentedViewController && ![presentedViewController.presentedViewController isBeingDismissed]) { + while (presentedViewController.presentedViewController && + ![presentedViewController.presentedViewController isBeingDismissed]) { if ([presentedViewController isKindOfClass:[UITabBarController class]]) { - UITabBarController* tabBarController = (UITabBarController*)presentedViewController; + UITabBarController* tabBarController = + (UITabBarController*)presentedViewController; presentedViewController = tabBarController.selectedViewController; - } else if ([presentedViewController isKindOfClass:[UINavigationController class]]) { - UINavigationController* navigationController = (UINavigationController*)presentedViewController; + } else if ([presentedViewController + isKindOfClass:[UINavigationController class]]) { + UINavigationController* navigationController = + (UINavigationController*)presentedViewController; presentedViewController = navigationController.visibleViewController; } else { presentedViewController = presentedViewController.presentedViewController; @@ -238,18 +242,6 @@ - (UIViewController *)rootController { return presentedViewController; } -- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController { - if ([rootViewController isKindOfClass:[UITabBarController class]]) { - UITabBarController* tabBarController = (UITabBarController*)rootViewController; - return [self topViewControllerWithRootViewController:tabBarController.selectedViewController]; - } else if ([rootViewController isKindOfClass:[UINavigationController class]]) { - UINavigationController* navigationController = (UINavigationController*)rootViewController; - return [self topViewControllerWithRootViewController:navigationController.visibleViewController]; - } else { - return rootViewController; - } -} - - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { NSLog(@"handleMethodCall %@", call.method); From 1c71d40809df6b254bee16182f318a27babac5ce Mon Sep 17 00:00:00 2001 From: Aldo Becerril Date: Fri, 9 Aug 2024 13:25:13 -0700 Subject: [PATCH 09/15] format fix --- .../Classes/FLTAdInstanceManager_Internal.m | 2 +- .../ios/Classes/FLTGoogleMobileAdsPlugin.m | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m index e77d73f7c..60a19047f 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m @@ -68,7 +68,7 @@ - (void)disposeAllAds { } - (void)showAdWithID:(NSNumber *_Nonnull)adId - rootViewController:(UIViewController *_Nonnull)rootViewController{ + rootViewController:(UIViewController *_Nonnull)rootViewController { id ad = (id)[self adFor:adId]; if (!ad) { diff --git a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m index bfcdb4b71..50b356e75 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m +++ b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m @@ -227,13 +227,13 @@ - (UIViewController *)rootController { while (presentedViewController.presentedViewController && ![presentedViewController.presentedViewController isBeingDismissed]) { if ([presentedViewController isKindOfClass:[UITabBarController class]]) { - UITabBarController* tabBarController = - (UITabBarController*)presentedViewController; + UITabBarController *tabBarController = + (UITabBarController *)presentedViewController; presentedViewController = tabBarController.selectedViewController; } else if ([presentedViewController isKindOfClass:[UINavigationController class]]) { - UINavigationController* navigationController = - (UINavigationController*)presentedViewController; + UINavigationController *navigationController = + (UINavigationController *)presentedViewController; presentedViewController = navigationController.visibleViewController; } else { presentedViewController = presentedViewController.presentedViewController; @@ -442,9 +442,9 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result(nil); } else if ([call.method isEqualToString:@"loadAdManagerInterstitialAd"]) { FLTGAMInterstitialAd *ad = [[FLTGAMInterstitialAd alloc] - initWithAdUnitId:call.arguments[@"adUnitId"] - request:call.arguments[@"request"] - adId:call.arguments[@"adId"]]; + initWithAdUnitId:call.arguments[@"adUnitId"] + request:call.arguments[@"request"] + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadRewardedAd"]) { @@ -482,9 +482,9 @@ - (void)handleMethodCall:(FlutterMethodCall *)call } FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] - initWithAdUnitId:call.arguments[@"adUnitId"] - request:request - adId:call.arguments[@"adId"]]; + initWithAdUnitId:call.arguments[@"adUnitId"] + request:request + adId:call.arguments[@"adId"]]; [_manager loadAd:ad]; result(nil); } else if ([call.method isEqualToString:@"loadAppOpenAd"]) { From 15f04302c9e7e7905292dfc84573e5d625ff2846 Mon Sep 17 00:00:00 2001 From: Aldo Becerril Date: Mon, 12 Aug 2024 11:57:16 -0700 Subject: [PATCH 10/15] Removed rootViewController reference for fullscreen ads --- .../ios/Runner.xcodeproj/project.pbxproj | 89 ------------------- .../example/ios/Runner/Info.plist | 2 +- .../ios/RunnerTests/FLTAppOpenAdTest.m | 2 +- .../RunnerTests/FLTGamInterstitialAdTest.m | 2 +- .../ios/RunnerTests/FLTInterstitialAdTest.m | 2 +- .../ios/RunnerTests/FLTRewardedAdTest.m | 2 +- .../FLTRewardedInterstitialAdTest.m | 2 +- .../Classes/FLTAdInstanceManager_Internal.h | 3 +- .../Classes/FLTAdInstanceManager_Internal.m | 5 +- .../ios/Classes/FLTAd_Internal.h | 3 +- .../ios/Classes/FLTAd_Internal.m | 25 +++--- .../ios/Classes/FLTGoogleMobileAdsPlugin.m | 4 +- 12 files changed, 21 insertions(+), 120 deletions(-) diff --git a/packages/google_mobile_ads/example/ios/Runner.xcodeproj/project.pbxproj b/packages/google_mobile_ads/example/ios/Runner.xcodeproj/project.pbxproj index ed5150ba5..3d588697c 100644 --- a/packages/google_mobile_ads/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/google_mobile_ads/example/ios/Runner.xcodeproj/project.pbxproj @@ -37,8 +37,6 @@ 9E61AA6029BBE8FD00801A83 /* FLTNativeTemplateStyleTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E61AA5B29BBE8FD00801A83 /* FLTNativeTemplateStyleTest.m */; }; 9E61AA6129BBE8FD00801A83 /* FLTNativeTemplateFontStyleTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E61AA5C29BBE8FD00801A83 /* FLTNativeTemplateFontStyleTest.m */; }; 9E61AA6229BBE8FD00801A83 /* FLTNativeTemplateColorTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 9E61AA5D29BBE8FD00801A83 /* FLTNativeTemplateColorTest.m */; }; - C032D0C69E82A86DA475F8FE /* libPods-RunnerTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 72FE6B99C77221F59BD2657E /* libPods-RunnerTests.a */; }; - CB51B8C665175A2D77BE7B0B /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 552A358A77902B418501B0E8 /* libPods-Runner.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -67,13 +65,8 @@ /* Begin PBXFileReference section */ 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; - 27B7088677C69B9B87E86B96 /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 44F3DED22B745BEE004D7117 /* FLTMediationExtras.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = FLTMediationExtras.h; path = ../../ios/Classes/FLTMediationExtras.h; sourceTree = ""; }; - 5088939374F111D280B15613 /* Pods-RunnerTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.release.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.release.xcconfig"; sourceTree = ""; }; - 552A358A77902B418501B0E8 /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - 72FE6B99C77221F59BD2657E /* libPods-RunnerTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RunnerTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - 7382CA922D972355676543EB /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; @@ -157,7 +150,6 @@ 9EF4E6FE26392B230007E4FE /* FLTGoogleMobileAdsCollection_Internal.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FLTGoogleMobileAdsCollection_Internal.m; path = ../../ios/Classes/FLTGoogleMobileAdsCollection_Internal.m; sourceTree = ""; }; 9EF4E6FF26392B230007E4FE /* FLTMobileAds_Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = FLTMobileAds_Internal.h; path = ../../ios/Classes/FLTMobileAds_Internal.h; sourceTree = ""; }; 9EFEAB4E29B0019F000A063B /* GoogleMobileAds.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = GoogleMobileAds.xcframework; path = "Pods/Google-Mobile-Ads-SDK/Frameworks/GoogleMobileAdsFramework/GoogleMobileAds.xcframework"; sourceTree = ""; }; - B01820B337C2EF12599D0744 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -165,7 +157,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - CB51B8C665175A2D77BE7B0B /* libPods-Runner.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -173,7 +164,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - C032D0C69E82A86DA475F8FE /* libPods-RunnerTests.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -183,10 +173,6 @@ 194BB02CA5CDABA098EA0B10 /* Pods */ = { isa = PBXGroup; children = ( - B01820B337C2EF12599D0744 /* Pods-Runner.debug.xcconfig */, - 7382CA922D972355676543EB /* Pods-Runner.release.xcconfig */, - 27B7088677C69B9B87E86B96 /* Pods-RunnerTests.debug.xcconfig */, - 5088939374F111D280B15613 /* Pods-RunnerTests.release.xcconfig */, ); path = Pods; sourceTree = ""; @@ -197,8 +183,6 @@ 9EFEAB4E29B0019F000A063B /* GoogleMobileAds.xcframework */, 9EB9FE57280F853D00DDBB4F /* UserMessagingPlatform.xcframework */, 9EA7213525BB6464008D57E3 /* GoogleMobileAds.xcframework */, - 552A358A77902B418501B0E8 /* libPods-Runner.a */, - 72FE6B99C77221F59BD2657E /* libPods-RunnerTests.a */, ); name = Frameworks; sourceTree = ""; @@ -384,14 +368,12 @@ isa = PBXNativeTarget; buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; buildPhases = ( - E92B7B87E1A00D5F29391D09 /* [CP] Check Pods Manifest.lock */, 9740EEB61CF901F6004384FC /* Run Script */, 97C146EA1CF9000F007C117D /* Sources */, 97C146EB1CF9000F007C117D /* Frameworks */, 97C146EC1CF9000F007C117D /* Resources */, 9705A1C41CF9048500538489 /* Embed Frameworks */, 3B06AD1E1E4923F5004D2608 /* Thin Binary */, - 88D22564A698FDC5B3114D86 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -406,7 +388,6 @@ isa = PBXNativeTarget; buildConfigurationList = 9E61AA1E29BBE51900801A83 /* Build configuration list for PBXNativeTarget "RunnerTests" */; buildPhases = ( - A1476C20D685A26F4507611D /* [CP] Check Pods Manifest.lock */, 9E61AA1229BBE51900801A83 /* Sources */, 9E61AA1329BBE51900801A83 /* Frameworks */, 9E61AA1429BBE51900801A83 /* Resources */, @@ -498,30 +479,6 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed\n/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin\n"; }; - 88D22564A698FDC5B3114D86 /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh", - "${PODS_CONFIGURATION_BUILD_DIR}/Google-Mobile-Ads-SDK/GoogleMobileAdsResources.bundle", - "${PODS_CONFIGURATION_BUILD_DIR}/GoogleUserMessagingPlatform/UserMessagingPlatformResources.bundle", - "${PODS_CONFIGURATION_BUILD_DIR}/google_mobile_ads/google_mobile_ads.bundle", - "${PODS_CONFIGURATION_BUILD_DIR}/webview_flutter_wkwebview/webview_flutter_wkwebview_privacy.bundle", - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/GoogleMobileAdsResources.bundle", - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/UserMessagingPlatformResources.bundle", - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/google_mobile_ads.bundle", - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/webview_flutter_wkwebview_privacy.bundle", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; alwaysOutOfDate = 1; @@ -537,50 +494,6 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build\n"; }; - A1476C20D685A26F4507611D /* [CP] Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; - outputFileListPaths = ( - ); - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-RunnerTests-checkManifestLockResult.txt", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; - showEnvVarsInLog = 0; - }; - E92B7B87E1A00D5F29391D09 /* [CP] Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; - outputFileListPaths = ( - ); - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; - showEnvVarsInLog = 0; - }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -819,7 +732,6 @@ }; 9E61AA1C29BBE51900801A83 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 27B7088677C69B9B87E86B96 /* Pods-RunnerTests.debug.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; @@ -846,7 +758,6 @@ }; 9E61AA1D29BBE51900801A83 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 5088939374F111D280B15613 /* Pods-RunnerTests.release.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; diff --git a/packages/google_mobile_ads/example/ios/Runner/Info.plist b/packages/google_mobile_ads/example/ios/Runner/Info.plist index 36a0058fe..924f1d9a8 100644 --- a/packages/google_mobile_ads/example/ios/Runner/Info.plist +++ b/packages/google_mobile_ads/example/ios/Runner/Info.plist @@ -21,7 +21,7 @@ CFBundleVersion 1 GADApplicationIdentifier - ca-app-pub-3212738706492790~4234003410 + ca-app-pub-3940256099942544~1458002511 LSRequiresIPhoneOS SKAdNetworkItems diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m index efdbfd921..3c3516059 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m @@ -126,7 +126,7 @@ - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request return TRUE; }]]); - [ad showFromRootViewController:mockRootViewController]; + [ad show]; OCMVerify([appOpenClassMock presentFromRootViewController:[OCMArg isEqual:mockRootViewController]]); diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m index c3d55f8d7..676b0828a 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m @@ -117,7 +117,7 @@ - (void)testLoadShowInterstitialAd { }]]); // Show the ad - [ad showFromRootViewController:mockRootViewController]; + [ad show]; OCMVerify([interstitialClassMock presentFromRootViewController:[OCMArg isEqual:mockRootViewController]]); diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m index 16fbf3cd8..fa25be2c8 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m @@ -105,7 +105,7 @@ - (void)testLoadShowInterstitialAd { }]]); // Show the ad - [ad showFromRootViewController:mockRootViewController]; + [ad show]; OCMVerify([interstitialClassMock presentFromRootViewController:[OCMArg isEqual:mockRootViewController]]); diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m index 9da13d63a..696fcd4d5 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m @@ -145,7 +145,7 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request setServerSideVerificationOptions:[OCMArg isEqual:gadOptions]]); // Show the ad and verify callbacks invoked - [ad showFromRootViewController:mockRootViewController]; + [ad show]; OCMVerify([rewardedClassMock presentFromRootViewController:[OCMArg isEqual:mockRootViewController] diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m index 261a9e049..8a795e42c 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m @@ -151,7 +151,7 @@ - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request setServerSideVerificationOptions:[OCMArg isEqual:gadOptions]]); // Show the ad and verify callbacks are invoked - [ad showFromRootViewController:mockRootViewController]; + [ad show]; OCMVerify([rewardedInterstitialClassMock presentFromRootViewController:[OCMArg isEqual:mockRootViewController] diff --git a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h index 26701a8ea..1e8dd5549 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h +++ b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.h @@ -32,8 +32,7 @@ - (NSNumber *_Nullable)adIdFor:(id _Nonnull)ad; - (void)loadAd:(id _Nonnull)ad; - (void)dispose:(NSNumber *_Nonnull)adId; -- (void)showAdWithID:(NSNumber *_Nonnull)adId - rootViewController:(UIViewController *_Nonnull)rootViewController; +- (void)showAdWithID:(NSNumber *_Nonnull)adId; - (void)onAdLoaded:(id _Nonnull)ad responseInfo:(GADResponseInfo *_Nonnull)responseInfo; - (void)onAdFailedToLoad:(id _Nonnull)ad error:(NSError *_Nonnull)error; diff --git a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m index 60a19047f..6f8e856cc 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTAdInstanceManager_Internal.m @@ -67,8 +67,7 @@ - (void)disposeAllAds { [_ads removeAllObjects]; } -- (void)showAdWithID:(NSNumber *_Nonnull)adId - rootViewController:(UIViewController *_Nonnull)rootViewController { +- (void)showAdWithID:(NSNumber *_Nonnull)adId { id ad = (id)[self adFor:adId]; if (!ad) { @@ -76,7 +75,7 @@ - (void)showAdWithID:(NSNumber *_Nonnull)adId return; } - [ad showFromRootViewController:rootViewController]; + [ad show]; } - (void)onAdLoaded:(id _Nonnull)ad diff --git a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h index a1f32b8b5..7d8b79f65 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h +++ b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.h @@ -164,8 +164,7 @@ @end @protocol FLTAdWithoutView -- (void)showFromRootViewController: - (UIViewController *_Nonnull)rootViewController; +- (void)show; @end @interface FLTBaseAd : NSObject diff --git a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m index cce9efe02..23cdb5120 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m @@ -726,10 +726,9 @@ - (void)load { }]; } -- (void)showFromRootViewController: - (UIViewController *_Nonnull)rootViewController { +- (void)show { if (self.interstitial) { - [self.interstitial presentFromRootViewController:rootViewController]; + [self.interstitial presentFromRootViewController:nil]; } else { NSLog(@"InterstitialAd failed to show because the ad was not ready."); } @@ -790,10 +789,9 @@ - (void)load { }]; } -- (void)showFromRootViewController: - (UIViewController *_Nonnull)rootViewController { +- (void)show { if (self.interstitial) { - [self.interstitial presentFromRootViewController:rootViewController]; + [self.interstitial presentFromRootViewController:nil]; } else { NSLog(@"InterstitialAd failed to show because the ad was not ready."); } @@ -871,11 +869,10 @@ - (void)load { }]; } -- (void)showFromRootViewController: - (UIViewController *_Nonnull)rootViewController { +- (void)show { if (self.rewardedAd) { [self.rewardedAd - presentFromRootViewController:rootViewController + presentFromRootViewController:nil userDidEarnRewardHandler:^{ GADAdReward *reward = self.rewardedAd.adReward; FLTRewardItem *fltReward = @@ -967,11 +964,10 @@ - (void)load { }]; } -- (void)showFromRootViewController: - (UIViewController *_Nonnull)rootViewController { +- (void)show { if (self.rewardedInterstitialAd) { [self.rewardedInterstitialAd - presentFromRootViewController:rootViewController + presentFromRootViewController:nil userDidEarnRewardHandler:^{ GADAdReward *reward = self.rewardedInterstitialAd.adReward; FLTRewardItem *fltReward = @@ -1063,10 +1059,9 @@ - (void)load { }]; } -- (void)showFromRootViewController: - (UIViewController *_Nonnull)rootViewController { +- (void)show { if (self.appOpenAd) { - [self.appOpenAd presentFromRootViewController:rootViewController]; + [self.appOpenAd presentFromRootViewController:nil]; } else { NSLog(@"AppOpenAd failed to show because the ad was not ready."); } diff --git a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m index 50b356e75..83036603e 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m +++ b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m @@ -244,7 +244,6 @@ - (UIViewController *)rootController { - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result { - NSLog(@"handleMethodCall %@", call.method); UIViewController *rootController = self.rootController; if ([call.method isEqualToString:@"MobileAds#initialize"]) { @@ -510,8 +509,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call [_manager dispose:call.arguments[@"adId"]]; result(nil); } else if ([call.method isEqualToString:@"showAdWithoutView"]) { - [_manager showAdWithID:call.arguments[@"adId"] - rootViewController:rootController]; + [_manager showAdWithID:call.arguments[@"adId"]]; result(nil); } else if ([call.method isEqualToString:@"AdSize#getAnchoredAdaptiveBannerAdSize"]) { From 1558236b190b97aca9bec9c99d461cb8f6421014 Mon Sep 17 00:00:00 2001 From: Aldo Becerril Date: Mon, 12 Aug 2024 11:59:26 -0700 Subject: [PATCH 11/15] Revert Podfile change --- packages/google_mobile_ads/example/ios/Podfile | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/google_mobile_ads/example/ios/Podfile b/packages/google_mobile_ads/example/ios/Podfile index fcc8b3e03..03efaafd8 100644 --- a/packages/google_mobile_ads/example/ios/Podfile +++ b/packages/google_mobile_ads/example/ios/Podfile @@ -28,6 +28,7 @@ require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelpe flutter_ios_podfile_setup target 'Runner' do + use_frameworks! use_modular_headers! flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) From 82fc52000baedb7e7ea74e8bcb47f7dca2d8d703 Mon Sep 17 00:00:00 2001 From: Aldo Becerril Date: Mon, 12 Aug 2024 12:04:52 -0700 Subject: [PATCH 12/15] Reverted showFromRootViewController --- packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m index 23cdb5120..aeff03b74 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m +++ b/packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m @@ -619,7 +619,7 @@ - (void)load { format:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]; } -- (void)showFromRootViewController:(UIViewController *)rootViewController { +- (void)show { // Must be overridden by subclasses [NSException raise:NSInternalInconsistencyException From 2cdaa42d2156a37979552df25e75249823908dc7 Mon Sep 17 00:00:00 2001 From: Aldo Becerril Date: Tue, 13 Aug 2024 09:36:34 -0700 Subject: [PATCH 13/15] Adding back comments --- .../google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m index 83036603e..9832c0c9b 100644 --- a/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m +++ b/packages/google_mobile_ads/ios/Classes/FLTGoogleMobileAdsPlugin.m @@ -223,6 +223,8 @@ - (UIViewController *)rootController { #pragma clang diagnostic pop } + // Get the presented view controller. This fixes an issue in the add to app + // case: https://github.com/googleads/googleads-mobile-flutter/issues/700 UIViewController *presentedViewController = root; while (presentedViewController.presentedViewController && ![presentedViewController.presentedViewController isBeingDismissed]) { From 70c895916f2b526fb71dd4af75590cc501ffa3c4 Mon Sep 17 00:00:00 2001 From: Aldo Becerril Date: Tue, 13 Aug 2024 14:16:55 -0700 Subject: [PATCH 14/15] Tests fix --- .../example/ios/RunnerTests/FLTAppOpenAdTest.m | 4 +--- .../example/ios/RunnerTests/FLTGamInterstitialAdTest.m | 4 +--- .../example/ios/RunnerTests/FLTInterstitialAdTest.m | 4 +--- .../example/ios/RunnerTests/FLTRewardedAdTest.m | 4 +--- .../example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m | 4 +--- 5 files changed, 5 insertions(+), 15 deletions(-) diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m index 3c3516059..e67d18485 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m @@ -56,8 +56,6 @@ - (void)testLoadShowGAMRequest { // Helper method for testing with FLTAdRequest and FLTGAMAdRequest. - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request gadOrGAMRequest:(GADRequest *)gadOrGAMRequest { - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); FLTAppOpenAd *ad = [[FLTAppOpenAd alloc] initWithAdUnitId:@"testId" request:request adId:@1]; @@ -129,7 +127,7 @@ - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request [ad show]; OCMVerify([appOpenClassMock - presentFromRootViewController:[OCMArg isEqual:mockRootViewController]]); + presentFromRootViewController:[OCMArg isNil]]); // Verify full screen callbacks. OCMVerify([mockManager adWillPresentFullScreenContent:[OCMArg isEqual:ad]]); diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m index 676b0828a..a881f896c 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m @@ -35,8 +35,6 @@ - (void)testLoadShowInterstitialAd { GAMRequest *gadRequest = OCMClassMock([GAMRequest class]); OCMStub([request asGAMRequest:[OCMArg any]]).andReturn(gadRequest); - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); FLTGAMInterstitialAd *ad = [[FLTGAMInterstitialAd alloc] initWithAdUnitId:@"testId" request:request @@ -120,7 +118,7 @@ - (void)testLoadShowInterstitialAd { [ad show]; OCMVerify([interstitialClassMock - presentFromRootViewController:[OCMArg isEqual:mockRootViewController]]); + presentFromRootViewController:[OCMArg isNil]]); // Verify full screen callbacks. OCMVerify([mockManager adWillPresentFullScreenContent:[OCMArg isEqual:ad]]); diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m index fa25be2c8..e060be037 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m @@ -35,8 +35,6 @@ - (void)testLoadShowInterstitialAd { GADRequest *gadRequest = OCMClassMock([GADRequest class]); OCMStub([request asGADRequest:[OCMArg any]]).andReturn(gadRequest); - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); FLTInterstitialAd *ad = [[FLTInterstitialAd alloc] initWithAdUnitId:@"testId" request:request adId:@1]; @@ -108,7 +106,7 @@ - (void)testLoadShowInterstitialAd { [ad show]; OCMVerify([interstitialClassMock - presentFromRootViewController:[OCMArg isEqual:mockRootViewController]]); + presentFromRootViewController:[OCMArg isNil]]); // Verify full screen callbacks. OCMVerify([mockManager adWillPresentFullScreenContent:[OCMArg isEqual:ad]]); diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m index 696fcd4d5..dc7bd20ce 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m @@ -50,8 +50,6 @@ - (void)testLoadShowRewardedAdGAMRequest { // Helper method for testing with FLTAdRequest and FLTGAMAdRequest. - (void)testLoadShowRewardedAd:(FLTAdRequest *)request gadOrGAMRequest:(GADRequest *)gadOrGAMRequest { - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); FLTRewardedAd *ad = [[FLTRewardedAd alloc] initWithAdUnitId:@"testId" request:request adId:@1]; @@ -148,7 +146,7 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request [ad show]; OCMVerify([rewardedClassMock - presentFromRootViewController:[OCMArg isEqual:mockRootViewController] + presentFromRootViewController:[OCMArg isNil] userDidEarnRewardHandler:[OCMArg any]]); [fullScreenContentDelegate adWillPresentFullScreenContent:rewardedClassMock]; diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m index 8a795e42c..0c5475638 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m @@ -50,8 +50,6 @@ - (void)testLoadShowRewardedInterstitialAdGAMRequest { // Helper method for testing with FLTAdRequest and FLTGAMAdRequest. - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request gadOrGAMRequest:(GADRequest *)gadOrGAMRequest { - UIViewController *mockRootViewController = - OCMClassMock([UIViewController class]); FLTRewardedInterstitialAd *ad = [[FLTRewardedInterstitialAd alloc] initWithAdUnitId:@"testId" request:request @@ -154,7 +152,7 @@ - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request [ad show]; OCMVerify([rewardedInterstitialClassMock - presentFromRootViewController:[OCMArg isEqual:mockRootViewController] + presentFromRootViewController:[OCMArg isNil] userDidEarnRewardHandler:[OCMArg any]]); // Verify full screen callbacks. From 2f0ec220b58243749363456b127d61ad861856aa Mon Sep 17 00:00:00 2001 From: Aldo Becerril Date: Tue, 13 Aug 2024 14:24:37 -0700 Subject: [PATCH 15/15] Format Fix --- .../example/ios/RunnerTests/FLTAppOpenAdTest.m | 3 +-- .../example/ios/RunnerTests/FLTGamInterstitialAdTest.m | 4 ++-- .../example/ios/RunnerTests/FLTInterstitialAdTest.m | 4 ++-- .../example/ios/RunnerTests/FLTRewardedAdTest.m | 5 ++--- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m index e67d18485..1122044e4 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTAppOpenAdTest.m @@ -126,8 +126,7 @@ - (void)testLoadShowAppOpenAd:(FLTAdRequest *)request [ad show]; - OCMVerify([appOpenClassMock - presentFromRootViewController:[OCMArg isNil]]); + OCMVerify([appOpenClassMock presentFromRootViewController:[OCMArg isNil]]); // Verify full screen callbacks. OCMVerify([mockManager adWillPresentFullScreenContent:[OCMArg isEqual:ad]]); diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m index a881f896c..da46fba0b 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTGamInterstitialAdTest.m @@ -117,8 +117,8 @@ - (void)testLoadShowInterstitialAd { // Show the ad [ad show]; - OCMVerify([interstitialClassMock - presentFromRootViewController:[OCMArg isNil]]); + OCMVerify( + [interstitialClassMock presentFromRootViewController:[OCMArg isNil]]); // Verify full screen callbacks. OCMVerify([mockManager adWillPresentFullScreenContent:[OCMArg isEqual:ad]]); diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m index e060be037..d3ef3c13d 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTInterstitialAdTest.m @@ -105,8 +105,8 @@ - (void)testLoadShowInterstitialAd { // Show the ad [ad show]; - OCMVerify([interstitialClassMock - presentFromRootViewController:[OCMArg isNil]]); + OCMVerify( + [interstitialClassMock presentFromRootViewController:[OCMArg isNil]]); // Verify full screen callbacks. OCMVerify([mockManager adWillPresentFullScreenContent:[OCMArg isEqual:ad]]); diff --git a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m index dc7bd20ce..71d6f66d8 100644 --- a/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m +++ b/packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m @@ -145,9 +145,8 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request // Show the ad and verify callbacks invoked [ad show]; - OCMVerify([rewardedClassMock - presentFromRootViewController:[OCMArg isNil] - userDidEarnRewardHandler:[OCMArg any]]); + OCMVerify([rewardedClassMock presentFromRootViewController:[OCMArg isNil] + userDidEarnRewardHandler:[OCMArg any]]); [fullScreenContentDelegate adWillPresentFullScreenContent:rewardedClassMock]; OCMVerify([mockManager adWillPresentFullScreenContent:[OCMArg isEqual:ad]]);