0

I am trying to implement the MarketingCloudSDK for our iOS app and have a question about initialization of the SDK. We need to set the analyticsEnabled value in the ConfigBuilder during initialization based on the users preferences if they want marketing notificatoins or not. We use redux for our architecture, so we do not have access to the app state in our app delegate, as it has not been setup yet. Therefore I need to delay the SDK initialization until we get the app state setup.

I have this working, and the initialization happens when I expect it to happen, based on when the user sets their preferences. I am just curious if there is any downside to initializing the SDK multiple times? Currently on app launch it will initialize based on the default app state, then we will initialize again, when we get the users preferences from user defaults, as well as any time the user manually changes this preference in settings.

We are also setting the ContactKey in the same manner. Is it required to set this after the initialization, or will it remember this value if the SDK is re-initialized?

Here's the current function that I'm calling to initialize the SDK to determine if we need to allow analytics or not.

    private func registerSalesforce(analyticsEnabled: Bool) {
        SFMCSdk.mp.tearDown()

        let configuration = PushConfigBuilder(appId: appID)
            .setAccessToken(accessToken)
            .setMarketingCloudServerUrl(URL(string: appEndpoint)!)
            .setMid(mid)
            .setInboxEnabled(false)
            .setLocationEnabled(false)
            .setAnalyticsEnabled(analyticsEnabled)
            .build()
        SFMCSdk.initializeSdk(ConfigBuilder().setPush(config: configuration).build())

        if SFMCSdk.mp.getStatus() == .operational, App.configuration == .debug {
            SFMCSdk.mp.setDebugLoggingEnabled(true)
        }
    }

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy