Question

iOS SDK - Accessing `Purchases.shared.appUserID` immediately after initialization

  • 24 May 2024
  • 0 replies
  • 15 views

Badge

Directly after initializing the RevenueCat SDK in my AppDelegate.didFinishLaunchingWithOptions method, I call `Purchases.shared.appUserID`. I briefly looked into the implementation and saw that `IdentityManager.currentAppUserId` (which is used by `Purchases.shared.appUserID` to retrieve the actual id) uses a `fatalError` when no cached app user id is present:

```

    var currentAppUserID: String {
        guard let appUserID = self.deviceCache.cachedAppUserID else {
            fatalError(Strings.identity.null_currentappuserid.description)
        }

        return appUserID
    }

```

My setup:

```

Purchases.configure(
    with: Configuration.Builder(withAPIKey: "...")
        .build()
)
Purchases.shared.delegate = self
let appUserId = Purchases.shared.appUserID // <- safe?

```

I assume, that the initialization process via `Purchases.configure` is synchronous and that I can safely call `Purchases.shared.appUserID` as shown in the code snippet above. Is this correct or are there any scenarios in which this will crash or yield an invalid id?


This post has been closed for comments