Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebViewBridge bug?? #154

Closed
camellieeee opened this issue Sep 21, 2016 · 9 comments
Closed

WebViewBridge bug?? #154

camellieeee opened this issue Sep 21, 2016 · 9 comments

Comments

@camellieeee
Copy link

2016-09-21 2 37 41
My HTML:
imgs[i].onclick=function(){
alert(1);
WebViewBridge.send('a');
alert(2);
}
only alert 1,cannot alert 2;
I think WebViewBridge is undefind. This �error appears after update XCode8

@StevenOspina
Copy link

Just noticed this too. I only get this on iOS 8 however. 9 and 10 work fine for me.

@camellieeee
Copy link
Author

@StevenOspina Me too, but how to save it on IOS8 ?

@hmedney
Copy link
Collaborator

hmedney commented Sep 27, 2016

@camellieeee @StevenOspina try installing from master and perform a clean build - just added a small change that should improve operation under IOS 8. Let me know if this resolves the issue...thanks!

@moaxaca
Copy link

moaxaca commented Sep 29, 2016

@StevenOspina Also having this problem on latest master, Android 23.

Rebuilding fixed it.

@alinz
Copy link
Owner

alinz commented Oct 4, 2016

@camellieeee did the rebuilding fix the issue? if not reopen this ticket. and give use more details about the problem.

@alinz alinz closed this as completed Oct 4, 2016
@annalamws
Copy link

I have installed react-native-webview-bridge version 0.33.0, react-native verson 0.33.0, and I am using Xcode 8 to build to an iphone with iOS 8. Crash occurs as below:
screen shot 2016-11-08 at 5 48 47 pm

However, iOS 9 and 10 work fine.
For iOS 8, everything work fine again when I change WebViewBridge to WebView. Please help.

@agumack
Copy link

agumack commented Nov 12, 2016

@annalamws i have same problem

@ezyone123
Copy link

ezyone123 commented Dec 2, 2016

@alinz I am not sure why this was closed

I am having this issue as well:

XCode Version 8.1 (8B62)
iPhone 5s running iOS 8.1 (12B41)
react-native version 0.37.0

using master react-native-webview-bridge

Exact issue outlined above on line
[webView stringByEvaluatingJavaScriptFromString:webViewBridgeScriptContent];

webViewBridgeScriptConent = (function (window) { 'use strict'; if (window.WebViewBridge) { return; } var RNWBSchema = 'wvb'; var sendQueue = []; var receiveQueue = []; var doc = window.document; var customEvent = doc.createEvent('Event'); function callFunc(func, message) { if ('function' === typeof func) { func(message); } } function signalNative() { window.location = RNWBSchema + '://message' + new Date().getTime(); } var WebViewBridge = { __push__: function (message) { receiveQueue.push(message); setTimeout(function () { var message = receiveQueue.pop(); callFunc(WebViewBridge.onMessage, message); }, 15); }, __fetch__: function () { var messages = JSON.stringify(sendQueue); sendQueue = []; return messages; }, send: function (message) { if ('string' !== typeof message) { callFunc(WebViewBridge.onError, "message is type '" + typeof message + "', and it needs to be string"); return; } sendQueue.push(message); signalNative(); }, onMessage: null, onError: null }; window.WebViewBridge = WebViewBridge; customEvent.initEvent('WebViewBridge', true, true); doc.dispatchEvent(customEvent); }(window));
Issue only happens on iOS 8, other devices work just fine

@ezyone123 ezyone123 mentioned this issue Dec 2, 2016
@ezyone123
Copy link

ezyone123 commented Dec 2, 2016

So it seems like this functionality has made it into react 0.37 in the web view, this library is no longer needed and seems to have lost the support of the author. This is great as this library remade a lot of stuff that was already in the web view so now its all in one place.

Details on the project that added this functionality

The docs

Basically replace WebViewBridge with WebView (imported from react-native) and in the web view call window.postMessage('some string'); where you want to pass a value around. The onBridgeMessage should also be changed to onMessage as a property of webview. The function onMessage(event) functions gets an event so you must extract the value from it using event.nativeEvent.data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants