AdaptySDK-Flutter icon indicating copy to clipboard operation
AdaptySDK-Flutter copied to clipboard

Adapty Flutter SDK with SceneDelegate

Open kingsglade opened this issue 6 months ago • 1 comments

Hi All,

Apologies in advance, this is a very specific issue where I'm trying to get two mature Flutter packages to play nice. I'm in the process of implementing both CarPlay and Adapty for my flutter app and ran into a blocker which I overcame but only with an unpleasant hack.

Dependencies:

  • To implement CarPlay (see https://pub.dev/packages/flutter_carplay) it's required that we implement a SceneDelegate as detailed on their package info, see Getting Started step 3.
  • To have the Adapty SDK work properly we need application(didFinishLaunchingWithOptions) callback to trigger in module SwiftAdaptyFlutterPlugin because it's required that activateOnLaunch() execute to pull the settings from the Adapty-Info.plist

Problem statement: My CarPlay app is functioning normally but my Adapty integration that was previously working now does not. Debugging suggests this is because we're using a SceneDelegate to register plugins and subsequently the callback application(didFinishLaunchingWithOptions) doesn't trigger so Adapty doesn't initialise. We then get an error when trying to use any subsequent Adapty functions such as GetProfile.

Now to the hack: Fortunately setLogLevel works, so I've added the hackiest of hack calls to activateOnLaunch() in module SwiftAdaptyFlutterPlugin just before the line Adapty.logLevel = logLevel in function handleSetLogLevel. I mainly wanted to see if this would work given the timing of the call and good news is that it does and my Adapty paywall is now working, but there are probably some gotchas that I'm not aware of!

Steps To Reproduce: Follow both flutter_carplay (1.0.3) and Adapty (2.7.1) standard implementation steps (a shortcut would be to add Adapty to the flutter_carplay sample app).

Question: Is it possible for a) Adapty to trap SceneDelegate lifecycle callbacks that are similar/equivalent to application(didFinishLaunchingWithOptions) so as to ensure that Adapty initialises in this scenario or b) Allow control from early in the Flutter lifecycle to call Activate() or similar manually.

I get that there's a reason the activation is being done automatically so as to play nice with StoreKit but unless I put this hack in or implement another custom method call in the SDK I can't see this being resolved. I'm pretty sure the CarPlay solution needs to retain the SceneDelegate approach.

Thanks in advance for your assistance! Mark

kingsglade avatar Dec 28 '23 20:12 kingsglade