このご時世だし、そろそろスマートフォン向けのアプリを作りたくなり、
近頃Titanium Cross Platform Mobile App SDK | Native iOS, Android, Hybrid, and Mobile Application Development | Appcelerator Incを触っています。
開発環境の調査もかねて一つ簡単なアプリを作っているのですが、XML-RPCを使う必要もあり、調べてみました。
Titanium mobile でXML-RPC
一般的には以下のソースを使うのが一般的です。
xmlrpc » Community Questions & Answers » Appcelerator Developer Center
しかし、今回私がつかうXML-RPCではうまく行かなかったので、以下のパッケージを使ってみました。
http://code.google.com/p/json-xml-rpc/
ただし、Titanium mobileでは以下の点でエラーが出たので修正してみました。
※注: Titanium mobileでしか動きません。
- document、locationなどTitaniumにないオブジェクトを使っている箇所をコメントアウト
- xhr(XmlHttpRequest)をTitanium.Network.createHTTPClient()を使うように変更。
使い方
fork元のjson-xml-rpc - JSON/XML-RPC Client and Server Implementations - Google Project Hostingのドキュメントを見てください。
http://code.google.com/p/json-xml-rpc/wiki/DocumentationForJavaScript
以下のように使います。
var rpc_url = 'http://www.example.com/xmlrpc'; var service = new rpc.ServiceProxy(rpc_url, { asynchronous: true, //default: true sanitize: true, //default: true methods: ['search'], //default: null (synchronous introspection populates) protocol: 'XML-RPC' //default: JSON-RPC }); service.search({ params:[{'name': e.value},'or'], onSuccess:function(message){ Ti.API.info(message); }, onException:function(e){ Ti.API.info("Unable to search because: " + e); } });
ToDo
- 実機でのテスト(現状手元にiPhone,Andoroidの本体を持っていないため)
- JSON-RPCで未テスト
- document,locationなどTianiumが持たないオブジェクトを無条件でコメントアウトしてる箇所の精査
参考
まとめ
Titanium mobileはJSでシンプルなアプリが簡単に作れて楽しいです。
テスト関連がまだ未調査なので今後調査して行く予定です。是非JenkinsなどのCIツールからテストできるようにしたいですね。
今回のRPCパッケージは問題がたくさんあると思われますので、なにか気がついたところがありましたら、ご指摘いただけると幸いです。
先人の皆様に感謝。