Make titanium easily and powerfully
Imroving productivity, giving a automated solution Titanium Command-Line Interface Reference
You must use Alloy to create MVC
Currently, Alloy is using Backbone version 0.9.2, which is not the most current version of Backbone. The documentation links in the Model guides link to version 0.9.2 of the Backbone documentation. If you go to the official Backbone site, the documentation might be out-of-sync with these guides.
Create your CLI command like jake
jakefile (coffeescript)
appplatform = switch process.env.appplatform
when 'ios', 'android' then process.env.appplatform
else 'ios'
apptarget = switch process.env.apptarget
when 'device' then process.env.apptarget
else
if appplatform is 'ios' then 'simulator' else 'emulator'
appdeploytype = switch process.env.appdeploytype
when 'development', 'test' then process.env.appdeploytype
else 'development'
appsimversion = switch process.env.appsimversion
when '6.1' then "-S #{process.env.appsimversion} --retina"
else '--retina --tall'
desc 'build app in normal way'
task 'build', ['prepare'], {async: true}, ->
if appplatform is 'android' and apptarget isnt 'device'
appappname = '' if appappname is 'rjhy'
cmds = "ti build -d YourProductName -p #{appplatform} -D #{appdeploytype} -C 'Google Nexus 4 - 4.3 - API 18 - 768x1280'"
jake.exec cmds, {interactive: true}, complete
else
jake.exec "ti build -d YourProductName -p #{appplatform} -T #{apptarget} -D #{appdeploytype} #{appsimversion}", {interactive: true}, complete
Using jslint to check code by CLI if you wirte javascript
Easily write xml by using jade
Modify alloy.jmk to redirect xml to jade
task('pre:compile', function(event, logger) {
var wrench = require('wrench'),
fs = require('fs'),
jade = require('jade'),
path = require('path'),
appDir = path.join(event.dir.project, 'app');
wrench.readdirSyncRecursive(appDir).forEach(function(view) {
if (view.match(/\.jade$/) && view.indexOf('templates') === -1 && view.indexOf('includes') === -1) {
try {
fs.writeFileSync(
path.join(appDir, view.replace(/\.jade$/, '.xml')),
jade.compile(fs.readFileSync(path.join(appDir, view)).toString(), {
filename: path.join(appDir, view),
pretty: true
})(event));
} catch (e) {
logger.error('ERROR: ' + view + '\n' + JSON.stringify(e));
process.exit(1);
}
}
});
});
Using tishadow to quickly build and update project
TiShadow provides Titanium developers the ability to deploy apps, run tests or execute code snippets live across all running iOS and Android devices.
Be careful about the assets of webview in tishadow
Using Genymotion quicken building simulator on android
example (coffeescript)
view = Ti.UI.createView
height: 100%
width: 100%
view.applyProperties
backgroundColor: 'red'
id: 'myview'
cls: 'header'
console.log "My view`s cls is %s", view.cls
If you could not ensure which mistake in your file then check source javascript file like 'Resources/$platform/alloy/controllers/index.js'
At lastest, you could read titanium-mobile source code if you could not solve your error
Don`t modify tainium-mobile source code and build your own titainum SDK to solve your problem although you can build it easily
# file a
Ti.Network.getOnline()
# file b
# It`s wrong
Titanium.App.version
First and foremost all of the things in '$' will be extend to exports Check the resource code, you will see
_.extend($, exports);
Other man can easily read which thing you hope to make it public
# wrong
$.updateUserInfo = (userInfo) ->
# right
exports.updateUserInfo = (userInfo) ->
Don`t use 'else', although your application only support iOS and android
# wrong
if OS_IOS
height = 45
else
height = 40
# better
height = 45
if OS_ANDROID
height = 40
# right
if OS_IOS
height = 45
else if OS_ANDROID
height = 40
Read document clearly before you create module
iOS Module Development Guide android Module Development Guide
Search in module-market [http://gitt.io/] before you create module
Read source code before your create module
You should imitate the sytle of source code
date: moment
async: async
util: underscore
Underscore is inner in titanium enviorment if the file is a controller When you use underscore in lib/*.js, you should require it by yourself Make sure the underscore document`s version equals titanium
Share your exprenrice to Q&A
Report issuses to titanium
Easily write code by using CoffeeScript, and check code by coffeelint
Best to bind data in xml(jade)
<Alloy>
<Collection src="book"/>
<Window backgroundColor="white" onClose="cleanup">
<ScrollableView dataCollection="book">
<View layout="vertical">
<ImageView image="{cover}" />
<Label text="{title} by {artist}" />
</View>
</ScrollableView>
</Window>
</Alloy>