Ti.include: Differences Between Android and iPhone
Hello,
I want to include some device-specific constants in all of my JavaScript files. I thought the easiest way to do this would be to put the constants in the /Resources/android and /Resources/iphone directories, and include them using Ti.include() as needed.
I created two device specific constant files:
/Resources/android/device.js
/Resources/iphone/device.js
I have a /Resources/login/login.js
file. To include the device.js
file, I thought I could use this line in the login.js
file:
Ti.include("/device.js");
This works on Android; the /Resources/android/device.js
file is included. However, on iPhone, it complains that it can't find the device.js
file. To get the include to work on iPhone, I had to use this line:
Ti.include("../iphone/device.js");
Which obviously is not cross-platform.
My question: How I can include device specific files in a cross-platform way? Am I doing something wrong or did I encounter a bug? If it's a bug, is there any work around you can suggest?
Thank you!!!
-Ryan
3 Answers
-
I can't get any combination of path to work with Ti.include on android, only iphone. Even with what your example shows.
For your question, have you tried wrapping each include path syntax with:
if (Ti.Platform.osname == "iphone"){ //include one way } else if (Ti.Platform.osname == "android"){ //include the other way }
I've been using that conditional syntax to do various platform specific things.
-
One issue that I've been having is that when building for android, the javascripts are not getting copied to the Resources folder.
It only happens with a few javascript files. If I manually copy the js files to the build folder then the includes work.
I find that the android support in Titanium is light years behind the iphone support. -
This worked perfectly fine on 1.6, upon upgrading to 1.7 I have found this problem too.
Is this a bug or a feature?