तक नहीं पहुंच सकता है मैं index.html
दिखाने के लिए प्रतिक्रिया मूल वेबव्यू का उपयोग करता हूं, और HTML ऐप पर मैज पोस्ट करेगा। तब ऐप संदेश प्राप्त करेगा और इसे कंसोल पर लिख देगा। समस्या यह है कि ऐप संदेश प्राप्त नहीं कर सकता है, जब postMessage
तुरंत सिर पर चलाया जाता है। मुझे लगता है कि यह शायद एचटीएमएल से संबंधित लोडिंग समाप्त नहीं हुआ है। मैंने setTimeout
के साथ देरी का उपयोग किया, और यह काम किया।देशी एचटीएमएल पोस्ट प्रतिक्रिया प्रतिक्रिया संदेश वेबव्यू
अब मैं जानना चाहता हूँ:
- वहाँ इस समस्या को हल करने के लिए बेहतर तरीका है?
- देरी 100 मिलीस्कॉन्ड क्यों काम नहीं करती, लेकिन 200 मिलीस्कॉन्ड में देरी हुई?
मैं प्रतिक्रिया मूल संस्करण 0.3 9.0, और नोड संस्करण 7.2.0 का उपयोग कर रहा हूं।
यहाँ कोड है मैं अब तक है:
index.html
<head>
<title>Index</title>
<script type="text/javascript" src="index.js"></script>
<script type="text/javascript">
// can not be received
postMessage('send to react native from index inline, no delay', '*');
// can not be received
setTimeout(function(){
postMessage('send to react native from index inline, delay 0 milliscond', '*')
}, 0);
// can received
setTimeout(function(){
postMessage('send to react native from index inline, delay 100 milliscond', '*')
}, 100);
onload = function() {
// can not be received
postMessage('send to react native from index inline after onload, no delay', '*')
// can received
setTimeout(function() {
postMessage('send to react native from index inline after onload, delay 0 milliscond', '*')
}, 0);
};
</script>
index.js
// can not be received
postMessage('send to react native from index.js, no delay', '*');
// can not be received
setTimeout(function() {
postMessage('send to react native from index.js, delay 100 milliscond', '*')
}, 100);
// can received
setTimeout(function() {
postMessage('send to react native from index.js, delay 200 milliscond', '*')
}, 200);
मूल निवासी web_view_page.js
प्रतिक्रिया 10क्रोम कंसोल लॉग
2016-12-21 11:45:02.367 web_view.js:147 onMessage: send to react native from index inline after onload, delay 0 milliscond
2016-12-21 11:45:02.491 web_view.js:147 onMessage: send to react native from index inline, delay 100 milliscond
2016-12-21 11:45:02.628 web_view.js:147 onMessage: send to react native from index.js, delay 200 milliscond