尊重版权,转载请注明出处
本文来自:江清清的技术专栏-翻译组(www.lcode.org)
开源项目地址:github.com/aksonov/rea…
项目介绍
该组件支持即时通信功能的开发,使用封装iOS XMPPFramework库。不过当前版本支持iOS平台以及只支持最基本的文字聊天。大家可以继续关注该开源项目,相信更多的功能会放出来
刚创建的React Native技术交流3群(496508742)欢迎各位大牛,React Native技术爱好者加入交流!
配置运行
1.1.运行命令进行安装依赖库
npm install react-native-xmpp --save
1.2. 命令行切换到XMPP组件目录
cd node_modules/react-native-xmpp
1.3.运行命令进行安装
pod install --no-integrate
1.4.XCode选中项目右击,Libraries ➜ 添加到当前项目
1.5.添加./node_modules/react-native-xmpp/RNXMPP.xcodeproj
1.6.点击Link Binary With Libraries 添加libRNXMPP.a, **libresolv*和 libxml2库
使用实例
var XMPP = require('react-native-xmpp');
// optional callbacks
XMPP.on('message', (message)=>console.log("MESSAGE:"+JSON.stringify(message)));
XMPP.on('iq', (message)=>console.log("IQ:"+JSON.stringify(message)));
XMPP.on('presence', (message)=>console.log("PRESENCE:"+JSON.stringify(message)));
XMPP.on('error', (message)=>console.log("ERROR:"+message));
XMPP.on('loginError', (message)=>console.log("LOGIN ERROR:"+message));
XMPP.on('login', (message)=>console.log("LOGGED!"));
XMPP.on('connect', (message)=>console.log("CONNECTED!"));
XMPP.on('disconnect', (message)=>console.log("DISCONNECTED!"));
// connect
XMPP.connect(MYJID, MYPASSWORD);
// send message
XMPP.message('Hello world!', TOJID);
// disconnect
XMPP.disconnect();
运行效果
当前实例通过流量登录服务器,并且在服务器中注册了四个用户,进行简单的聊天通信