React Native WebView postMessage does not work

后端 未结 4 2026
旧时难觅i
旧时难觅i 2020-12-13 00:28

I can\'t get React Native WebView postMessage to work. The React Native app successfully receives the post message sendt from the web app. But the web app does not receive m

4条回答
  •  不思量自难忘°
    2020-12-13 01:14

    Actually the listener works differently in different OSs such as iOS and Android. So you should use document.addEventListener for Android and window.addEventListener for iOS.

    if(navigator.appVersion.includes('Android')){
                document.addEventListener("message", function (data) {
                   alert("you are in android OS");
                });
            }
    else {
                window.addEventListener("message", function (data) {
                   alert("you are in android OS");               
                 });
            }
    

提交回复
热议问题