2828
29294 . 点击 ** Finish** 。根据屏幕提示,安装所需插件。
3030
31- 上述步骤使用 ** DevEco Studio 5.0.1 Release(5.0.5.315 )** 示例。
31+ 上述步骤使用 ** DevEco Studio 5.1.0 Release(5.1.0.828 )** 示例。
3232
33335 . 在项目中引入 SDK。
3434
@@ -111,15 +111,14 @@ ohpm install @easemob/chatuikit
111111
112112``` typescript
113113import { ChatPageParams , ChatUIKitClient , ChatClient , ChatError , ChatOptions , ConversationType } from ' @easemob/chatuikit' ;
114- import { promptAction } from ' @kit.ArkUI' ;
115114
116115@Entry
117116@Component
118117struct Index {
119118 pathStack : NavPathStack = new NavPathStack ();
120119 private appKey : string = [项目的AppKey ]; // 将[项目的AppKey]替换为项目的 App Key 字符串
121120 private userId : string = ' ' ;
122- private password : string = ' ' ;
121+ private token : string = ' ' ;
123122 private peerId : string = ' ' ;
124123
125124 private initSDK () {
@@ -128,34 +127,34 @@ struct Index {
128127 });
129128 options .setAutoLogin (false );
130129 let client = ChatClient .getInstance ();
131- client .init (getContext (), options );
130+ client .init (this . getUIContext (). getHostContext (), options );
132131 ChatUIKitClient .init (client );
133132 }
134133
135134 private login () {
136- if (! this .userId || ! this .password ) {
137- promptAction . showToast ({message: " UserId or password cannot be empty!" });
135+ if (! this .userId || ! this .token ) {
136+ this . getUIContext (). getPromptAction (). showToast ({message: " UserId or token cannot be empty!" });
138137 return ;
139138 }
140- ChatUIKitClient .loginWithPassword (this .userId , this .password )
139+ ChatUIKitClient .login (this .userId , this .token )
141140 .then (() => {
142- promptAction .showToast ({message: " Login successful!" });
141+ this . getUIContext (). getPromptAction () .showToast ({message: " Login successful!" });
143142 })
144143 .catch ((e : ChatError ) => {
145- promptAction .showToast ({message: " Login failed: " + e .description });
144+ this . getUIContext (). getPromptAction () .showToast ({message: " Login failed: " + e .description });
146145 })
147146 }
148147
149148 private logout () {
150149 ChatUIKitClient .logout (false )
151150 .then (() => {
152- promptAction .showToast ({message: " Logout successful!" });
151+ this . getUIContext (). getPromptAction () .showToast ({message: " Logout successful!" });
153152 })
154153 }
155154
156155 private startChat () {
157156 if (! this .peerId ) {
158- promptAction .showToast ({message: " Peer id cannot be empty!" });
157+ this . getUIContext (). getPromptAction () .showToast ({message: " Peer id cannot be empty!" });
159158 return ;
160159 }
161160 this .pathStack .pushPath ({name: ' ChatPage' , param: {
@@ -175,10 +174,9 @@ struct Index {
175174 .commonStyle ()
176175 .onChange (value => this .userId = value )
177176
178- TextInput ({ placeholder: ' Password ' })
177+ TextInput ({ placeholder: ' Token ' , text: this . token })
179178 .commonStyle ()
180- .type (InputType .Password )
181- .onChange (value => this .password = value )
179+ .onChange (value => this .token = value )
182180
183181 Button (' Login' )
184182 .commonStyle ()
@@ -235,4 +233,4 @@ struct Index {
235233
2362343 . 在另一台设备或者模拟器上登录另一个账号。
237235
238- 4 . 两台设别或者模拟器分别输入对方的账号 ,并点击 ` Start Chat ` 按钮,进入聊天页面。现在你可以在两个账号间进行聊天。
236+ 4 . 两台设备或者模拟器分别输入对方的账号 ,并点击 ` Start Chat ` 按钮,进入聊天页面。现在你可以在两个账号间进行聊天。
0 commit comments