edo1z blog

プログラミングなどに関するブログです

Titanium とAppcelerator Cloud Services(BaaS)

ついに腰を据えてとりあえずTitaniumをやることに決めました。iPhoneでもAndroidでもアプリをJavascriptベースで作れるもので、Phonegapとかよりも速いらしい。Appcelerator Cloud Services(ACS)というBaasを自社で持っているため、Titaniumとの連動性が高い点も良さそう。iPhoneであればアプリ内課金に公式モジュールが対応しているようで、Android版モジュールもあるようだが、まだバグが多いようだという情報のみ発見した。まだ出来たてのようだ。

下記は、TitaniumでACSを使ってみたサンプルプログラムのコード

var Cloud = require('ti.cloud');
Cloud.debug = true;

Titanium.UI.setBackgroundColor('#0f0');

var win = Titanium.UI.createWindow({
 backgroundColor: '#000'
});

var label1 = Titanium.UI.createLabel({
 text: 'Sample1',
 color: '#ff0',
 font: {
  fontFamily: 'Arial',
  fontSize: '70px',
  fontWeight: 'bold'},
 top: '10px'
});

var label2 = Titanium.UI.createLabel({
 text: '',
 color: '#f0c',
 font: {
  fontFamily: 'Arial',
  fontSize: '30px',
  fontWeight: 'normal'},
 top: '100px'
});

var textField = Titanium.UI.createTextField({
 value: '',
 borderStyle: Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
 width: '200px',
 top: '150px'
});

var button = Titanium.UI.createButton({
 title: 'ボタン',
 top: '250px',
 width: '200px',
 height: '80px'
});

button.addEventListener('click',function(e){
 label2.text = 'User登録中...';

 Cloud.Users.create({
     username: textField.value,
     password: textField.value,
     password_confirmation: textField.value,
 }, function (e) {
     if (e.success) {
   label2.text = 'User登録が完了しました!';
     } else {
         label2.text = 'User登録に失敗しました。';
     }
 });
});

win.add(label1);
win.add(label2);
win.add(textField);
win.add(button);

win.open();