braze-inc / braze-swift-sdk

Braze SDK for the Apple ecosystem, including: iOS, macOS, iPadOS, visionOS, tvOS
https://www.braze.com
Other
52 stars 19 forks source link

[Bug]: Error with "Braze SDK disabled: Cannot perform action" after init #20

Closed malcommac closed 2 years ago

malcommac commented 2 years ago

Platform

iOS

Platform Version

16.0.1

Braze SDK Version

5.5.1

Xcode Version

XCode 14.0.1

Computer Processor

Apple (M1)

Repro Rate

100%

Steps To Reproduce

After initializing the SDK (it seems to happens since the 5.5.1) we got the following errors on console (with debug mode active):

Braze SDK disabled: Cannot perform action user(BrazeKit.CUser.Action.addEvent(BrazeKit.Events.Event.Data.userCustomAttributeRemoveFromArray(key: "logged_out_devices", value: "DBA1A1C0-1098-4C14-BE65-8B443BA6CBDB")))
Braze SDK disabled: Cannot schedule work
Braze SDK disabled: Cannot perform action 
...
user(BrazeKit.CUser.Action.attributes(BrazeKit.Attributes.Action.setCustomAttribute("Enabled App Push", Optional(AnyCodable(true)))))
Braze SDK disabled: Cannot perform action user(BrazeKit.CUser.Action.attributes(BrazeKit.Attributes.Action.setCustomAttribute("Enabled Mobile Location", Optional(AnyCodable(true)))))
Braze SDK disabled: Cannot perform action user(BrazeKit.CUser.Action.attributes(BrazeKit.Attributes.Action.setCustomAttribute("Has User rated App", Optional(AnyCodable("2022-10-18T14:50:47Z")))))

The same Braze SDK disabled: Cannot perform action is repeated with any triggered event.

The only workaround is to call the enable() function explicitly on SDK:

brazeSDK = .init(configuration: configuration)
brazeSDK?.enabled = true // <--- must be called

with this, it seems working fine; otherwise, the same error is logged over and over again.

I think we should assume enable the SDK after initialization unless explicitly calling disable() method.
This is weird behavior, probably a bug inside the init function of the SDK itself.

Expected Behavior

it should work fine

Actual Incorrect Behavior

report the SDK disabled error and no events are correctly logged.

Verbose Logs

No response

Additional Information

No response

lowip commented 2 years ago

Hi @malcommac,

Thank you for the feedback, this is not a bug but a documented behavior ([wipeData()](https://braze-inc.github.io/braze-swift-sdk/documentation/brazekit/braze/wipedata()), enabled).

Calling wipeData() or braze.enable = false is persistent across app launches. I agree the behavior is unintuitive, but is there to avoid cases where the user would decline an analytics notice (e.g. GDPR) and the app mistakenly initializes the SDK for the next session. This is a behavior consistent with our Android and Web SDKs.

In practice, this means that you need to call braze.enabled = true at some point after wipeData().

We'll look into making these apis more ergonomic.