chabokpush / chabok-client-rn

Chabok react native wrapper
https://doc.chabokpush.com/react-native-bridge/introducing.html
5 stars 5 forks source link

عدم دریافت مقدار data #6

Closed amir-yaghoubi closed 6 years ago

amir-yaghoubi commented 6 years ago
مقدار data به درستی parse نمی‌شود که باعث عدم دریافت آن می‌شود
Mr-Hqq commented 6 years ago
تو فایل AdpPushClientModule تابع زیر رو اضافه کنید


WritableMap toWritableMap(JSONObject json){
        WritableMap response = Arguments.createMap();
        Iterator iter = json.keys();
        while (iter.hasNext()) {
            String key = iter.next();
            try {
                if (json.get(key) instanceof Integer) {
                    response.putInt(key, (Integer) json.get(key));
                } else if (json.get(key) instanceof String) {
                    response.putString(key, (String) json.get(key));
                } else if (json.get(key) instanceof JSONObject) {
                    toWritableMap((JSONObject) json.get(key));
                } else if (json.get(key) instanceof Double) {
                    response.putDouble(key, (Double) json.get(key));
                }else if (json.get(key) instanceof Boolean) {
                    response.putBoolean(key, (Boolean) json.get(key));
                }
            } catch (JSONException e) {
                // Something went wrong!
            }
        }
        return response;
}


بعد تو تابع
public void onEvent(final PushMessage msg)
کد زیر رو اضافه کنید مشکل حل میشه
response.putMap("data", toWritableMap(msg.getData()));
amir-yaghoubi commented 6 years ago
خیلی ممنون، اگه امکانش براتون هست pull-request این راه حل رو بزنین خیلی خوب میشه
behrad commented 6 years ago

Can you please create a PR for your solution @Mr-Hqq ?

Mr-Hqq commented 6 years ago

@behrad it's done for goodness. Please let me know if I'm wrong!

amir-yaghoubi commented 6 years ago

This issue fixed in this PR #10 and will be available in next version.

I will close this issue since its resolved.