Skip to content

Commit 3577782

Browse files
committed
ios sdk版本升级到6.2.0
1 parent 3fde796 commit 3577782

File tree

8 files changed

+312
-8
lines changed

8 files changed

+312
-8
lines changed

docs/.nojekyll

Whitespace-only changes.

docs/README.md

Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
2+
React Native的网易云信插件
3+
欢迎加入QQ群交流`153174456`
4+
## Demo
5+
[react-native-chat-demo](https://github.com/reactnativecomponent/react-native-chat-demo)
6+
7+
#### 注意事项:
8+
9+
##### 1.react-native版本需要0.47.0及以上NIMSDK对应版本4.7.0
10+
11+
##### 2.普通帐号不要使用5位数,因为5位数设定是系统帐号,尽量使用6位或者6位以上
12+
13+
## 如何安装
14+
15+
### 1.首先安装npm包
16+
17+
```bash
18+
npm install react-native-netease-im --save
19+
```
20+
21+
### 2.link
22+
```bash
23+
react-native link react-native-netease-im
24+
```
25+
26+
#### 手动link~(如果不能够自动link)
27+
##### ios
28+
```
29+
a.打开XCode's工程中, 右键点击Libraries文件夹 ➜ Add Files to <...>
30+
b.去node_modules ➜ react-native-netease-im ➜ ios ➜ 选择 RNNeteaseIm.xcodeproj
31+
c.在工程Build Phases ➜ Link Binary With Libraries中添加libRNNeteaseIm.a
32+
```
33+
##### Android
34+
```
35+
// file: android/settings.gradle
36+
...
37+
38+
include ':react-native-netease-im'
39+
project(':react-native-netease-im').projectDir = new File(settingsDir, '../node_modules/react-native-netease-im/android')
40+
```
41+
42+
```
43+
// file: android/app/build.gradle
44+
...
45+
46+
dependencies {
47+
...
48+
compile project(':react-native-netease-im')
49+
}
50+
```
51+
52+
`android/app/src/main/java/<你的包名>/MainActivity.java`
53+
54+
```
55+
import com.netease.im.uikit.permission.MPermission;
56+
import com.netease.im.RNNeteaseImModule;
57+
import com.netease.im.ReceiverMsgParser;
58+
59+
public class MainActivity extends ReactActivity {
60+
61+
......
62+
63+
@Override
64+
protected void onCreate(Bundle savedInstanceState) {
65+
super.onCreate(savedInstanceState);
66+
if(ReceiverMsgParser.checkOpen(getIntent())){//在后台时处理点击推送消息
67+
RNNeteaseImModule.launch = getIntent();
68+
}
69+
}
70+
71+
@Override
72+
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
73+
MPermission.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
74+
}
75+
```
76+
77+
`android/app/src/main/java/<你的包名>/MainApplication.java`中添加如下两行:
78+
79+
```java
80+
...
81+
import com.netease.im.RNNeteaseImPackage; // 在public class MainApplication之前import
82+
import com.netease.im.IMApplication;
83+
84+
public class MainApplication extends Application implements ReactApplication {
85+
86+
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
87+
@Override
88+
protected boolean getUseDeveloperSupport() {
89+
return BuildConfig.DEBUG;
90+
}
91+
92+
@Override
93+
protected List<ReactPackage> getPackages() {
94+
return Arrays.<ReactPackage>asList(
95+
         new RNNeteaseImPackage(), // 然后添加这一行
96+
new MainReactPackage()
97+
);
98+
}
99+
};
100+
101+
@Override
102+
public ReactNativeHost getReactNativeHost() {
103+
return mReactNativeHost;
104+
}
105+
@Override
106+
public void onCreate() {
107+
   //初始化方法appId以及appKey在小米开放平台获取,小米推送证书名称在网易云信后台设置
108+
   IMApplication.setDebugAble(BuildConfig.DEBUG);
109+
   IMApplication.init(this, MainActivity.class,R.drawable.ic_stat_notify_msg,new   IMApplication.MiPushConfig("小米推送证书名称","小米推送appId","小米推送的appKey"));
110+
...
111+
}
112+
}
113+
```
114+
115+
116+
### 3.工程配置
117+
#### iOS配置
118+
install with CocoaPods
119+
```
120+
pod 'NIMSDK', '4.9.0'
121+
pod 'SSZipArchive', '~> 1.2'
122+
pod 'Reachability', '~> 3.1.1'
123+
pod 'CocoaLumberjack', '~> 2.0.0-rc2'
124+
pod 'FMDB', '~>2.5'
125+
```
126+
Run `pod install`
127+
128+
在工程target的`Build Phases->Link Binary with Libraries`中加入`、libsqlite3.0.tbd、libc++.tbd、libz.tbd、CoreTelephony.framework、AVFoundation.framework、CoreMedia.framework、CoreMotion.framework`
129+
130+
131+
132+
在你工程的`AppDelegate.m`文件中添加如下代码:
133+
134+
```
135+
...
136+
#import <NIMSDK/NIMSDK.h>
137+
#import "NTESSDKConfigDelegate.h"
138+
@interface AppDelegate ()
139+
@property (nonatomic,strong) NTESSDKConfigDelegate *sdkConfigDelegate;
140+
@end
141+
@implementation AppDelegate
142+
143+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
144+
{
145+
...
146+
[self setupNIMSDK];
147+
[self registerAPNs];
148+
if (launchOptions) {//未启动时,点击推送消息
149+
NSDictionary * remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
150+
if (remoteNotification) {
151+
[self performSelector:@selector(clickSendObserve:) withObject:remoteNotification afterDelay:0.5];
152+
}
153+
}
154+
...
155+
return YES;
156+
}
157+
- (void)clickSendObserve:(NSDictionary *)dict{
158+
[[NSNotificationCenter defaultCenter]postNotificationName:@"ObservePushNotification" object:@{@"dict":dict,@"type":@"launch"}];
159+
}
160+
- (void)setupNIMSDK
161+
{
162+
//在注册 NIMSDK appKey 之前先进行配置信息的注册,如是否使用新路径,是否要忽略某些通知,是否需要多端同步未读数
163+
self.sdkConfigDelegate = [[NTESSDKConfigDelegate alloc] init];
164+
[[NIMSDKConfig sharedConfig] setDelegate:self.sdkConfigDelegate];
165+
[[NIMSDKConfig sharedConfig] setShouldSyncUnreadCount:YES];
166+
//appkey 是应用的标识,不同应用之间的数据(用户、消息、群组等)是完全隔离的。
167+
//注册APP,请将 NIMSDKAppKey 换成您自己申请的App Key
168+
[[NIMSDK sharedSDK] registerWithAppID:@"appkey" cerName:@"证书名称"];
169+
}
170+
171+
#pragma mark - misc
172+
- (void)registerAPNs
173+
{
174+
[[UIApplication sharedApplication] registerForRemoteNotifications];
175+
UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
176+
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
177+
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
178+
}
179+
180+
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
181+
{
182+
[[NIMSDK sharedSDK] updateApnsToken:deviceToken];
183+
}
184+
//在后台时处理点击推送消息
185+
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
186+
187+
[[NSNotificationCenter defaultCenter]postNotificationName:@"ObservePushNotification" object:@{@"dict":userInfo,@"type":@"background"}];
188+
}
189+
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
190+
{
191+
NSLog(@"fail to get apns token :%@",error);
192+
}
193+
- (void)applicationDidEnterBackground:(UIApplication *)application {
194+
NSInteger count = [[[NIMSDK sharedSDK] conversationManager] allUnreadCount];
195+
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:count];
196+
}
197+
```
198+
199+
#### Android配置
200+
201+
`android/app/build.gradle`里,defaultConfig栏目下添加如下代码:
202+
203+
204+
`AndroidManifest.xml`里,添加如下代码:
205+
```
206+
< manifest
207+
208+
......
209+
210+
<!-- SDK 权限申明, 第三方 APP 接入时,请将 com.im.demo 替换为自己的包名 -->
211+
<!-- 和下面的 uses-permission 一起加入到你的 AndroidManifest 文件中。 -->
212+
<permission
213+
android:name="com.im.demo.permission.RECEIVE_MSG"
214+
android:protectionLevel="signature"/>
215+
<!-- 接收 SDK 消息广播权限, 第三方 APP 接入时,请将 com.im.demo 替换为自己的包名 -->
216+
<uses-permission android:name="com.im.demo.permission.RECEIVE_MSG"/>
217+
<!-- 小米推送 -->
218+
<permission
219+
android:name="com.im.demo.permission.MIPUSH_RECEIVE"
220+
android:protectionLevel="signature"/>
221+
<uses-permission android:name="com.im.demo.permission.MIPUSH_RECEIVE"/>
222+
223+
......
224+
< application
225+
......
226+
<!-- 设置你的网易聊天App Key -->
227+
<meta-data
228+
android:name="com.netease.nim.appKey"
229+
android:value="App Key" />
230+
<!--添加新的 IPC 数据共享机制,替换不安全的多进程读写 SharedPreference-->
231+
<provider
232+
android:name="com.netease.nimlib.ipc.NIMContentProvider"
233+
android:authorities="com.im.demo.ipc.provider"
234+
android:exported="false"
235+
android:process=":core" />
236+
237+
```
238+
239+
## 如何使用
240+
241+
### 引入包
242+
243+
```
244+
import {NimSession} from 'react-native-netease-im';
245+
```
246+
247+
### API
248+
249+
参考[index.js](https://github.com/reactnativecomponent/react-native-netease-im/blob/master/index.js)
250+
251+
#### 监听会话
252+
```
253+
NativeAppEventEmitter.addListener("observeRecentContact",(data)=>{
254+
 console.log(data); //返回会话列表和未读数
255+
});
256+
```
257+
#### 推送
258+
```
259+
//程序运行时获取的推送点击事件
260+
NativeAppEventEmitter.addListener("observeLaunchPushEvent",(data)=>{
261+
 console.log(data);
262+
});
263+
//程序后台时获取的推送点击事件
264+
NativeAppEventEmitter.addListener("observeBackgroundPushEvent",(data)=>{
265+
 console.log(data);
266+
});
267+
//推送数据格式
268+
{
269+
...
270+
   sessionBody:{
271+
sessionId:"",
272+
sessionType:"",
273+
sessionName:""
274+
}
275+
}
276+
277+
```
278+

docs/index.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>react-native-netease-im - 网易云信ReactNative插件</title>
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
7+
<meta name="description" content="网易云信ReactNative插件">
8+
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
9+
<link rel="stylesheet" href="//unpkg.com/docsify/lib/themes/vue.css">
10+
</head>
11+
<body>
12+
<div id="app"></div>
13+
<script>
14+
window.$docsify = {
15+
name: 'react-native-netease-im',
16+
repo: 'https://github.com/reactnativecomponent/react-native-netease-im'
17+
}
18+
</script>
19+
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
20+
</body>
21+
</html>

im/Friend.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
/**
2-
* Created by dowin on 2017/8/2.
1+
/*
2+
* @Author: huangjun
3+
* @Date: 2019-03-06 16:28:25
4+
* @Last Modified by: huangjun
5+
* @Last Modified time: 2019-03-06 16:51:34
36
*/
4-
'use strict'
57
import { NativeModules,Platform } from 'react-native'
68
const { RNNeteaseIm } = NativeModules
79
class Friend {

ios/RNNeteaseIm/RNNeteaseIm.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@
431431
4E5B474B1EC1788F00D74E72 /* Debug */ = {
432432
isa = XCBuildConfiguration;
433433
buildSettings = {
434+
FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)/../../../../ios/Pods/**";
434435
GCC_PREFIX_HEADER = RNNeteaseIm/PrefixHeader.pch;
435436
HEADER_SEARCH_PATHS = (
436437
"$(SRCROOT)/../../../react-native/React/**",
@@ -446,6 +447,7 @@
446447
4E5B474C1EC1788F00D74E72 /* Release */ = {
447448
isa = XCBuildConfiguration;
448449
buildSettings = {
450+
FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)/../../../../ios/Pods/**";
449451
GCC_PREFIX_HEADER = RNNeteaseIm/PrefixHeader.pch;
450452
HEADER_SEARCH_PATHS = (
451453
"$(SRCROOT)/../../../react-native/React/**",

ios/RNNeteaseIm/RNNeteaseIm/PrefixHeader.pch

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
//
88
#ifndef PrefixHeader_pch
99
#define PrefixHeader_pch
10-
#import <NIMSDK.h>
10+
#import <NIMSDK/NIMSDK.h>
1111
#import "NTESGlobalMacro.h"
1212
#import "NIMKitInfo.h"
1313
#import "NIMKitUtil.h"
1414
#import "NIMKitInfoFetchOption.h"
1515
#import <CocoaLumberjack/CocoaLumberjack.h>
16-
#import "NIMAVChat.h"
16+
#import <NIMAVChat/NIMAVChat.h>
17+
1718
#import "NIMKit.h"
1819
#import "NIMObject.h"
1920
#import "DWCustomAttachment.h"

ios/RNNeteaseIm/RNNeteaseIm/TeamViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ -(void)dismissTeam:(NSString *)teamId Succ:(Success)succ Err:(Errors)err{
409409
//拉人入群
410410
-(void)addMembers:(NSString *)teamId accounts:(NSArray *)count Succ:(Success)succ Err:(Errors)err{
411411
NSString *postscript = @"邀请你加入群组";
412-
[[NIMSDK sharedSDK].teamManager addUsers:count toTeam:teamId postscript:postscript completion:^(NSError *error, NSArray *members) {
412+
[[NIMSDK sharedSDK].teamManager addUsers:count toTeam:teamId postscript:postscript attach:@"" completion:^(NSError *error, NSArray *members) {
413413
if (!error) {
414414
succ(@"200");
415415
}else{

ios/RNNeteaseIm/RNNeteaseIm/Util/NTESBundleSetting.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
//
88

99
#import <Foundation/Foundation.h>
10-
#import "NIMGlobalDefs.h"
11-
#import "NIMAVChatDefs.h"
10+
#import <NIMSDK/NIMGlobalDefs.h>
11+
#import <NIMAVChat/NIMAVChatDefs.h>
1212

1313
//部分API提供了额外的选项,如删除消息会有是否删除会话的选项,为了测试方便提供配置参数
1414
//上层开发只需要按照策划需求选择一种适合自己项目的选项即可,这个设置只是为了方便测试不同的case下API的正确性

0 commit comments

Comments
 (0)