NetEase Yunxin React Native SDK

NetEase Yunxin React Native SDK

react-native-netease-im .NetEase Yunxin React Native SDK

react-native-netease-im

NetEase Yunxin React Native SDK

installation

npm install @kangfenmao/react-native-netease-im

Instructions

import { NeteaseIm } from "@kangfenmao/react-native-netease-im"

NeteaseIm.foo()

For detailed usage, please refer to App.tsx

initialization

  1. Add an initialization method to the project entry index.js
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

  1. MainApplication.java Android system also need to onCreateadd initialization methods of
import com.kangfenmao.nim.NeteaseIm;

@Override
public void onCreate() {
  // ...
  NeteaseIm.init(this, "appKey");
}

event

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())

API

login

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)
}

autoLogin

Remarks:

  1. Every time you start the App, you need to call this method for fast login, and fast login does not require a user name and token.
  2. This method has no return value and needs to monitor the connection status.
  3. When the user logs out, he must log in again and call this interface to log in successfully.
try {
  await NeteaseIm.autoLogin()
} catch (error) {
  console.log(error.message)
}

getLoggined

Check login status

const  logined  =  await  NeteaseIm . getLogined ( ) 
console . log ( 'Whether to log in:' ,  logined )

logout

Note: This method has no return value

NeteaseIm.logout()

sendMessage

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>

getMessage

Get a message

getMessage(messageId: string, account: string, sessionType: SessionTypeEnum): Promise<NIM.Message>

getHistoryMessages

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

getConversations

Get a list of recent conversations

await NeteaseIm.getConversations()

deleteConversation

Delete a single conversation

NeteaseIm.deleteConversation(sessionId, SessionType.P2P)

resetConversationUnreadCount

Reset session unread

NeteaseIm.resetConversationUnreadCount(sessionId, SessionTypeEnum.P2P)

getTotalUnreadCount

Get total unread

await  NeteaseIm . getTotalUnreadCount ( )

SDK version

NeteaseIm.sdkVersion

Push configuration

iOS push configuration

Modify index.jsthe Init method, and the second parameter passed Certificate Name:

NeteaseIm.init("appKey", "apnsCertname")

Android push configuration

In MainApplication.javaintroducing head

import com.netease.nimlib.sdk.mixpush.MixPushConfig;

Modify onCreateinitialization 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 = "";

Example

Clone the project to the local

run

yarn prepair

Modify example/env.json

yarn example ios

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

Download Details:

Author: kangfenmao

Source Code: https://github.com/kangfenmao/react-native-netease-im

react-native react mobile-apps

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How native is React Native? | React Native vs Native App Development

Article covers: How native is react native?, React Native vs (Ionic, Cordova), Similarities and difference between React Native and Native App Development.

React Native Mobile App Development

Skenix is providing React Native Development Services with qualified React Native App Developers. Get the best React Native App Development Services.

How React Native Is Shaping Mobile App Development

Are you a mobile app developer looking for more efficient tools for your projects? Mobile app development is getting tougher and tougher as the market continues to grow. As a developer, you need to develop Apps which meet the demands of your users. To achieve this, adopt the right tools, like the React Native development framework.

Top React Native Mobile App Development Companies in USA

Looking for top React Native mobile app development company in USA for Startups & Enterprise? Find out the top list of React Native mobile app development company in USA.

Which is the best React Native app development company in New York?

Hire top react native app development company in New York to build and develop custom react native mobile apps for Android & iOS with the latest features.