Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-14207] BlackBerry: Local WebView - Ti is undefined

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2013-12-18T00:16:41.000+0000
Affected Version/sRelease 3.1.1
Fix Version/s2013 Sprint 13 BB, 2013 Sprint 13, Release 3.1.2, Release 3.2.0
ComponentsBlackBerry
LabelsBlackberry, events, qe-closed-3.2.0, qe-testadded, ti.app, webview
ReporterMichael DeGiovanni
AssigneePedro Enrique
Created2013-06-12T15:26:15.000+0000
Updated2013-12-18T06:51:39.000+0000

Description

*Problem* In a local webview any titanium functionality such as
Ti.API.info('hello world');
or more important than that
Ti.API.addEventListener/fireEvent
do not work. I have also tried placing them in a timeout like mobile web but to no avail: Ti is always undefined. *index.xml*
<Window class="container" id="home" platform="android,blackberry">
	<WebView id="mainWebView" url="/www/index.html"  disableBounce="true"/>
</Window>
*index.js*
if (Ti.Platform.name === 'blackberry'){
    $.mainWebView.url = 'local:///assets/www/index.html';
}
*index.html*
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

	<title>SomePage</title>
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
	
	
	<link href="css/stylesheet.css" rel="stylesheet">
    
       <!-- THE OFFENDING CODE SNIPPET -->
	<script type="text/javascript">
	    window.onload = function(){
	    	setTimeout(function(){
	    		alert(typeof(Ti));
	    		Ti.API.info('in timeout file');
	    		Ti.API.fireEvent('someEvent');
	    	},2000);	
	    };
		
	</script>
	<script data-main="js/main" src="js/libs/require.js"></script>
</head>
<body>
</body>
</html>

Attachments

FileDateSize
webview_test.zip2013-08-12T22:22:30.000+00001306

Comments

  1. Russell McMahon 2013-06-13

    Can we get a snippet of offending code? Ti.API.info is available but I'm not sure what in web view means.
  2. Michael DeGiovanni 2013-06-13

    index.xml has the following: since /www/index.html somehow in blackberry cannot be found for the webview's url, in index.js a condition is done checking the platform if(Ti.Platform.name ==='blackberry'){ $.mainWebView.url = 'local:///assets/www/index.html'; } index.html has the following code: SomePage
  3. Michael DeGiovanni 2013-06-13

    looking at the blackberry documentation and the github Tiblackberry repository, I think this is still missing for two way interaction between the webview and the app on titanium. "You can interact with JavaScript executing on the page by using postMessage() and connecting to the messageReceived() signal. JavaScript can communicate back by using the "navigator.cascades.postMessage()" function and storing a message handler in the "navigator.cascades.onmessage" property." (http://developer.blackberry.com/cascades/reference/bb__cascades__webview.html)
  4. Michael DeGiovanni 2013-06-13

    Based on the android binding.js, I've added the following gist that needs to be injected on a local webview: https://gist.github.com/anonymous/5772986 .Obviously the interface between the titanium app has to be added. Note that in that gist the logging part has been left our (in Android it is through the webviews addJavascriptInterface )
  5. Pedro Enrique 2013-06-18

    Thanks Michael, I'm working on this.
  6. Pedro Enrique 2013-06-19

    PR: https://github.com/appcelerator/titanium_mobile_blackberry/pull/111
  7. Russell McMahon 2013-06-27

    Nice.
  8. Michael DeGiovanni 2013-06-28

    thanks!
  9. Pedro Enrique 2013-08-12

    Attached sample code
  10. Lokesh Choudhary 2013-08-12

    Verified the fix & the fix works as expected.Thus closing. Environment: Appcel Studio : 3.1.2.201308082014 Ti SDK : 3.1.2.v20130809141556 Mac OSX : 10.8.4 Alloy : 1.2.0-alpha6 CLI - 3.1.2-alpha win 7 Win 8 Z10 BB simulator : 10.0.10.822 Z10 device running 10.0.10.88 Q10 Simulator : 10.1.0.1720 Q10 Dev alpha C device running 10.1.0.138
  11. Olga Romero 2013-12-17

    [~penrique] Appcelerator Studio, build: 3.2.0.201312162210 Titanium SDK, build: 3.2.0.v20131216191854 CLI 3.2.0-cr3 Alloy 1.3.0-cr2 BBZ10 10.1.0 Tested .zip and webview header value "something else" does not change to "am changed again" as per code.
  12. Pedro Enrique 2013-12-17

    Cause was due to a change in the Ti.App module. PR for master: https://github.com/appcelerator/titanium_mobile_blackberry/pull/199 PR for 3.2.x: https://github.com/appcelerator/titanium_mobile_blackberry/pull/200
  13. Priya Agarwal 2013-12-18

    Tested Environment: Appcelerator Studio: 3.2.0.201312171913 SDK:3.2.0.v20131217190633 alloy: 1.3.0-cr2 acs: 1.0.10 npm: 1.3.2 titanium: 3.2.0-cr3 titanium-code-processor: 1.1.0-cr2 OS: Mac OSX 10.9 Blackberry Z10(v 10.0.10.261) Used with the sample code attached. Got the expected result as per code. 1)Clicking on 'click here' button. Webview header with id header_2 changes its title as 'something else' and also button with having title 'fire event' also changes to 'something else'. Console also gets logged printed with "Hello World!" 2)Then on clicking 'something else' title button. Again the Webview header with id header_2 changes its title as 'prop_1' Hence closing the issue as working fine.

JSON Source