HyphenateChatSDK 4.2.3
Instance Methods | Class Methods | Properties | List of all members
EMClient Class Reference

#import <EMClient.h>

Inheritance diagram for EMClient:

Instance Methods

(NSString *) - version
 
(void) - addDelegate:delegateQueue:
 
(void) - removeDelegate:
 
(EMError *_Nullable) - initializeSDKWithOptions:
 
(EMError *_Nullable) - registerWithUsername:password:
 
(void) - registerWithUsername:password:completion:
 
(EMError *_Nullable) - loginWithUsername:password:
 
(void) - loginWithUsername:password:completion:
 
(EMError *_Nullable) - loginWithUsername:token:
 
(void) - loginWithUsername:token:completion:
 
(EMError *_Nullable) - renewToken:
 
(void) - renewToken:completion:
 
(EMError *_Nullable) - logout:
 
(void) - logout:completion:
 
(EMError *_Nullable) - bindDeviceToken:
 
(void) - registerForRemoteNotificationsWithDeviceToken:completion:
 
(EMError *_Nullable) - uploadLogToServer
 
(void) - uploadDebugLogToServerWithCompletion:
 
(NSString *_Nullable) - getLogFilesPath:
 
(void) - getLogFilesPathWithCompletion:
 
(void) - log:
 
(void) - addLogDelegate:delegateQueue:
 
(void) - removeLogDelegate:
 
(void) - applicationDidEnterBackground:
 
(void) - applicationWillEnterForeground:
 
(void) - application:didReceiveRemoteNotification:
 

Class Methods

(instancetype _Nonnull) + sharedClient
 

Properties

NSString *_Nonnull version
 
NSString *_Nullable currentUsername
 
EMOptions *_Nonnull options
 
id< IEMChatManager > _Nullable chatManager
 
id< IEMChatroomManager > _Nullable roomManager
 
BOOL isAutoLogin
 
BOOL isLoggedIn
 
BOOL isConnected
 
NSString *_Nullable accessUserToken
 

Detailed Description

This class is the entry of the Chat SDK, which is responsible for management of modules like login, logout, and connection.

With this class, you can access other modules such as group [EMClient sharedClient].groupManager.

Method Documentation

◆ addDelegate:delegateQueue:

- (void) addDelegate: (id< EMClientDelegate >_Nonnull)  aDelegate
delegateQueue: (dispatch_queue_t _Nullable)  aQueue 

Adds a delegate.

Parameters
aDelegateThe delegate that you want to add.
aQueue(optional) The queue of calling delegate methods. If you want to run the app on the main thread, set this parameter as nil.

◆ addLogDelegate:delegateQueue:

- (void) addLogDelegate: (id< EMLogDelegate >_Nonnull)  aDelegate
delegateQueue: (addLog(delegate:queue:))  NS_SWIFT_NAME 

Adds the log callback delegate.

Parameters
aDelegateThe delegate that you want to add.
aQueueThe queue of calling delegate methods.

◆ application:didReceiveRemoteNotification:

- (void) application: (id _Nonnull)  application
didReceiveRemoteNotification: (NSDictionary *_Nullable)  userInfo 

Occurs when the device receives an APNs notification when your app is running in the foreground.

This event is specific to the iOS platform.

Parameters
applicationThe current application instance.
userInfoThe push content.

◆ applicationDidEnterBackground:

- (void) applicationDidEnterBackground: (id _Nonnull)  aApplication

Disconnects from the chat server when the app is switched to the background.

This method is specific to the iOS platform.

Parameters
aApplicationThe current application instance.

◆ applicationWillEnterForeground:

- (void) applicationWillEnterForeground: (id _Nonnull)  aApplication

Reconnects to the server when your app returns to the foreground.

This method is specific to the iOS platform.

Parameters
aApplicationThe current application instance.

◆ bindDeviceToken:

- (EMError *_Nullable) bindDeviceToken: (NSData *_Nonnull)  aDeviceToken

Binds the device token.

Device token binding is required to enable Apple Push Notification Service.

This is a synchronous method and blocks the current thread.

Parameters
aDeviceTokenThe device token to bind.

@Result If the binding succeeds, the SDK returns nil; otherwise, the SDK returns the description of the issue that causes the call to fail.

◆ getLogFilesPath:

- (NSString *_Nullable) getLogFilesPath: (EMError **_Nullable)  pError

Compresses the debug logs into a gzip archive (.gz).

You are strongly advised to delete this debug archive once it is no longer used.

This is a synchronous method and blocks the current thread.

Parameters
pErrorA description of the issue that caused this call to fail.
Returns
NSString The full file path of the debug archive.

◆ getLogFilesPathWithCompletion:

- (void) getLogFilesPathWithCompletion: (void(^)(NSString *_Nullable aPath, EMError *_Nullable aError))  aCompletionBlock

Compresses the debug logs into a gzip archive (.gz).

You are strongly advised to delete this debug archive once it is no longer used.

This is an asynchronous method.

Parameters
aCompletionBlockThe completion block, which contains the token and the error message if the method fails.

◆ initializeSDKWithOptions:

- (EMError *_Nullable) initializeSDKWithOptions: (EMOptions *_Nonnull)  aOptions

Initializes the SDK.

Parameters
aOptionsThe SDK options.

@Result A description of the issue that caused this call to fail.

◆ log:

- (void) log: (NSString *_Nonnull)  aLog

Outputs logs to a log file.

You can call this method after the SDK is initialized.

This is a synchronous method and blocks the current thread.

Parameters
aLogThe log information to output.

◆ loginWithUsername:password:

- (EMError *_Nullable) loginWithUsername: (NSString *_Nonnull)  aUsername
password: (NSString *_Nonnull)  aPassword 

Logs in to the chat server with a password.

This is a synchronous method and blocks the current thread.

It is recommended that you log in to the chat service with a token.

Parameters
aUsernameThe user ID. The maximum length is 64 characters. Ensure that you set this parameter. Supported characters include the 26 English letters (a-z), the ten numbers (0-9), the underscore (_), the hyphen (-), and the English period (.). This parameter is case insensitive, and upper-case letters are automatically changed to low-case ones. If you want to set this parameter as a regular expression, set it as ^[a-zA-Z0-9_-]+$.
aPasswordThe password. The maximum length is 64 characters. Ensure that you set this parameter.
Returns
If the login succeeds, the SDK returns nil; otherwise, the SDK returns the description of the issue that causes the call to fail.

◆ loginWithUsername:password:completion:

- (void) loginWithUsername: (NSString *_Nonnull)  aUsername
password: (NSString *_Nonnull)  aPassword
completion: (void(^)(NSString *_Nonnull aUsername, EMError *_Nullable aError))  aCompletionBlock 

Logs in to the chat server with a password.

This is an asynchronous method.

It is recommended that you log in to the chat service with a token.

Parameters
aUsernameThe user ID. The maximum length is 64 characters. Ensure that you set this parameter. Supported characters include the 26 English letters (a-z), the ten numbers (0-9), the underscore (_), the hyphen (-), and the English period (.). This parameter is case insensitive, and upper-case letters are automatically changed to low-case ones. If you want to set this parameter as a regular expression, set it as ^[a-zA-Z0-9_-]+$.
aPasswordThe password. The maximum length is 64 characters. Ensure that you set this parameter.
aCompletionBlockThe completion block, which contains the username and the error message if the method fails.

◆ loginWithUsername:token:

- (EMError *_Nullable) loginWithUsername: (NSString *_Nonnull)  aUsername
token: (NSString *_Nonnull)  aToken 

Logs in to the chat server with a token.

This method does not support automatic login.

This is a synchronous method and blocks the current thread.

Parameters
aUsernameThe user ID. The maximum length is 64 characters. Ensure that you set this parameter. Supported characters include the 26 English letters (a-z), the ten numbers (0-9), the underscore (_), the hyphen (-), and the English period (.). This parameter is case insensitive, and upper-case letters are automatically changed to low-case ones. If you want to set this parameter as a regular expression, set it as ^[a-zA-Z0-9_-]+$.
aTokenThe token for login to the chat server.
Returns
If the login succeeds, the SDK returns nil; otherwise, the SDK returns the description of the issue that causes the call to fail.

◆ loginWithUsername:token:completion:

- (void) loginWithUsername: (NSString *_Nonnull)  aUsername
token: (NSString *_Nonnull)  aToken
completion: (void(^)(NSString *_Nonnull aUsername, EMError *_Nullable aError))  aCompletionBlock 

Logs in to the chat server with a token.

This is an asynchronous method. This method supports automatic login.

Parameters
aUsernameThe user ID. The maximum length is 64 characters. Ensure that you set this parameter. Supported characters include the 26 English letters (a-z), the ten numbers (0-9), the underscore (_), the hyphen (-), and the English period (.). This parameter is case insensitive, and upper-case letters are automatically changed to low-case ones. If you want to set this parameter as a regular expression, set it as ^[a-zA-Z0-9_-]+$.
aTokenThe token for login to the chat server.
aCompletionBlockThe completion block, which contains the user ID and the error message if the method fails.

◆ logout:

- (EMError *_Nullable) logout: (BOOL)  aIsUnbindDeviceToken

Logs out of the chat server.

This is a synchronous method and blocks the current thread.

Parameters
aIsUnbindDeviceTokenWhether to unbind the user ID from the device.
  • Yes:Yes. Once the user ID is unbound from the device, the user device stops receiving push notifications from the Apple Push Notifications service. If the unbinding fails, the SDK returns an error that includes the reason for the failure.
  • NO:No.
Returns
A description of the issue that caused this call to fail.

◆ logout:completion:

- (void) logout: (BOOL)  aIsUnbindDeviceToken
completion: (void(^)(EMError *_Nullable aError))  aCompletionBlock 

Logs out of the chat server.

This is an asynchronous method.

Parameters
aIsUnbindDeviceTokenWhether to unbind the user ID from the device.
  • Yes:Yes. Once the user ID is unbound from the device, the user device stops receiving push notifications from the Apple Push Notifications service. If the unbinding fails, the SDK returns an error that includes the reason for the failure.
  • NO:No.
aCompletionBlockThe completion block, which contains the token and the error message if the method fails.

◆ registerForRemoteNotificationsWithDeviceToken:completion:

- (void) registerForRemoteNotificationsWithDeviceToken: (NSData *_Nonnull)  aDeviceToken
completion: (void(^)(EMError *_Nullable aError))  aCompletionBlock 

Registers the device token.

Device token binding is required to enable Apple push notification service.

This is an asynchronous method.

Parameters
aDeviceTokenThe device token to bind.
aCompletionBlockThe completion block, which contains the error message if the method fails.

◆ registerWithUsername:password:

- (EMError *_Nullable) registerWithUsername: (NSString *_Nonnull)  aUsername
password: (NSString *_Nonnull)  aPassword 

Registers a new user.

This method is not recommended and you are advised to call the RESTful API to register a new user.

After you call initializeSDKWithOptions and register your app in the console, the app has access to all the features registered inside your chat network. You add and remove users inside your chat network; depending on how you implement your app, you control the people each user can see inside your network.

This is a synchronous method and blocks the current thread. To ensure the registration reliability, we recommend using the RESTful API to register new chat users.

Parameters
aUsernameThe user ID. The maximum length is 64 characters. Ensure that you set this parameter. Supported characters include the 26 English letters (a-z), the ten numbers (0-9), the underscore (_), the hyphen (-), and the English period (.). This parameter is case insensitive, and upper-case letters are automatically changed to low-case ones. If you want to set this parameter as a regular expression, set it as ^[a-zA-Z0-9_-]+$.
aPasswordThe password. The maximum length is 64 characters. Ensure that you set this parameter.
Returns
A description of the issue that caused this call to fail.

◆ registerWithUsername:password:completion:

- (void) registerWithUsername: (NSString *_Nonnull)  aUsername
password: (NSString *_Nonnull)  aPassword
completion: (void(^)(NSString *_Nonnull aUsername, EMError *_Nullable aError))  aCompletionBlock 

Registers a new user.

This is an asynchronous method. This method is not recommended and you are advised to call the RESTful API to register a user.

To ensure registration reliability, we recommend using the RESTful API to register new chat users.

Parameters
aUsernameThe user ID. The maximum length is 64 characters. Ensure that you set this parameter. Supported characters include the 26 English letters (a-z), the ten numbers (0-9), the underscore (_), the hyphen (-), and the English period (.). This parameter is case insensitive, and upper-case letters are automatically changed to low-case ones. If you want to set this parameter as a regular expression, set it as ^[a-zA-Z0-9_-]+$.
aPasswordThe password. The maximum length is 64 characters. Ensure that you set this parameter.
aCompletionBlockThe completion block, which contains the username and the error message if the method fails.

◆ removeDelegate:

- (void) removeDelegate: (id _Nonnull)  aDelegate

Removes a delegate.

Parameters
aDelegateThe delegate that you want to remove.

◆ removeLogDelegate:

- (void) removeLogDelegate: (removeLog(delegate:))  NS_SWIFT_NAME

Removes the log callback delegate.

Parameters
aDelegateThe log callback delegate that you want to delete.

◆ renewToken:

- (EMError *_Nullable) renewToken: (NSString *_Nonnull)  newToken

Renews the user token when the current token expires.

If you are logged in with an Chat user token and you are notified via the ClientDelegate callback that the token is about to expire, you can call this method to renew the token to prevent unknown issues caused by an invalid token.

This is a synchronous method and blocks the current thread.

Parameters
newTokenThe new Chat token。
Returns
The result which contains the description of the cause to the failure if call fails.

◆ renewToken:completion:

- (void) renewToken: (NSString *_Nonnull)  newToken
completion: (void(^)(EMError *_Nullable aError))  aCompletionBlock 

Renews the user token when the current token expires.

If you are logged in with an Chat user token and you are notified via the ClientDelegate callback that the token is about to expire, you can call this method to renew the token to prevent unknown issues caused by an invalid token.

This is an asynchronous method.

Parameters
newTokenThe new Chat token。
Returns
The result which contains the description of the cause to the failure if call fails.

◆ sharedClient

+ (instancetype _Nonnull) sharedClient

Creates a Client instance. The Client class is the entry to the Chat SDK. You need to call this method to create a Client instance before calling any other methods.

◆ uploadDebugLogToServerWithCompletion:

- (void) uploadDebugLogToServerWithCompletion: (void(^)(EMError *_Nullable aError))  aCompletionBlock

Uploads the debug log to the chat server.

Parameters
aCompletionBlockThe completion block, which contains the token and the error message if the method fails.

◆ uploadLogToServer

- (EMError *_Nullable) uploadLogToServer

Uploads the log to the chat server.

The information in the debug log is used by our engineers to fix errors and improve system performance.

This is a synchronous method and blocks the current thread.

Returns
If the upload succeeds, the SDK returns nil; otherwise, the SDK returns the description of the issue that causes the call to fail.

◆ version

- (NSString *) version

The SDK version number.

Property Documentation

◆ accessUserToken

- (NSString* _Nullable) accessUserToken
readnonatomicassign

The token used by the current user to access the chat server.

The user needs to use the user ID and password for the first login. If the login succeeds, a token is returned and the user can use it for subsequent logins.

◆ chatManager

- (id<IEMChatManager> _Nullable) chatManager
readnonatomicstrong

The chat manager module.

◆ currentUsername

- (NSString* _Nullable) currentUsername
readnonatomicstrong

The ID of the user currently logged in to your chat app.

◆ isAutoLogin

- (BOOL) isAutoLogin
readnonatomicassign

Whether to allow a user to automatically log in to the chat server with the user ID used last time.

  • YES:Yes.
  • NO:No.

    If the login fails, for example, because of an incorrect password or a deactivated user account, this parameter will be reset to NO. In this case, you need to set it back to YES to allow automatic login.

◆ isConnected

- (BOOL) isConnected
readnonatomicassign

Whether the SDK is connected to the chat server.

  • YES:Yes.
  • NO:No.

◆ isLoggedIn

- (BOOL) isLoggedIn
readnonatomicassign

Whether the current user is already logged in to the chat server.

  • YES:The current user is already logged in.
  • NO:The current user is not logged in.

◆ options

- (EMOptions* _Nonnull) options
readnonatomicstrong

The SDK setting options. For example, whether to use HTTPs by default.

◆ roomManager

- (id<IEMChatroomManager> _Nullable) roomManager
readnonatomicstrong

The chat room manager module.

◆ version

- (NSString* _Nonnull) version
readnonatomicstrong

The SDK version number.


The documentation for this class was generated from the following file: