[TIMOB-20018] iOS: Ti.App.fireEvent from webView is not working
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2015-11-23T20:11:17.000+0000 |
Affected Version/s | Release 5.0.2 |
Fix Version/s | Release 5.2.0 |
Components | iOS |
Labels | webview |
Reporter | Ramesh RAMAMURTHY |
Assignee | Srikanth Sombhatla |
Created | 2015-11-18T17:03:53.000+0000 |
Updated | 2016-01-19T21:45:40.000+0000 |
Description
The example from your site that I am trying to run is not functioning in IOS 9.1. I am interested in getting the event fired from the WebView to be caught in the application. This works in Android but not in IOS. I have tried it WillHandleTouches set to False.
<html>
<head>
<script>
Ti.App.addEventListener("app:fromTitanium", function(e) {
alert(e.message);
});
</script>
</head>
<body>
<button onclick="Ti.App.fireEvent('app:fromWebView', { message: 'event fired from WebView, handled in Titanium' });">fromWebView</button>
</body>
</html>
var win = Ti.UI.createWindow();
var webview = Ti.UI.createWebView({
url: 'logging.html'
});
var button = Ti.UI.createButton({
title: 'fromTitanium',
height: '50dp',
width: '130dp'
});
button.addEventListener('click', function(e) {
Ti.App.fireEvent('app:fromTitanium', { message: 'event fired from Titanium, handled in WebView' });
});
Ti.App.addEventListener('app:fromWebView', function(e) {
alert(e.message);
});
win.add(webview);
win.add(button);
win.open();
This is seemingly a deadlock issue between the JS execution thread and main queue. For a quick work around, just delay the alert in JS so that main queue is not blocked. Change html to
In course we will fix this issue.
PR https://github.com/appcelerator/titanium_mobile/pull/7477 Tested with reported test case html.
The solution given seems to be for message from the App to WebView, My issue is the other way around from the WebView to the app. can you please see if there is a work around for that.
May I get an update on this issue please? we will really appreciate an fix or workaround for this issue?
Hi [~rramesh1], the issues was just resolved as part of the 5.2.0 release. Using the fix, your test case works from both webview -> app and app -> webview.
when will this be released? May I get a preview version so that we can begin testing our app.
Hi [~rramesh1], the release is planned for next year, as we just released 5.1.0.GA last week. But: You can always grab the latest preview version. [Here](http://builds.appcelerator.com/mobile/master/mobilesdk-5.2.0.v20151123122025-osx.zip) is the latest 5.2.0 build including the fix, we hope that helps!
I will try it out, If I run into trouble with 5.2.0 may I get a patch on 5.1.1 please
Since it is no 5.1.0 related issue and 5.1.1 is already out, you will need to wait until 5.2.0 releases. But you can always patch your own version by following [this](http://docs.appcelerator.com/platform/latest/#!/guide/Building_the_Titanium_SDK_From_Source) instructions.
I used the 5.2.0 you gave and tested the message, from the webview-> app did not work. here is code that I used. var html = '' + '' + '' + '' + '' + "" + ''+ '' ; var win = Ti.UI.createWindow(); var webview = Ti.UI.createWebView({ html:html, top :50, willHandleTouches:false }); var button = Ti.UI.createButton({ title: 'fromTitanium', height: '50dp', width: '130dp' }); button.addEventListener('click', function(e) { Ti.App.fireEvent('app:fromTitanium', { message: 'event fired from Titanium, handled in WebView' }); }); Ti.App.addEventListener('app:fromWebView', function(e) { alert(e.message); }); win.add(webview); win.add(button); win.open();
Just want to clarify that this is an issue only in IOS
You are trying to embed a multiline html file inline, for which the property is not intended. Please try the fix in the scenario you stated in the original ticket description where you load the html using a local file.
I will change it to local file and test it later today
var html = '' + '' + '' + '' + '' + "" + ''+ '' ; var htmlFile = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, "drive.html"); htmlFile.write(html); var win = Ti.UI.createWindow(); var webview = Ti.UI.createWebView({ //url:"https://saveonroad.com/test.html", url: htmlFile.getNativePath(), //html:html, top :50, willHandleTouches:false }); var button = Ti.UI.createButton({ title: 'fromTitanium', height: '50dp', width: '130dp' }); button.addEventListener('click', function(e) { Ti.App.fireEvent('app:fromTitanium', { message: 'event fired from Titanium, handled in WebView' }); }); Ti.App.addEventListener('app:fromWebView', function(e) { alert(e.message); }); win.add(webview); win.add(button); win.open();
tried these three scenarios , in none of the cases message from webview to App did not work. when the file is local or when using html string, app to webview message worked. When the file is remote messaging between the webview and the app did not work in both directions.
It works in one scenario, where the file exists on the local device, this file has to be static and we should not write to the file before opening it in the webview
Hi [~rramesh1], to clarify this once again: Sending and receiving events from the webview is *only* supposed to work with local html files. For example, your multi line inline had several syntax errors that prevented it from working. Please a) cache the html and display it or b) use a local html file from the beginning (recommended). If you still have issues, please check the [docs](http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.WebView) or the [Q&A](https://developer.appcelerator.com/questions/newest)
thanks Hans for your assistance it works now.
Closing ticket as fixed. Verified that while using the sample code from the bug description and a local html file (as per Hans's comment), I was able to fire an event from the app to WebView and vice-versa. Tested on: Appc CLI NPM: 4.2.2 Appc CLI Core: 5.2.0-229 Arrow: 1.7.21 SDK: 5.2.0.v20160114021251 Node: v4.2.4 OS: El Capitan (10.11.2) Xcode: 7.2 Devices: iphone 6 (9.2)