Skip to content

Commit 5caa040

Browse files
authored
Merge pull request #1364 from lixm1988/doc-v2
update iOS login code
2 parents ecd32b6 + a7e7b01 commit 5caa040

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

docs/document/ios/login.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010

1111
示例代码如下所示:
1212

13-
```objectivec
13+
```swift
1414
// 异步方法
15-
[[EMClient sharedClient] registerWithUsername:@"username"
16-
password:@"your password"
17-
completion:^(NSString *aUsername, EMError *aError) {
18-
}];
15+
EMClient.shared.register(withUsername: "userId", password: "your password") { userId, e in
16+
17+
}
1918
```
2019

2120
- 授权注册:通过环信提供的 REST API 注册环信用户账号,注册后保存到你的服务器或返给客户端。要使用授权注册,你需要在[环信即时通讯云控制台](https://console.easemob.com/user/login)**即时通讯** > **服务概览****设置**区域,将**用户注册模式**设置为**授权注册**。相关的 REST API 介绍,详见[授权注册单个用户](/document/server-side/account_system.html#授权注册单个用户)[批量授权注册用户](/document/server-side/account_system.html#批量授权注册用户)的接口介绍。
@@ -40,17 +39,18 @@ EMClient.shared().login(withUsername: "userId", token: "token") { userId, err in
4039

4140
1. **用户 ID + 密码** 是传统的登录方式。用户名和密码均由你的终端用户自行决定,密码需要符合密码规则要求。
4241

43-
```objectivec
42+
```swift
4443
//SDK 初始化 `EMOptions` 时可以传入 `loginExtensionInfo` 属性投递给被踢下线的设备。该属性需要开启多设备登录的情况下才能生效。
45-
EMOptions *options = [EMOptions optionsWithAppkey:<#AppKey#>];
46-
options.loginExtensionInfo = @"you was kicked out by other device";
47-
[EMClient.sharedClient initializeSDKWithOptions:options];
48-
// 异步方法
49-
[[EMClient sharedClient] loginWithUsername:@"username"
50-
password:@"your password"
51-
completion:^(NSString *aUsername, EMError *aError) {
52-
53-
}];
44+
let options = EMOptions(appkey: <#Appkey#>)
45+
options.loginExtensionInfo = "you was kicked out by other device"
46+
EMClient.shared().initializeSDK(with: options)
47+
EMClient.shared.login(withUsername: "userId", password: "your password") { userId, e in
48+
if e == nil {
49+
print("login success")
50+
} else {
51+
print("login error:\(e?.errorDescription ?? "")")
52+
}
53+
}
5454
```
5555

5656
## 自动登录

0 commit comments

Comments
 (0)