HMS-Core / hms-react-native-plugin

This repo contains all of React-Native HMS plugins.
https://developer.huawei.com/consumer/en/doc/overview/HMS-Core-Plugin?ha_source=hms1
Apache License 2.0
245 stars 68 forks source link

"react-native-hms-push" drops data from intent that leads to broke Linking.getInitialUrl() #184

Closed lexgorbunov closed 2 years ago

lexgorbunov commented 2 years ago

When I click by deeplink await Linking.getInitialUrl() returns null. If to remove react-native-hms-push from package.json everything works properly.

It loks like the problem is somewhere here: com/huawei/hms/rn/push/remote/HmsPushMessaging.java:300 in sendOpenedNotificationData method

public void sendOpenedNotificationData(Intent intent) {
        try {
            Map<String, Object> map = new HashMap<>();
            Bundle extras = intent.getExtras();
            if (extras != null) {
                RemoteMessage remoteMessage = new RemoteMessage(extras);
                map.put("remoteMessage", RemoteMessageUtils.toMap(remoteMessage));
                JSONObject extrasData = BundleUtils.convertJSONObject(extras);
                map.put("extras", extrasData);
            }
            if (intent.getDataString() != null)
                map.put("uriPage", intent.getDataString());
            HmsPushMessaging.setInitialNotification(map);
            getContext()
                .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit(Core.Event.NOTIFICATION_OPENED_EVENT, MapUtils.copyToWritableMap(map));

            intent.setFlags(0);
            intent.replaceExtras(new Bundle());
            intent.setData(intent.getData());
        } catch (Exception e) {
            Log.w(TAG, "sendOpenedNotificationData: " + e.getLocalizedMessage());
        }
    }

intent.setData(intent.getData());

I think you should add more specific checking (in com/huawei/hms/rn/push/remote/HmsPushMessaging.java:275 [checkFlag]) if intent has notification data or not to avoid loosing data.

yasserwaseet commented 2 years ago

@lexgorbunov I am facing the same problem, did you find a solution, please?

walterdl commented 2 years ago

Same issue using @hmscore/react-native-hms-push@6.3.0.304 and using dynamic links of firebase @react-native-firebase/dynamic-links@^14.11.0. Every call to dynamicLinks()..getInitialLink() returns null when the app is opened by a valid dynamic link. Uninstalling @hmscore/react-native-hms-push the problem is gone.

@lexgorbunov did you get a workaround to solve this?

ozcanozgur commented 2 years ago

Hi all,

There is an ongoing development for this issue yet the current scope of the solution only covers the firebase/dynamic-links issue. You may try this solution for the issue or share your demo file for us to check any other edge cases.

Please remove the logic which are added below from the line 278 at node_modules/@hmscore/react-native-hms-push/android/src/main/java/remote/HmsPushMessaging.java

intent.getDataString() != null

Thank you for reporting the issue to us.

ozcanozgur commented 2 years ago

We released the 6.5.0.300 version of Push a few days ago. This version contains some bug fixes related to clear intent data. The issue you mentioned has been fixed with the latest version.