我有一个任务是实现一个基于聊天的应用程序,以使用 Web 服务 api 调用访问服务器上可用的私有(private)数据。显示 Web 服务器上的所有可用用户并与这些人聊天。钛开发不可能支持iPhone/Android 聊天应用程序。如果可能的话,让我指导实现相同的操作。
最佳答案
是的,当然有可能。有一百万种方法可以做到这一点,你的问题不是很清楚。
如果它完全基于网络服务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" : "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="660b03260b034805090b" rel="noreferrer noopener nofollow">[email protected]</a>});
这对于钛合金来说并不困难,困难的部分是在服务器端。 Here is an example project that accomplishes chat through the use of the socket.io library.这对您来说可能是更好的方法。该链接包含有关其工作原理的视频以及完整的源代码。
关于titanium-mobile - 钛聊天实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12425327/