Webview unable to load local assets or from CDNs along with window.postMessage not working in iOS release build
See original GitHub issue- Review the documentation: https://facebook.github.io/react-native
- Search for existing issues: https://github.com/facebook/react-native/issues
- Use the latest React Native release: https://github.com/facebook/react-native/releases
Environment
React Native Environment Info: System: OS: macOS High Sierra 10.13.5 CPU: x64 Intel® Core™ i5-5350U CPU @ 1.80GHz Memory: 310.16 MB / 8.00 GB Shell: 5.3 - /bin/zsh Binaries: Node: 8.11.1 - /usr/local/bin/node Yarn: 1.5.1 - /usr/local/bin/yarn npm: 5.6.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3 Android SDK: Build Tools: 26.0.3, 27.0.3 API Levels: 26, 27 IDEs: Android Studio: 3.1 AI-173.4819257 Xcode: 9.4.1/9F2000 - /usr/bin/xcodebuild npmPackages: react: 16.4.1 => 16.4.1 react-native: ^0.56.0 => 0.56.0 npmGlobalPackages: create-react-native-app: 1.0.0 react-native-cli: 2.0.1
Description
I am using webview to display chart for my app using chartjs
and jquery
library I am able to view charts fine in iOS debug mode but in release config, all I get is a white screen, I tried to check if atleast window.postMessage
was working using setinterval code in my .html file, but I dont get any response from webview.
To check for window.postMessage I have also tried to possible solution from issue , still its not working
I have tried to inject the complete html code as well instead of serving the html as local asset file, still not success.
This issue is only present in iOS, works perfectly fine for android.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:7
@sja1n I think I understand your use case, I had a similar requirement where I was creating a stringified html document for webviews and i had to include js libraries from inside the app bundle. So I added my js and css and font files inside my bundles by adding it
/ios
andandroid/app/src/main/assets/_folder_name_
.I then used
react-native-fs
library to refer the assets folder inside my js. To include those files inside a webview you first need to provide the path of the assets folder as thebaseUrl
of the ‘source’ prop of webview.and the html went something like this
And window.postMessage works for me in production build as well. I think this should help you out.
I also faced a similar problem and this https://github.com/facebook/react-native/issues/19986#issuecomment-401685826 resolved it. Not sure what the issue is.