problem
When referencing commonjs modules in code, iOS device builds do not reference platform specific modules if they are present, instead they reference the non-platform-specific ones. This does not occur on iOS simulator builds, which behave as expected. This makes it impossible to use platform-specific versions of Javascript files on iOS device builds, being a blocker for the linked tickets.
test case
app.js
var win = Ti.UI.createWindow({
backgroundColor: '#fff',
modal: false,
exitOnClose: true
});
win.open();
require('lib/mylib').sayHello();
lib/mylib.js
exports.sayHello = function() {
alert('hello from the CFG.js (you should never see this)');
}
iphone/lib/mylib.js
exports.sayHello = function() {
alert('hello from the iphone CFG.js');
}
reproduce
Create a traditional titanium app, adding the files mentioned above.
Run for iOS simulator
Confirm that you get the message from the platform-specific mylib.js file: "hello from the iphone CFG.js"
Now run for an iOS device
You will get the error described here, where the non-platform-specific module is referenced, giving you the message: "hello from the CFG.js (you should never see this)"
This works for iPhone, not pretty though: alloy compile --config platform=ios && cp -r Resources/iphone/* Resources && ti build --platform ios -T device OSX 10.8.4 Xcode Version 5.0 (5A11386k) Titanium CLI 3.1.2 Alloy 1.3.0 SDK 3.1.2.GA
Just to explain [~troscoe]'s comment a bit, it is relative to Alloy 1.3.0 which uses platform-specific compiles (ALOY-760). Due to this ticket, these don't work properly for iOS device builds. His steps workaround this issue by:
Compiling Alloy for ios, putting files in platform-specific folder
Copy the platform-specific files to top-level Resources folder. This won't conflict with other platforms since their platform-specific folders behave as expected and will override these.
Run a titanium build, which will compile alloy to the platform-specific folder again. These will be ignored and the files copied in the last step will be used by the Titanium build process.
Pull request: https://github.com/appcelerator/titanium_mobile/pull/4723
Closing ticket as fixed. Verified the "hello from the iphone CFG.js" alert is appearing on iOS device when adding lib/mylib.js and iphone/lib/mylib.js to the specified directory. Tested on: Titanium Studio, build: 3.2.0.201310181940 OS: Mac OS X Mountain Lion (10.8.5) SDK build: 3.2.0.v20131021142445 Ti CLI: 3.2.0 (72f7426b4ee6c2d2883c666d5b7e03906a16012f) Devices: iphone 4s (6.0.1), iphone 5 (7.0.2)