NetEase Yunxin React Native SDK
npm install @kangfenmao/react-native-netease-im
import { NeteaseIm } from "@kangfenmao/react-native-netease-im"
NeteaseIm.foo()
For detailed usage, please refer to App.tsx
import { NeteaseIm } from "@kangfenmao/react-native-netease-im"
NeteaseIm.init("appKey", "apnsCername")
Note: The second parameter is the iOS push certificate name, which can be an empty string
onCreate
add initialization methods ofimport com.kangfenmao.nim.NeteaseIm;
@Override
public void onCreate() {
// ...
NeteaseIm.init(this, "appKey");
}
const listeners: EmitterSubscription[] = []
listeners . push (
// Connection status changed
NeteaseImEvent . addListener ( 'onConnectStatusChanged' , ( event : ConnectStatus ) =>
console . log ( event )
) ,
// Received a message
NeteaseImEvent . addListener ( 'onMessages' , ( messages : NIM . Message [] ) =>
console . log ( messages )
) ,
// Conversation list update
NeteaseImEvent . addListener ( 'onConversationsChanged' , ( conversations : NIM . Conversation []) =>
console.log(conversations)
)
)
// listeners.forEach((listener) => listener.remove())
Note: This method is used for the first login of the user
try {
const result = await NeteaseIm.login('account', 'token')
console.log(result)
} catch (error) {
console.log(error.code, error.message)
}
Remarks:
try {
await NeteaseIm.autoLogin()
} catch (error) {
console.log(error.message)
}
Check login status
const logined = await NeteaseIm . getLogined ( )
console . log ( 'Whether to log in:' , logined )
Note: This method has no return value
NeteaseIm.logout()
Send text message
try {
const result = await NeteaseIm . sendMessage (
'kangfenmao' ,
'This is a text message' ,
NimSessionTypeEnum . P2P ,
false
)
console . log ( result )
} catch ( error ) {
console . log ( { code : error . code , message : error . message } )
}
sendMessage(
account: string,
text: string,
type: NimSessionTypeEnum,
resend: boolean
): Promise<NIM.PromiseResult>
Get a message
getMessage(messageId: string, account: string, sessionType: SessionTypeEnum): Promise<NIM.Message>
Get historical news
getHistoryMessages(
sessionId: string,
sessionType: string,
messageId: string,
limit: number,
asc: boolean
): Promise<NIM.Message[]>
Query the latest historical message when messageId is an empty string
Get a list of recent conversations
await NeteaseIm.getConversations()
Delete a single conversation
NeteaseIm.deleteConversation(sessionId, SessionType.P2P)
Reset session unread
NeteaseIm.resetConversationUnreadCount(sessionId, SessionTypeEnum.P2P)
Get total unread
await NeteaseIm . getTotalUnreadCount ( )
NeteaseIm.sdkVersion
Modify index.js
the Init method, and the second parameter passed Certificate Name:
NeteaseIm.init("appKey", "apnsCertname")
In MainApplication.java
introducing head
import com.netease.nimlib.sdk.mixpush.MixPushConfig;
Modify onCreate
initialization methods is added MixPushConfig
:
NeteaseIm.init(this, "appKey", mixPushConfig);
mixPushConfig configuration
MixPushConfig mixPushConfig = new MixPushConfig();
// Mi push
mixPushConfig . XmAppId = " " ;
mixPushConfig.xmAppKey = "";
mixPushConfig.xmCertificateName = "";
// Huawei
mixPushConfig . HwAppId = " " ;
mixPushConfig.hwCertificateName = "";
// Meizu
mixPushConfig . MzAppId = " " ;
mixPushConfig.mzAppKey = "";
mixPushConfig.mzCertificateName = "";
// OPPO
mixPushConfig.oppoAppId = "";
mixPushConfig.oppoAppKey = "";
mixPushConfig.oppoAppSercet = "";
mixPushConfig.oppoCertificateName = "";
// VIVO
mixPushConfig.vivoCertificateName = "";
Clone the project to the local
run
yarn prepair
Modify example/env.json
yarn example ios
See the contributing guide to learn how to contribute to the repository and the development workflow.
Author: kangfenmao
Source Code: https://github.com/kangfenmao/react-native-netease-im
#react-native #react #mobile-apps