react-native-tim
v1.0.33
Published
tencent im sdk
Downloads
5
Maintainers
Readme
腾讯云通讯
使用方法见index.js
安装
npm install @anren/react-native-tim
rnpm link
ios配置
xcode工程->BuildPhases->Link Binary With Libraries->添加以下库
- CoreTelephony.framework
- SystemConfiguration.framework
- libc++
- libz
- libsqlite3
####离线推送配置
1.首先要在工程->Build Settings->Header Search Paths中添加模块所在位置:$(SRCROOT)/../node_modules/react-native-tim/ios
,设置为recursive
.
2.AppDelegate.m中添加头文件#import "RCTTIM/RCTTIMPush.h"
3.在AppDelegate.m的didFinishLaunchingWithOptions
方法中添加如下代码,注意如果有其他推送模块已经添加了获取token的相关代码,则不需要填写。
//didFinishLaunchingWithOptions方法中添加获取token代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
[RCTTIMPush registerForRemoteNotifications];
...
}
4.添加如下三个方法:
//收到token,将token级busiId传递给RCTTIM模块。busiID为腾讯分配,
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
#if DEBUG
//开发环境
[RCTTIMPush registerDeviceToken:deviceToken withBusiId:TIM_BUSIID_DEV];
#else
//生产环境
[RCTTIMPush registerDeviceToken:deviceToken withBusiId:TIM_BUSIID_PRO];
#endif
}
//收到通知
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[RCTTIMPush didReceiveNotification:userInfo];
}
//收到通知(for ios7)
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[RCTTIMPush didReceiveNotification:userInfo];
}
android配置
AndroidManifest.xml 中添加以下权限
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
并在中添加以下配置
<!-- 消息收发service -->
<service
android:name="com.tencent.qalsdk.service.QalService"
android:exported="false"
android:process=":QALSERVICE" >
</service>
<!-- 消息收发辅助service -->
<service
android:name="com.tencent.qalsdk.service.QalAssistService"
android:exported="false"
android:process=":QALSERVICE" >
</service>
<!-- 离线消息广播接收器 -->
<receiver
android:name="com.tencent.qalsdk.QALBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.tencent.qalsdk.broadcast.qal" />
</intent-filter>
</receiver>
<!-- 系统消息广播接收器 -->
<receiver
android:name="com.tencent.qalsdk.core.NetConnInfoCenter"
android:process=":QALSERVICE">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.TIME_SET" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.TIMEZONE_CHANGED" />
</intent-filter>
</receiver>
MainApplication.java的添加如下代码
//getPackages添加下面一行,参数代表图标icon资源ID
new TIMPackage(R.mipmap.ic_launcher)
消息结构
消息共分为两部分:
- 消息基础信息
- 消息元素
示例如下:
// message struct
{
msgId: 'sadfasdf', //消息id
isSelf: false, //是否自己发送
hasGap: false, //是否存在消息断层,如果存在建议调用getMessage获取丢失消息。
eleCount: 1, //消息元素个数
isReaded: false, //是否已读
sender: 'asdasd' //发送者id
timestamp: 1239012309, //创建时间
elems: [ //消息元素,数组,可能多个
//文本元素
{
type:'text',
data:'hello world.'
}
]
}
消息元素有以下几种类型:
- text 文本信息
- custom 自定义信息,子类型为image,audio及其他命令信息
- groupSystem 群系统消息,子类型(subType字段)参见腾讯官网
- groupTips 群提示信息,子类型(subType字段)参见腾讯官网
以上信息分别有不同的结构,具体参见官网。