From 50b7f75e49eead10194db368ad5863bba7800e01 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 22 Nov 2024 17:05:24 -0500 Subject: [PATCH 1/2] impl --- packages/interactive_media_ads/CHANGELOG.md | 4 + .../AdsRequestProxyApi.kt | 2 +- .../RunnerTests/AdDisplayContainerTests.swift | 101 +++++++++++- .../AdDisplayContainerProxyAPIDelegate.swift | 43 ++++- .../AdsRequestProxyAPIDelegate.swift | 2 +- .../InteractiveMediaAdsLibrary.g.swift | 123 +++++++++++++- .../lib/src/ios/interactive_media_ads.g.dart | 155 +++++++++++++++++- .../pigeons/interactive_media_ads_ios.dart | 29 +++- packages/interactive_media_ads/pubspec.yaml | 4 +- 9 files changed, 439 insertions(+), 24 deletions(-) diff --git a/packages/interactive_media_ads/CHANGELOG.md b/packages/interactive_media_ads/CHANGELOG.md index c188eda3cd81..77ff5ea6b226 100644 --- a/packages/interactive_media_ads/CHANGELOG.md +++ b/packages/interactive_media_ads/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.3+4 + +* Adds remaining methods for internal wrapper of the iOS native `IMAAdDisplayContainer`. + ## 0.2.3+3 * Adds internal wrapper for Android native `CompanionAdSlot` and `CompanionAdSlot.ClickListener`. diff --git a/packages/interactive_media_ads/android/src/main/kotlin/dev/flutter/packages/interactive_media_ads/AdsRequestProxyApi.kt b/packages/interactive_media_ads/android/src/main/kotlin/dev/flutter/packages/interactive_media_ads/AdsRequestProxyApi.kt index b4a7fa165596..3dec0274efbd 100644 --- a/packages/interactive_media_ads/android/src/main/kotlin/dev/flutter/packages/interactive_media_ads/AdsRequestProxyApi.kt +++ b/packages/interactive_media_ads/android/src/main/kotlin/dev/flutter/packages/interactive_media_ads/AdsRequestProxyApi.kt @@ -21,7 +21,7 @@ class AdsRequestProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) : * * This must match the version in pubspec.yaml. */ - const val pluginVersion = "0.2.3+3" + const val pluginVersion = "0.2.3+4" } override fun setAdTagUrl(pigeon_instance: AdsRequest, adTagUrl: String) { diff --git a/packages/interactive_media_ads/example/ios/RunnerTests/AdDisplayContainerTests.swift b/packages/interactive_media_ads/example/ios/RunnerTests/AdDisplayContainerTests.swift index be3bad268049..2e6fa541fdd8 100644 --- a/packages/interactive_media_ads/example/ios/RunnerTests/AdDisplayContainerTests.swift +++ b/packages/interactive_media_ads/example/ios/RunnerTests/AdDisplayContainerTests.swift @@ -3,6 +3,7 @@ // found in the LICENSE file. import Flutter +import GoogleInteractiveMediaAds import XCTest @testable import interactive_media_ads @@ -13,8 +14,104 @@ final class AdDisplayContainerTests: XCTestCase { let api = registrar.apiDelegate.pigeonApiIMAAdDisplayContainer(registrar) let instance = try? api.pigeonDelegate.pigeonDefaultConstructor( - pigeonApi: api, adContainer: UIView(), adContainerViewController: UIViewController()) - + pigeonApi: api, adContainer: UIView(), companionSlots: [], + adContainerViewController: UIViewController()) XCTAssertNotNil(instance) } + + func testAdContainer() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiIMAAdDisplayContainer(registrar) + + let instance = TestAdDisplayContainer() + let value = try? api.pigeonDelegate.adContainer(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.adContainer) + } + + func testCompanionSlots() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiIMAAdDisplayContainer(registrar) + + let instance = TestAdDisplayContainer() + let value = try? api.pigeonDelegate.companionSlots(pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, instance.companionSlots) + } + + func testSetAdContainerViewController() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiIMAAdDisplayContainer(registrar) + + let instance = TestAdDisplayContainer() + let controller = UIViewController() + try? api.pigeonDelegate.setAdContainerViewController( + pigeonApi: api, pigeonInstance: instance, controller: controller) + + XCTAssertEqual(instance.adContainerViewController, controller) + } + + func testGetAdContainerViewController() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiIMAAdDisplayContainer(registrar) + + let instance = TestAdDisplayContainer() + let adContainerViewController = UIViewController() + instance.adContainerViewController = adContainerViewController + let value = try? api.pigeonDelegate.getAdContainerViewController( + pigeonApi: api, pigeonInstance: instance) + + XCTAssertEqual(value, adContainerViewController) + } + + func testRegisterFriendlyObstruction() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiIMAAdDisplayContainer(registrar) + + let instance = TestAdDisplayContainer() + let friendlyObstruction = IMAFriendlyObstruction( + view: UIView(), purpose: IMAFriendlyObstructionPurpose.closeAd, detailedReason: "reason") + try? api.pigeonDelegate.registerFriendlyObstruction( + pigeonApi: api, pigeonInstance: instance, friendlyObstruction: friendlyObstruction) + + XCTAssertEqual(instance.registerFriendlyObstructionArgs, [friendlyObstruction]) + } + + func testUnregisterAllFriendlyObstructions() { + let registrar = TestProxyApiRegistrar() + let api = registrar.apiDelegate.pigeonApiIMAAdDisplayContainer(registrar) + + let instance = TestAdDisplayContainer() + try? api.pigeonDelegate.unregisterAllFriendlyObstructions( + pigeonApi: api, pigeonInstance: instance) + + XCTAssertTrue(instance.unregisterAllFriendlyObstructionsCalled) + } +} + +class TestAdDisplayContainer: IMAAdDisplayContainer { + private var adContainerTestValue = UIView() + private var companionSlotsTestValue = [IMACompanionAdSlot(view: UIView())] + var registerFriendlyObstructionArgs: [AnyHashable?]? = nil + var unregisterAllFriendlyObstructionsCalled = false + + convenience init() { + self.init(adContainer: UIView(), viewController: UIViewController()) + } + + override var adContainer: UIView { + return adContainerTestValue + } + + override var companionSlots: [IMACompanionAdSlot] { + return companionSlotsTestValue + } + + override func register(_ friendlyObstruction: IMAFriendlyObstruction) { + registerFriendlyObstructionArgs = [friendlyObstruction] + } + + override func unregisterAllFriendlyObstructions() { + unregisterAllFriendlyObstructionsCalled = true + } } diff --git a/packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/AdDisplayContainerProxyAPIDelegate.swift b/packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/AdDisplayContainerProxyAPIDelegate.swift index a7ab7f0f504c..775b3b984e01 100644 --- a/packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/AdDisplayContainerProxyAPIDelegate.swift +++ b/packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/AdDisplayContainerProxyAPIDelegate.swift @@ -12,9 +12,48 @@ import GoogleInteractiveMediaAds class AdDisplayContainerProxyAPIDelegate: PigeonApiDelegateIMAAdDisplayContainer { func pigeonDefaultConstructor( pigeonApi: PigeonApiIMAAdDisplayContainer, adContainer: UIView, - adContainerViewController: UIViewController? + companionSlots: [IMACompanionAdSlot]?, adContainerViewController: UIViewController? ) throws -> IMAAdDisplayContainer { return IMAAdDisplayContainer( - adContainer: adContainer, viewController: adContainerViewController) + adContainer: adContainer, viewController: adContainerViewController, + companionSlots: companionSlots) + } + + func adContainer(pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer) + throws -> UIView + { + return pigeonInstance.adContainer + } + + func companionSlots( + pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer + ) throws -> [IMACompanionAdSlot]? { + return pigeonInstance.companionSlots + } + + func setAdContainerViewController( + pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer, + controller: UIViewController? + ) throws { + pigeonInstance.adContainerViewController = controller + } + + func getAdContainerViewController( + pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer + ) throws -> UIViewController? { + return pigeonInstance.adContainerViewController + } + + func registerFriendlyObstruction( + pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer, + friendlyObstruction: IMAFriendlyObstruction + ) throws { + pigeonInstance.register(friendlyObstruction) + } + + func unregisterAllFriendlyObstructions( + pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer + ) throws { + pigeonInstance.unregisterAllFriendlyObstructions() } } diff --git a/packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/AdsRequestProxyAPIDelegate.swift b/packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/AdsRequestProxyAPIDelegate.swift index 7b00f9c7f95d..fbd8ffff3be6 100644 --- a/packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/AdsRequestProxyAPIDelegate.swift +++ b/packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/AdsRequestProxyAPIDelegate.swift @@ -13,7 +13,7 @@ class AdsRequestProxyAPIDelegate: PigeonApiDelegateIMAAdsRequest { /// The current version of the `interactive_media_ads` plugin. /// /// This must match the version in pubspec.yaml. - static let pluginVersion = "0.2.3+3" + static let pluginVersion = "0.2.3+4" func pigeonDefaultConstructor( pigeonApi: PigeonApiIMAAdsRequest, adTagUrl: String, adDisplayContainer: IMAAdDisplayContainer, diff --git a/packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/InteractiveMediaAdsLibrary.g.swift b/packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/InteractiveMediaAdsLibrary.g.swift index 501b6ac923ff..6c3ed9ddf279 100644 --- a/packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/InteractiveMediaAdsLibrary.g.swift +++ b/packages/interactive_media_ads/ios/interactive_media_ads/Sources/interactive_media_ads/InteractiveMediaAdsLibrary.g.swift @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v22.5.0), do not edit directly. +// Autogenerated from Pigeon (v22.6.2), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation @@ -1200,10 +1200,38 @@ class InteractiveMediaAdsLibraryPigeonCodec: FlutterStandardMessageCodec, @unche } protocol PigeonApiDelegateIMAAdDisplayContainer { + /// Initializes IMAAdDisplayContainer for rendering the ad and displaying the + /// sad UI. func pigeonDefaultConstructor( pigeonApi: PigeonApiIMAAdDisplayContainer, adContainer: UIView, - adContainerViewController: UIViewController? + companionSlots: [IMACompanionAdSlot]?, adContainerViewController: UIViewController? ) throws -> IMAAdDisplayContainer + /// View containing the video display and ad related UI. + /// + /// This view must be present in the view hierarchy in order to make ad or + /// stream requests. + func adContainer(pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer) + throws -> UIView + /// List of companion ad slots. + func companionSlots( + pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer + ) throws -> [IMACompanionAdSlot]? + /// View controller containing the ad container. + func setAdContainerViewController( + pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer, + controller: UIViewController?) throws + /// View controller containing the ad container. + func getAdContainerViewController( + pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer + ) throws -> UIViewController? + /// Registers a view that overlays or obstructs this container as “friendly” + /// for viewability measurement purposes. + func registerFriendlyObstruction( + pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer, + friendlyObstruction: IMAFriendlyObstruction) throws + /// Unregisters all previously registered friendly obstructions. + func unregisterAllFriendlyObstructions( + pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer) throws } protocol PigeonApiProtocolIMAAdDisplayContainer { @@ -1242,11 +1270,12 @@ final class PigeonApiIMAAdDisplayContainer: PigeonApiProtocolIMAAdDisplayContain let args = message as! [Any?] let pigeonIdentifierArg = args[0] as! Int64 let adContainerArg = args[1] as! UIView - let adContainerViewControllerArg: UIViewController? = nilOrValue(args[2]) + let companionSlotsArg: [IMACompanionAdSlot]? = nilOrValue(args[2]) + let adContainerViewControllerArg: UIViewController? = nilOrValue(args[3]) do { api.pigeonRegistrar.instanceManager.addDartCreatedInstance( try api.pigeonDelegate.pigeonDefaultConstructor( - pigeonApi: api, adContainer: adContainerArg, + pigeonApi: api, adContainer: adContainerArg, companionSlots: companionSlotsArg, adContainerViewController: adContainerViewControllerArg), withIdentifier: pigeonIdentifierArg) reply(wrapResult(nil)) @@ -1257,6 +1286,85 @@ final class PigeonApiIMAAdDisplayContainer: PigeonApiProtocolIMAAdDisplayContain } else { pigeonDefaultConstructorChannel.setMessageHandler(nil) } + let setAdContainerViewControllerChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.interactive_media_ads.IMAAdDisplayContainer.setAdContainerViewController", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + setAdContainerViewControllerChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! IMAAdDisplayContainer + let controllerArg: UIViewController? = nilOrValue(args[1]) + do { + try api.pigeonDelegate.setAdContainerViewController( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, controller: controllerArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + setAdContainerViewControllerChannel.setMessageHandler(nil) + } + let getAdContainerViewControllerChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.interactive_media_ads.IMAAdDisplayContainer.getAdContainerViewController", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + getAdContainerViewControllerChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! IMAAdDisplayContainer + do { + let result = try api.pigeonDelegate.getAdContainerViewController( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(result)) + } catch { + reply(wrapError(error)) + } + } + } else { + getAdContainerViewControllerChannel.setMessageHandler(nil) + } + let registerFriendlyObstructionChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.interactive_media_ads.IMAAdDisplayContainer.registerFriendlyObstruction", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + registerFriendlyObstructionChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! IMAAdDisplayContainer + let friendlyObstructionArg = args[1] as! IMAFriendlyObstruction + do { + try api.pigeonDelegate.registerFriendlyObstruction( + pigeonApi: api, pigeonInstance: pigeonInstanceArg, + friendlyObstruction: friendlyObstructionArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + registerFriendlyObstructionChannel.setMessageHandler(nil) + } + let unregisterAllFriendlyObstructionsChannel = FlutterBasicMessageChannel( + name: + "dev.flutter.pigeon.interactive_media_ads.IMAAdDisplayContainer.unregisterAllFriendlyObstructions", + binaryMessenger: binaryMessenger, codec: codec) + if let api = api { + unregisterAllFriendlyObstructionsChannel.setMessageHandler { message, reply in + let args = message as! [Any?] + let pigeonInstanceArg = args[0] as! IMAAdDisplayContainer + do { + try api.pigeonDelegate.unregisterAllFriendlyObstructions( + pigeonApi: api, pigeonInstance: pigeonInstanceArg) + reply(wrapResult(nil)) + } catch { + reply(wrapError(error)) + } + } + } else { + unregisterAllFriendlyObstructionsChannel.setMessageHandler(nil) + } } ///Creates a Dart instance of IMAAdDisplayContainer and attaches it to [pigeonInstance]. @@ -1277,13 +1385,18 @@ final class PigeonApiIMAAdDisplayContainer: PigeonApiProtocolIMAAdDisplayContain } let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance( pigeonInstance as AnyObject) + let adContainerArg = try! pigeonDelegate.adContainer( + pigeonApi: self, pigeonInstance: pigeonInstance) + let companionSlotsArg = try! pigeonDelegate.companionSlots( + pigeonApi: self, pigeonInstance: pigeonInstance) let binaryMessenger = pigeonRegistrar.binaryMessenger let codec = pigeonRegistrar.codec let channelName: String = "dev.flutter.pigeon.interactive_media_ads.IMAAdDisplayContainer.pigeon_newInstance" let channel = FlutterBasicMessageChannel( name: channelName, binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in + channel.sendMessage([pigeonIdentifierArg, adContainerArg, companionSlotsArg] as [Any?]) { + response in guard let listResponse = response as? [Any?] else { completion(.failure(createConnectionError(withChannelName: channelName))) return diff --git a/packages/interactive_media_ads/lib/src/ios/interactive_media_ads.g.dart b/packages/interactive_media_ads/lib/src/ios/interactive_media_ads.g.dart index a26cfa675acb..5add90505e91 100644 --- a/packages/interactive_media_ads/lib/src/ios/interactive_media_ads.g.dart +++ b/packages/interactive_media_ads/lib/src/ios/interactive_media_ads.g.dart @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v22.5.0), do not edit directly. +// Autogenerated from Pigeon (v22.6.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers @@ -53,7 +53,6 @@ abstract class PigeonInternalProxyApiBaseClass { final BinaryMessenger? pigeon_binaryMessenger; /// Maintains instances stored to communicate with native language objects. - @protected final PigeonInstanceManager pigeon_instanceManager; /// Instantiates and returns a functionally identical object to oneself. @@ -795,10 +794,13 @@ class _PigeonCodec extends StandardMessageCodec { /// /// See https://developers.google.com/ad-manager/dynamic-ad-insertion/sdk/ios/reference/Classes/IMAAdDisplayContainer. class IMAAdDisplayContainer extends NSObject { + /// Initializes IMAAdDisplayContainer for rendering the ad and displaying the + /// sad UI. IMAAdDisplayContainer({ super.pigeon_binaryMessenger, super.pigeon_instanceManager, - required UIView adContainer, + required this.adContainer, + this.companionSlots, UIViewController? adContainerViewController, }) : super.pigeon_detached() { final int pigeonVar_instanceIdentifier = @@ -815,10 +817,11 @@ class IMAAdDisplayContainer extends NSObject { pigeonChannelCodec, binaryMessenger: pigeonVar_binaryMessenger, ); - final List? pigeonVar_replyList = await pigeonVar_channel - .send([ + final List? pigeonVar_replyList = + await pigeonVar_channel.send([ pigeonVar_instanceIdentifier, adContainer, + companionSlots, adContainerViewController ]) as List?; if (pigeonVar_replyList == null) { @@ -843,17 +846,31 @@ class IMAAdDisplayContainer extends NSObject { IMAAdDisplayContainer.pigeon_detached({ super.pigeon_binaryMessenger, super.pigeon_instanceManager, + required this.adContainer, + this.companionSlots, }) : super.pigeon_detached(); late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecIMAAdDisplayContainer = _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + /// View containing the video display and ad related UI. + /// + /// This view must be present in the view hierarchy in order to make ad or + /// stream requests. + final UIView adContainer; + + /// List of companion ad slots. + final List? companionSlots; + static void pigeon_setUpMessageHandlers({ bool pigeon_clearHandlers = false, BinaryMessenger? pigeon_binaryMessenger, PigeonInstanceManager? pigeon_instanceManager, - IMAAdDisplayContainer Function()? pigeon_newInstance, + IMAAdDisplayContainer Function( + UIView adContainer, + List? companionSlots, + )? pigeon_newInstance, }) { final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = _PigeonInternalProxyApiBaseCodec( @@ -876,13 +893,20 @@ class IMAAdDisplayContainer extends NSObject { final int? arg_pigeon_instanceIdentifier = (args[0] as int?); assert(arg_pigeon_instanceIdentifier != null, 'Argument for dev.flutter.pigeon.interactive_media_ads.IMAAdDisplayContainer.pigeon_newInstance was null, expected non-null int.'); + final UIView? arg_adContainer = (args[1] as UIView?); + assert(arg_adContainer != null, + 'Argument for dev.flutter.pigeon.interactive_media_ads.IMAAdDisplayContainer.pigeon_newInstance was null, expected non-null UIView.'); + final List? arg_companionSlots = + (args[2] as List?)?.cast(); try { (pigeon_instanceManager ?? PigeonInstanceManager.instance) .addHostCreatedInstance( - pigeon_newInstance?.call() ?? + pigeon_newInstance?.call(arg_adContainer!, arg_companionSlots) ?? IMAAdDisplayContainer.pigeon_detached( pigeon_binaryMessenger: pigeon_binaryMessenger, pigeon_instanceManager: pigeon_instanceManager, + adContainer: arg_adContainer!, + companionSlots: arg_companionSlots, ), arg_pigeon_instanceIdentifier!, ); @@ -898,11 +922,128 @@ class IMAAdDisplayContainer extends NSObject { } } + /// View controller containing the ad container. + Future setAdContainerViewController( + UIViewController? controller) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecIMAAdDisplayContainer; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.interactive_media_ads.IMAAdDisplayContainer.setAdContainerViewController'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, controller]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// View controller containing the ad container. + Future getAdContainerViewController() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecIMAAdDisplayContainer; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.interactive_media_ads.IMAAdDisplayContainer.getAdContainerViewController'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return (pigeonVar_replyList[0] as UIViewController?); + } + } + + /// Registers a view that overlays or obstructs this container as “friendly” + /// for viewability measurement purposes. + Future registerFriendlyObstruction( + IMAFriendlyObstruction friendlyObstruction) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecIMAAdDisplayContainer; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.interactive_media_ads.IMAAdDisplayContainer.registerFriendlyObstruction'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, friendlyObstruction]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Unregisters all previously registered friendly obstructions. + Future unregisterAllFriendlyObstructions() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecIMAAdDisplayContainer; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.interactive_media_ads.IMAAdDisplayContainer.unregisterAllFriendlyObstructions'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + @override IMAAdDisplayContainer pigeon_copy() { return IMAAdDisplayContainer.pigeon_detached( pigeon_binaryMessenger: pigeon_binaryMessenger, pigeon_instanceManager: pigeon_instanceManager, + adContainer: adContainer, + companionSlots: companionSlots, ); } } diff --git a/packages/interactive_media_ads/pigeons/interactive_media_ads_ios.dart b/packages/interactive_media_ads/pigeons/interactive_media_ads_ios.dart index da64692f8456..445b87b48744 100644 --- a/packages/interactive_media_ads/pigeons/interactive_media_ads_ios.dart +++ b/packages/interactive_media_ads/pigeons/interactive_media_ads_ios.dart @@ -309,10 +309,31 @@ enum UIElementType { swiftOptions: SwiftProxyApiOptions(import: 'GoogleInteractiveMediaAds'), ) abstract class IMAAdDisplayContainer extends NSObject { - IMAAdDisplayContainer( - UIView adContainer, - UIViewController? adContainerViewController, - ); + /// Initializes IMAAdDisplayContainer for rendering the ad and displaying the + /// sad UI. + IMAAdDisplayContainer(UIViewController? adContainerViewController); + + /// View containing the video display and ad related UI. + /// + /// This view must be present in the view hierarchy in order to make ad or + /// stream requests. + late UIView adContainer; + + /// List of companion ad slots. + late List? companionSlots; + + /// View controller containing the ad container. + void setAdContainerViewController(UIViewController? controller); + + /// View controller containing the ad container. + UIViewController? getAdContainerViewController(); + + /// Registers a view that overlays or obstructs this container as “friendly” + /// for viewability measurement purposes. + void registerFriendlyObstruction(IMAFriendlyObstruction friendlyObstruction); + + /// Unregisters all previously registered friendly obstructions. + void unregisterAllFriendlyObstructions(); } /// An object that manages the content for a rectangular area on the screen. diff --git a/packages/interactive_media_ads/pubspec.yaml b/packages/interactive_media_ads/pubspec.yaml index 4fa1d3743c21..6ac1fc8a1f38 100644 --- a/packages/interactive_media_ads/pubspec.yaml +++ b/packages/interactive_media_ads/pubspec.yaml @@ -2,7 +2,7 @@ name: interactive_media_ads description: A Flutter plugin for using the Interactive Media Ads SDKs on Android and iOS. repository: https://github.com/flutter/packages/tree/main/packages/interactive_media_ads issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+interactive_media_ads%22 -version: 0.2.3+3 # This must match the version in +version: 0.2.3+4 # This must match the version in # `android/src/main/kotlin/dev/flutter/packages/interactive_media_ads/AdsRequestProxyApi.kt` and # `ios/interactive_media_ads/Sources/interactive_media_ads/AdsRequestProxyAPIDelegate.swift` @@ -31,7 +31,7 @@ dev_dependencies: flutter_test: sdk: flutter mockito: ^5.4.4 - pigeon: ^22.6.1 + pigeon: ^22.6.2 topics: - ads From 5a58b1d3a6f955802703062e2a341749e6b6eef0 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 22 Nov 2024 17:11:25 -0500 Subject: [PATCH 2/2] no protected --- .../lib/src/ios/ios_ad_display_container.dart | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/interactive_media_ads/lib/src/ios/ios_ad_display_container.dart b/packages/interactive_media_ads/lib/src/ios/ios_ad_display_container.dart index 4bdd8fa46133..f0780d1a747e 100644 --- a/packages/interactive_media_ads/lib/src/ios/ios_ad_display_container.dart +++ b/packages/interactive_media_ads/lib/src/ios/ios_ad_display_container.dart @@ -77,10 +77,8 @@ base class IOSAdDisplayContainer extends PlatformAdDisplayContainer { params.onContainerAdded(this); }, layoutDirection: params.layoutDirection, - creationParams: - // ignore: invalid_use_of_protected_member - _controller.view.pigeon_instanceManager - .getIdentifier(_controller.view), + creationParams: _controller.view.pigeon_instanceManager + .getIdentifier(_controller.view), creationParamsCodec: const StandardMessageCodec(), ); }