cocoafish / cocoafish-javascript-sdk-demo

Demo app showing sample use of the Javascript sdk
http://cocoafish.com
11 stars 4 forks source link

Titanium.Network undefined in cocoafish-1.2.min.js #5

Open fariazz opened 11 years ago

fariazz commented 11 years ago

Hi, I have a HTML5 app which uses the Javascript SDK, it works fine when I run it in a web browser. I want to wrap it in a webview using Titanium so that I can package it for Android.

When I run this HTML5 app inside of a webview in Titanium, I get the following error when running any sdk.sendRequest(), and it doesn't retrieve info from the ACS cloud:

[INFO][TiWebChromeClient.console(  390)] (main) [2796,30865] TypeError: Result of expression 'Titanium.Network' [undefined] is not an object. (1:http://sdk.cocoafish.com/js/cocoafish-1.2.min.js)

The code in Titanium's app.js is very simple:

var win = Ti.UI.createWindow({
    fullscreen:false,
    navBarHidden:true,
});
var webview = Ti.UI.createWebView({
    url: 'login.html',
    navBarHidden:true,
    fullscreen:true
});
win.add(webview);
win.open();

And login.html is very simple, it creates a new Cocoafish object with the app's key, then it uses sendRequest for login. It works well in all desktop web browsers.

ypjin commented 11 years ago

There seems problems with this approach. We did not test it. fariazz, can you please try Titanium module instead? Thanks for your patience.

fariazz commented 11 years ago

hi @ypjin using a Titanium module is not an option for this project. What I'm doing is a simple HTML5 app for an online course where I'll show how the same app can run in browsers, mobile browsers, and be wrapped in a webview and packed as a native app using Titanium.

Is is possible to disable the cocoafish file trying to access the "Titanium" object, I just want it to behave the same as if it was inside any web browser.

ypjin commented 11 years ago

I don't think there is a simple way to disable it. You may want to have a try with http://sdk.cocoafish.com/js/appcelerator/cocoafish-1.2.min.js which was built for Titanmium, but the suggested way is to use the Titanium module.

fariazz commented 11 years ago

Hi @ypjin thanks for your response.

You may want to have a try with http://sdk.cocoafish.com/js/appcelerator/cocoafish-1.2.min.js

That is exactly the file I'm already trying and where I'm getting the error...

cocoafish-1.2.min.js runs well on desktop browsers, mobile browsers, all I want is to be able to run it on a Titanium web view, I understand Titanium has a module for this (I use it in native apps with Titanium), but in the course I'm building I'm teaching students how to wrap a HTML5 app as a mobile app in a webview, not how to create a native app.

Since I'm already using ACS in the HTML5 app I though well the logic choice for wrapping the app would be Titanium (technology that I use on a daily basis in other projects). Would it be possible to double check if fixing this is not possible? I don't want to use ACS for the app and then Phonegap to wrap the app, wouldn't make much sense for the students :s

If this can't be fixed I think it would be good to put a warning on the Cocoafish Javascript SDK documentation, to let people know that the library doesn't run in Titanium webviews..