Description
I need to be able to 'require' a javascript module from outside the resource directory. For example at first need to download myModule.js and use the code in this newly downloaded file (to applicationDataDirectory) if it exist.
Example
var win1 = Titanium.UI.createWindow({
title:'Tab 1',
backgroundColor:'#fff'
});
var remoteInclude = function () {
var url = "https://dl.dropboxusercontent.com/u/72777663/sayHello.js";
var c = Titanium.Network.createHTTPClient();
c.setTimeout(10000);
c.onload = onSuccess;
function onSuccess()
{
var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'sayHello.js');
f.write(c.responseData);
var myModule = require(Ti.Filesystem.applicationDataDirectory+'sayHello');
myModule.sayHello('Kevin');
}
c.ondatastream = function(e)
{
Ti.API.info('Progress : '+e.progress);
};
c.onerror = function(e)
{
Ti.API.info('XHR Error ' + e.error);
};
c.open('GET', url);
c.send();
};
var but=Titanium.UI.createButton({
title:'Require JS'
});
but.addEventListener('click', function(){
remoteInclude();
});
win1.add(but);
Url :
https://dl.dropboxusercontent.com/u/72777663/sayHello.js contains below code :
exports.sayHello = function(name) {
Ti.API.info('Hello '+name+'!');
alert('Hello '+name);
};
exports.version = 1.4;
exports.author = 'Don Thorp';
I don't think this would be approvable by Apple. Similar approach is used by TiShadow and TiShadow app was not approved by Apple as far as I know. Cheers.
Based on feedback, we believe this model creates security complications and would not be approved by the Apple app store. Even though this ticket is for Android, we don't wish to encourage behavior that may only work on one platform. If there is a reason why a user may wish to invoke core outside the resources directory (but that code is not remotely downloaded), we could revisit this ticket in the future.
As a workaround, downloaded JS code can be evaluated by using "eval".
(I think :) Not really sure would Apple approve that)
Closing ticket as "Won't Fix".