Titanium聊天实现

时间:2012-09-14 13:13:39

标签: titanium-mobile

我有一项任务是实现一个基于聊天的应用程序,以使用Web服务api调用来访问服务器上可用的私有数据。显示所有可用的用户来自Web服务器并与这些人聊天。钛开发不可能支持iPhone / Android聊天应用程序。如果可能的话,让我指导实施。

1 个答案:

答案 0 :(得分:1)

是的,当然有可能。有一百万种方法可以做到这一点,你的问题不是很清楚。

如果它完全基于Web服务then just use this.

这是一个发布到Web服务并发送JSON对象的快速示例:

 var getChatMessages = Ti.Network.createHTTPClient({
        onload : function(e) {
             var doSomethignWithThis = this.responseText;
        },
        onerror : function(e) {
            Ti.API.info(this.responseText);
            Ti.API.info('SelectActivityStepsByKeyList webservice failed with message : ' + e.error);
        }
    });
    getChatMessages.open('POST', 'http://yourchatserver/GetChats');
    getChatMessages.setRequestHeader("Content-Type", "application/json");
    getChatMessages.send({"message" : "How is everyone today?", "user" : "me@me.com});

这对钛来说并不困难,硬件部分在服务器端。 Here is an example project that accomplishes chat through the use of the socket.io library.这可能是一种更好的方法。该链接包含有关其工作原理的视频以及完整的源代码。

相关问题