Agora RTC Objective-C API Reference Refactor

Instance Methods | Class Methods
AgoraRtmClientKit Class Reference

Inherits <NSObject>.

## Instance Methods
(instancetype _Nullable) | - initWithConfig:delegate:error:
(void) | - loginByToken:completion:
(void) | - logout:
(AgoraRtmStorage *_Nullable) | - getStorage
(AgoraRtmLock *_Nullable) | - getLock
(AgoraRtmPresence *_Nullable) | - getPresence
(AgoraRtmHistory *_Nullable) | - getHistory
(void) | - renewToken:completion:
(void) | - subscribeWithChannel:option:completion:
(void) | - unsubscribeWithChannel:completion:
(void) | - publish:message:option:completion:
(void) | - publish:data:option:completion:
(void) | - addDelegate:
(void) | - removeDelegate:
(AgoraRtmStreamChannel *_Nullable) | - createStreamChannel:error:
(AgoraRtmErrorCode) | - destroy

## Class Methods
(NSString *_Nullable) | + getErrorReason:
(NSString *_Nonnull) | + getVersion

## Detailed Description

The AgoraRtmClientKit class.

This class provides the main methods that can be invoked by your app.

AgoraRtmClientKit is the basic interface class of the Agora RTM SDK. Creating an AgoraRtmClientKit object and then calling the methods of this object enables you to use Agora RTM SDK's functional

## Method Documentation

## ◆ NS_UNAVAILABLE

- (instancetype _Nullable) NS_UNAVAILABLE |  |  |

## ◆ initWithConfig:delegate:error:

- (instancetype _Nullable) initWithConfig: |  | (AgoraRtmClientConfig *_Nonnull) | config
delegate: |  | (id< AgoraRtmClientDelegate > _Nullable) | delegate
error: |  | (NSError **) | error

Initializes the rtm client instance.

Parameters

  config | The configurations for RTM Client.
  delegate | The callbacks handler.
  error | When get nil instance, get error info from error.

Returns
  - nil: initialize rtm client failed, and the error information can be retrievd via the `error` parameter.
  - not nil: initialize rtm client success.

## ◆ loginByToken:completion:

- (void) loginByToken: |  | (NSString *_Nullable) | token
completion: |  | (AgoraRtmOperationBlock _Nullable) | completionBlock

Login the Agora RTM service.

Parameters

  token | Token used to login RTM service.
  completionBlock | The operation result will be notified by completionBlock, if operation success，will given a not nil response and nil errorInfo，if operation failed，will given a nil response and not nil errorInfo.

## ◆ logout:

- (void) logout: |  | (AgoraRtmOperationBlock _Nullable) | completionBlock |

Logout the Agora RTM service. Be noticed that this method will break the rtm service includeing storage/lock/presence.

Parameters

  completionBlock | The operation result will be notified by completionBlock, if operation success，will given a not nil response and nil errorInfo，if operation failed，will given a nil response and not nil errorInfo.

## ◆ getStorage

- (AgoraRtmStorage* _Nullable) getStorage |  |  |

Get the storage instance.

Returns
  - return nil if error occured

## ◆ getLock

- (AgoraRtmLock* _Nullable) getLock |  |  |

Get the lock instance.

Returns
  - return nil if error occured

## ◆ getPresence

- (AgoraRtmPresence* _Nullable) getPresence |  |  |

Get the presence instance.

Returns
  - return nil if error occured

## ◆ getHistory

- (AgoraRtmHistory* _Nullable) getHistory |  |  |

Get the history instance.

Returns
  - return NULL if error occurred

## ◆ renewToken:completion:

- (void) renewToken: |  | (NSString *_Nonnull) | token
completion: |  | (AgoraRtmOperationBlock _Nullable) | completionBlock

Renews the token. Once a token is enabled and used, it expires after a certain period of time. You should generate a new token on your server, call this method to renew it.

Parameters

  token | Token used renew.
  completionBlock | The operation result will be notified by completionBlock, if operation success，will given a not nil response and nil errorInfo，if operation failed，will given a nil response and not nil errorInfo.

## ◆ subscribeWithChannel:option:completion:

- (void) subscribeWithChannel: |  | (NSString *_Nonnull) | channelName
option: |  | (AgoraRtmSubscribeOptions *_Nullable) | subscribeOption
completion: |  | (AgoraRtmOperationBlock _Nullable) | completionBlock

Subscribe a channel.

Parameters

  channelName | The name of the channel.
  subscribeOption | The options of subscribe the channel.
  completionBlock | The operation result will be notified by completionBlock, if operation success，will given a not nil response and nil errorInfo，if operation failed，will given a nil response and not nil errorInfo.

## ◆ unsubscribeWithChannel:completion:

- (void) unsubscribeWithChannel: |  | (NSString *_Nonnull) | channelName
completion: |  | (AgoraRtmOperationBlock _Nullable) | completionBlock

Unsubscribe a channel.

Parameters

  channelName | The name of the channel.
  completionBlock | The operation result will be notified by completionBlock, if operation success，will given a not nil response and nil errorInfo，if operation failed，will given a nil response and not nil errorInfo.

## ◆ publish:message:option:completion:

- (void) publish: |  | (NSString *_Nonnull) | channelName
message: |  | (NSString *_Nonnull) | message
option: |  | (AgoraRtmPublishOptions *_Nullable) | publishOption
completion: |  | (AgoraRtmOperationBlock _Nullable) | completionBlock

Publish a message in the channel.

Parameters

  channelName | The name of the channel.
  message | The content of the string message.
  publishOption | The option of the message.
  completionBlock | The operation result will be notified by completionBlock, if operation success，will given a not nil response and nil errorInfo，if operation failed，will given a nil response and not nil errorInfo.

## ◆ publish:data:option:completion:

- (void) publish: |  | (NSString *_Nonnull) | channelName
data: |  | (NSData *_Nonnull) | data
option: |  | (AgoraRtmPublishOptions *_Nullable) | publishOption
completion: |  | (AgoraRtmOperationBlock _Nullable) | completionBlock

Publish a message in the channel.

Parameters

  channelName | The name of the channel.
  data | The content of the raw message.
  publishOption | The option of the message.
  completionBlock | The operation result will be notified by completionBlock, if operation success，will given a not nil response and nil errorInfo，if operation failed，will given a nil response and not nil errorInfo.

## ◆ addDelegate:

- (void) addDelegate: |  | (id< AgoraRtmClientDelegate > _Nonnull) | delegate |

add more delegate instance.

Parameters

  delegate | The name of the channel.

## ◆ removeDelegate:

- (void) removeDelegate: |  | (id< AgoraRtmClientDelegate > _Nonnull) | delegate |

remove delegate instance.

Parameters

  delegate | The name of the channel.

## ◆ getErrorReason:

+ (NSString* _Nullable) getErrorReason: |  | (AgoraRtmErrorCode) | errorCode |

Convert error code to error string.

Parameters

  errorCode | Received error code

Returns
  The error reason

## ◆ getVersion

+ (NSString * _Nonnull) getVersion |  |  |

Get the version info of the AgoraRtmKit.

Returns
  The version info of the AgoraRtmKit.

## ◆ createStreamChannel:error:

- (AgoraRtmStreamChannel * _Nullable) createStreamChannel: |  | (NSString *_Nonnull) | channelName
error: |  | (NSError **) | error

create a stream channel instance.

Parameters

  channelName | The Name of the channel.
  error | When get nil instance, get error info from error.

Returns
  - nil: create stream channel failed，and the error information can be retrievd via the `error` parameter.
  - not nil: create stream channel success.

## ◆ destroy

- (AgoraRtmErrorCode) destroy |  |  |

destroy the rtm client instance.

Returns
  - AgoraRtmErrorOk: Success.
  - other: Failure.