onMessage prop doesn't work on iOS

Bug description:
On iOS the onMessage prop does not work. Its function doesn’t run. On android it works.

To Reproduce:
This is an exemple code:
export const Web = () => {
const INJECTED_JAVASCRIPT = (function() { window.ReactNativeWebView.postMessage(JSON.stringify({key : "value"})); })();

return (
<WebView
source={{ uri: ‘https://reactnative.dev’ }}
injectedJavaScript={INJECTED_JAVASCRIPT}
onMessage={(event) => {
const data = JSON.parse(event.nativeEvent.data)
window.alert(data.key)
}}
/>
)
}

Expected behavior:
I expect to see the alert(“value”) but on iOS it doesn’t work.

Environment:

  • OS version: 15.5
  • react-native version: 0.68.2
  • react-native-webview version: 11.18.1

Solved!
Apparently we had incorrectly set the App Bound Domains in info.plist

1 Like