Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activating AdaptyUI fails if done the same way as docs says #92

Open
nathanfallet opened this issue Nov 25, 2024 · 8 comments
Open

Activating AdaptyUI fails if done the same way as docs says #92

nathanfallet opened this issue Nov 25, 2024 · 8 comments

Comments

@nathanfallet
Copy link

nathanfallet commented Nov 25, 2024

In the docs, it's recommended to enable Adapty and AdaptyUI this way:

Adapty.activate(with: configurationBuilder) { error in
  // handle the error
}
// Only if you are going to use AdaptyUI
AdaptyUI.activate()

But when done this way, AdaptyUI fails to activate because it does not wait for Adapty to be activated.

AdaptyUI activate error: You should activate Adapty SDK before using AdaptyUI
v3.2.0, AdaptyUI/AdaptyUI+Public.swift#211

And only later in the log you can see Adapty activating:

Adapty activated successfully. [2UDtMB]
v3.2.0, Adapty/Adapty+Activate.swift#93

A way to fix this is writing it this way:

Adapty.activate(with: configurationBuilder) { error in
  if let error {
    // handle the error
    return
  }
  // Only if you are going to use AdaptyUI
  AdaptyUI.activate()
}

This way, AdaptyUI is only activated when Adapty is. (and it works)

Is this a bug or does docs need to be updated?

@yildirimatcioglu
Copy link

Same here version 3.2.1

@EgorSigolaev
Copy link

Same, version 3.2.1

@ryancstack
Copy link

ryancstack commented Feb 18, 2025

I think these fail unless you sequentially call them, either through structured concurrency (async/await) or activating within the completion. I haven't tried the latter, but assume that's why it's failing to activate.

edit: I see you have the "in completion" solution marked

@x401om
Copy link
Contributor

x401om commented Feb 20, 2025

Hello! I apologize for not addressing this issue sooner.

Depending on the context, we suggest two ways to activate Adapty:

1. Asynchronous context with async/await:

let adaptyConfigBuilder = AdaptyConfiguration
    .builder(withAPIKey: "YOUR_API_KEY")

do {
    try await Adapty.activate(with: adaptyConfigBuilder)
    try await AdaptyUI.activate()
} catch {
    // Handle the error
}

2. Synchronous context with callbacks (e.g., within application(_:didFinishLaunchingWithOptions:)):

let adaptyConfigBuilder = AdaptyConfiguration
    .builder(withAPIKey: "YOUR_API_KEY")

Adapty.activate(with: adaptyConfigBuilder) { error in
    // Handle the error
}

AdaptyUI.activate { error in
    // Handle the error
}

There is no need to wait for Adapty.activate to complete before running AdaptyUI.activate. I have double-checked both methods using our demo apps, and everything appears to be working correctly on my end.

It would be helpful to have a demo project that reproduces the issue or, at the very least, verbose logs.

@EgorSigolaev
Copy link

Hello! I apologize for not addressing this issue sooner.

Depending on the context, we suggest two ways to activate Adapty:

1. Asynchronous context with async/await:

let adaptyConfigBuilder = AdaptyConfiguration
    .builder(withAPIKey: "YOUR_API_KEY")

do {
    try await Adapty.activate(with: adaptyConfigBuilder)
    try await AdaptyUI.activate()
} catch {
    // Handle the error
}

2. Synchronous context with callbacks (e.g., within application(_:didFinishLaunchingWithOptions:)):

let adaptyConfigBuilder = AdaptyConfiguration
    .builder(withAPIKey: "YOUR_API_KEY")

Adapty.activate(with: adaptyConfigBuilder) { error in
    // Handle the error
}

AdaptyUI.activate { error in
    // Handle the error
}

There is no need to wait for Adapty.activate to complete before running AdaptyUI.activate. I have double-checked both methods using our demo apps, and everything appears to be working correctly on my end.

It would be helpful to have a demo project that reproduces the issue or, at the very least, verbose logs.

I will try to reproduce the bug again. But that was definitely happening, I am not the only one who noticed.

@x401om
Copy link
Contributor

x401om commented Feb 20, 2025

@EgorSigolaev I’m not saying there isn’t an issue, I just wanted to highlight the recommended ways to call Adapty methods and ask for additional details to reproduce it. I appreciate your help.

@EgorSigolaev
Copy link

@EgorSigolaev I’m not saying there isn’t an issue, I just wanted to highlight the recommended ways to call Adapty methods and ask for additional details to reproduce it. I appreciate your help.

I meant I used the approach of calling Adapty methods as you mentioned above. But it didn't work as expected. If I have any updates according the issue, I will write here.

@ryancstack
Copy link

Yes I experienced the same thing @x401om. Calling the methods synchronously and then attempting to download a paywall failed immediately as "adapty not activated"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants