electrode-io / ern-navigation

Electrode Native solution for React Native navigation

Home Page:https://www.electrode.io/ern-navigation/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`finishedCallback` receives incorrectly encoded JSON string on iOS

romanlv opened this issue · comments

commented

Calling this JS code in ERN miniapp

this.finish(JSON.stringify({ offerId: 3 }));

triggers finishedCallback payload with value "{\"offerId\":3}" (it's an actual value, Swift string can be coded as "\"{\\\"offerId\\\":3}\"")

to be able to process it app develops have to do extra processing to clean it up:

        let unescapedString = payload?.dropFirst().dropLast().replacingOccurrences(of: #"\"#, with: "")
        guard let data = unescapedString?.data(using: .utf8),
            let model = try? JSONDecoder().decode(MultiOfferRecord.self, from: data) else {
                return
        }

happens in: ern-navigation@1.1.3

@romanlv Thanks for reporting this. I think this is what we do on Android, sending a JSONObject instead of String. Will do the same for iOS as well.

@romanlv regarding this.finish(JSON.stringify({ offerId: 3 })); the navigation component does stringify the payload passed in, so you can simply call this.finish({ offerId: 3 }). Otherwise, the payload would be stringified twice before it is being sent to native.

commented

Thanks, @deepueg, sorry, my bad, stupid mistake :)

commented

agree, it makes sense to have Android and iOS to receive the same type

I thought you left it open for developers to decide what method of serialization to use, in case if someone wants to use non-json format

This is fixed in the native implementation and available with the latest version of ern-navigation
https://github.com/electrode-io/ernnavigation-api-impl-native/releases/tag/v1.2.4