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]: Localization issues on push notification action buttons #86

Closed 3a4oT closed 1 year ago

3a4oT commented 1 year ago

Platform

iOS

Platform Version

iOS 17.0.3

Braze SDK Version

7.1.0

Xcode Version

Xcode 15.0

Computer Processor

Apple (M1)

Repro Rate

100%

Steps To Reproduce

  1. Integrate Braze SDK and implement push notification functionality using manual flow.
  2. Run the app, and trigger a push notification campaign.

Expected Behavior

Should display button labels like:

Actual Incorrect Behavior

localizationBug

Verbose Logs

No response

Additional Information

Please note that Braze SDK backed to the internal swift package library (used with TCA as a dependency). Maybe default localised strings can't be loaded because of it since when we are on swift package level we should load resources like Bundle(.module) instead of Bundle(.main)??

hokstuff commented 1 year ago

Hi @3a4oT,

Thank you for raising this issue! We have filed at ticket to look at it internally.

Integrate Braze SDK and implement push notification functionality using manual flow

To clarify, when you say using manual flow, are you referencing that you integrated the Braze SDK without a package manager (SPM, Cocoapods), or are you referencing something else? Have you been able to been able to repro this when using a package manager?

3a4oT commented 1 year ago

Hey @hokstuff. Yes, I'm using SPM as the package manager. By "manual" flow I mean Manual push integration from documentation. So no swizzling and no configuration.push.automation = true (:

3a4oT commented 1 year ago

More context: I integrated BrazeSDK in my own swift package and proxy needed API to it, then from iOS target, I call my library, which under the hood calls Braze API. I hope it does make sense to you.

jerielng commented 1 year ago

Thanks for the additional info! If the manual integration refers to just the push feature, I don't think that should have any impact on the localization, but if you did some additional steps to proxy the Swift package into your project, it's possible that the bundle may not be accessible by default. Are you able to locate where the bundle is in your project hierarchy and maybe assign its location to the overrideResourceBundle? We added this as of 5.11.1 that allows integrations with a little more complex setups to control this piece more granularly.

3a4oT commented 1 year ago

Hey @jerielng , thanks for pointers. Yes, I can locate and even get bundle instance on runtime, however, it doesn't work. I used the following code:

 if let resourcePath: String = Bundle.main.resourcePath {
            let brazeKitBundlePath: String = resourcePath + "/" + "braze-swift-sdk_BrazeKitResources" + ".bundle"
            if let brazeKitBundle = Bundle(path: brazeKitBundlePath) {
                BrazeKit.overrideResourceBundle = brazeKitBundle
                print(brazeKitBundle.bundlePath)
            } else {
                print("failed to locate brazeKit bundle")
            }

        }

        let configuration = Braze.Configuration(apiKey: apiKey, endpoint: endpoint)
#if DISTRIBUTION
        configuration.logger.level = .disabled
#else
        configuration.logger.level = .info
#endif
        braze = Braze(configuration: configuration)
3a4oT commented 1 year ago

Also, what is weird is that I haven't found any occurrences of braze-swift-sdk_BrazeKitResources

Can it be related to this #if SWIFT_PACKAGE block?

PS. After looking on Package.swift, I see you vend a private version of Swift Framework, so most probably my comment is not relevant.

3a4oT commented 1 year ago

OK, after checking the consumer code I found the issue, and it's NOT related to BrazeSDK. The issue was related to swizzling Bundle's localizedString(forKey:value:table:). The issue can be closed. Thanks everyone.

jerielng commented 1 year ago

Thanks for confirming! We'll go ahead and close it but feel free to reach out again if you have more questions!