Initialize the SDK
3 min
after adding the appstorys sdk to your project, initialize it once when your app launches we will provide you with your account id and app id , which must be passed as parameters userid is configured from app to app and you will need to pass userid for the user as defined in your app swiftui call the appstorys() function inside a task {} block attached to your root view (for example, in your main app struct) task { appstorys initialize( accountid "your account id", appid "your app id", userid "your user id" ) } withappstorysoverlays() uikit call the appstorys() function from appdelegate application( didfinishlaunchingwithoptions ) ▎ // appdelegate swift import appstorys ios @main class appdelegate uiresponder, uiapplicationdelegate { func application( application uiapplication, didfinishlaunchingwithoptions launchoptions ) > bool { appstorys initialize( accountid "your account id", appid "your app id", userid "your user id" ) return true } } one xcode setting people miss in your app target → general → frameworks, libraries, and embedded content , make sure appstorys ios is set to embed & sign without this the app builds successfully but crashes at launch with dyld library not loaded @rpath/appstorys ios framework note if the user id is not present at the time of initialization, you can leave that and call the below whenever the user id gets generated try await appstorys shared setuserid("user id") notes setuserid is an async throws function — call it from an async context and handle errors with try/catch the sdk must already be initialized (via initialize) before calling setuserid, otherwise it throws appstoryserror notinitialized the user id cannot be empty — passing an empty string throws appstoryserror invalidparameter if the current user was previously anonymous (a fallback id generated by the sdk), calling setuserid reconciles that anonymous identity with the new identified user id, merging their prior activity if the new id matches the current user id, the call is a no op setting a new user id clears cached campaigns and refreshes them for the newly identified user