MLIMClient Class Reference

Inherits from NSObject
Declared in MLIMClient.h

Overview

A client representation of a user connection.

Properties

  status

The client status

@property (nonatomic, readonly) MLIMClientStatus status

Declared In

MLIMClient.h

  delegate

The delegate object for the client. You can implement methods defined in protocol MLIMClientDelegate to handle client connection events, messages, friend online status change events.

@property (nullable, nonatomic, weak) id<MLIMClientDelegate> delegate

Declared In

MLIMClient.h

  currentUser

The current logged in user of this client.

@property (nullable, nonatomic, readonly) MLIMUser *currentUser

Declared In

MLIMClient.h

  currentPassenger

The current logged in passenger.

@property (nullable, nonatomic, readonly) MLIMPassenger *currentPassenger

Declared In

MLIMClient.h

Creating IM client

+ clientWithConfiguration:

Creates an MLIMClient object using the config.

+ (instancetype)clientWithConfiguration:(MLIMClientConfiguration *)config

Parameters

config

the client configuration

Return Value

a new instance of MLIMClient

Discussion

Note: The property appId and clientKey must not be empty.

Declared In

MLIMClient.h

+ clientWithAppId:clientKey:installationId:

Creates an MLIMClient object using appId, clientKey and installationId.

+ (instancetype)clientWithAppId:(NSString *)appId clientKey:(NSString *)clientKey installationId:(nullable NSString *)installationId

Parameters

appId

The MaxLeap applicationId.

clientKey

The MaxLeap application clientKey

installationId

The installationId for the [MLInstallation currentInstallation].

Return Value

A new instance of MLIMClient

Declared In

MLIMClient.h

Login/Logout

– loginWithUserId:completion:

Login or signup with a user id, without password. UserId must match [a-zA-Z0-9_\-]+.

- (void)loginWithUserId:(NSString *)uid completion:(MLIMBooleanResultBlock)block

Parameters

uid

The user id

block

The block to execute after login completion. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Declared In

MLIMClient.h

– loginWithUsername:password:completion:

Login with username and password. Only the user registered in MaxLeap can login.

- (void)loginWithUsername:(NSString *)username password:(NSString *)password completion:(MLIMBooleanResultBlock)block

Parameters

username

The username of a MLUser

password

The password of a MLUser

block

The block to execute after login completion. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Declared In

MLIMClient.h

– loginWithPhoneNumber:smsCode:completion:

Login with phone number and sms code. The sms code can be requested via calling api [MLUser requestLoginSmsCodeWithPhoneNumber:block:].

- (void)loginWithPhoneNumber:(NSString *)phoneNumber smsCode:(NSString *)smsCode completion:(MLIMBooleanResultBlock)block

Parameters

phoneNumber

The phone number of a MLUser

smsCode

The sms code user received

block

The block to execute after login completion. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Declared In

MLIMClient.h

– loginWithThirdPartyOAuth:completion:

Login with oauth info from third party like facebook.

- (void)loginWithThirdPartyOAuth:(NSDictionary *)OAuth completion:(MLIMBooleanResultBlock)block

Parameters

OAuth

The oauth info, must contain the user id and accessToken

block

The block to execute after login completion. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Discussion

The oauth data is stored in [[MLUser currentUser]](../Classes/MLUser.html#//api/name/currentUser).oauthData. It has the following structure: {“platformName”:{“id”:“”, “access_token”:“”, …}, …}

Declared In

MLIMClient.h

– loginPassenger:completion:

Login a passenger. If the passenger is not exist, a new passenger will be created.

- (void)loginPassenger:(MLIMPassenger *)passenger completion:(MLIMBooleanResultBlock)block

Parameters

passenger

The passenger object

block

The block to execute after login completion. It should have the following argument signature: (BOOL succeeded, NSError *error)

Discussion

When creating a passenger, passenger.pid will be used if it exists, otherwise a new pid will be generated. Setting custom fileds on the passenger is helpful to update the attributes of the passenger. But the values must be JSON Types. eg: passenger[field1] = @{@"a": @3}; After login success, the passenger id canbe access using passenger.pid.

Declared In

MLIMClient.h

– logoutWithCompletion:

Delete config.installId from current user and then disconnect the connection.

- (void)logoutWithCompletion:(MLIMBooleanResultBlock)block

Parameters

block

The block to execute after login completion. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Discussion

Note: After logout, this device cannot receive any furture messages send to the user, include offline push notifications.

Declared In

MLIMClient.h

– deleteInstallIdCompletion:

Delete config.installId from current user to prevent the user receiving offline push notifications.

- (void)deleteInstallIdCompletion:(MLIMBooleanResultBlock)block

Parameters

block

The block to execute after request completion. It should have the following argument signature: (BOOL succeeded, NSError *error)

Declared In

MLIMClient.h

Pause/Resume

– pause

Disconnect the connection, do not logout. User will be offline and receive offline push notifications.

- (void)pause

Declared In

MLIMClient.h

– resume

Recover the connection, different from login. User will be online and receive realtime messages.

- (void)resume

Declared In

MLIMClient.h

Sending instant messages

– sendMessage:completion:

Send messages.

- (void)sendMessage:(MLIMMessage *)message completion:(nullable MLIMBooleanResultBlock)block

Parameters

message

The message to send, should specify a receiver.

block

The block to execute after message sending. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Discussion

Note: The message should specify a receiver.

Declared In

MLIMClient.h

– sendMessage:progress:completion:

Send message

- (void)sendMessage:(MLIMMessage *)message progress:(nullable MLIMProgressBlock)progress completion:(nullable MLIMBooleanResultBlock)block

Parameters

message

The message to send, should specify a receiver.

progress

A block to notify attachment uploading progress. The block should have the following argument signature: (int percentDone)

block

The block to execute after message sending. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Declared In

MLIMClient.h

– sendMessage:toFriend:completion:

Send message to friend.

- (void)sendMessage:(MLIMMessage *)message toFriend:(NSString *)uid completion:(MLIMBooleanResultBlock)block

Parameters

message

The message to send, message.receiver will be mutated.

uid

Friend’s userId.

block

Block to execute after message send completion. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Declared In

MLIMClient.h

– sendMessage:toStranger:completion:

Send message to a stranger.

- (void)sendMessage:(MLIMMessage *)message toStranger:(NSString *)uid completion:(MLIMBooleanResultBlock)block

Parameters

message

The message to send, message.receiver will be mutated.

uid

The stranger’s userId.

block

Block to execute after message send completion. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Declared In

MLIMClient.h

– sendMessage:toGroup:completion:

Send message to group.

- (void)sendMessage:(MLIMMessage *)message toGroup:(NSString *)gid completion:(MLIMBooleanResultBlock)block

Parameters

message

The message to send, message.receiver will be mutated

gid

The target group Id.

block

The block should have the following signature: (BOOL succeeded, NSError *error)

Declared In

MLIMClient.h

– sendMessage:toRoom:completion:

Send message to room.

- (void)sendMessage:(MLIMMessage *)message toRoom:(NSString *)rid completion:(MLIMBooleanResultBlock)block

Parameters

message

The message to send. message.receiver will be mutated

rid

The target roomId.

block

The block should have the following signature: (BOOL succeeded, NSError *error)

Declared In

MLIMClient.h

Sending System Messages

– sendSystemMessage:completion:

Sending a system message via restful api, but the message will be received via socket.

- (void)sendSystemMessage:(MLIMMessage *)message completion:(nullable MLIMBooleanResultBlock)block

Parameters

message

A system message

block

The block should have the following signature: (BOOL succeded, NSError *error)

Declared In

MLIMClient.h

– sendSystemMessage:progress:completion:

Sending a system message via restful api, but the message will be received via socket.

- (void)sendSystemMessage:(MLIMMessage *)message progress:(nullable MLIMProgressBlock)progress completion:(nullable MLIMBooleanResultBlock)block

Parameters

message

A system message

progress

A block to notify attachment uploading progress. The block should have the following argument signature: (int percentDone)

block

The block should have the following signature: (BOOL succeded, NSError *error)

Declared In

MLIMClient.h

– sendSystemMessageToAllUsers:completion:

Send system message to all users. Only online users can recieve the message.

- (void)sendSystemMessageToAllUsers:(MLIMMessage *)message completion:(MLIMBooleanResultBlock)block

Parameters

message

message to send.

block

A block to notify the result.

Declared In

MLIMClient.h

– sendSystemMessage:toUser:completion:

Send system message to single user. If the user is offline, a push notification will be send.

- (void)sendSystemMessage:(MLIMMessage *)message toUser:(NSString *)uid completion:(MLIMBooleanResultBlock)block

Parameters

message

the message

uid

the user to send

block

A block to notify the result.

Declared In

MLIMClient.h

– sendSystemMessage:toGroup:completion:

Send system message to group. The offline users in the group will recieve push notifications.

- (void)sendSystemMessage:(MLIMMessage *)message toGroup:(NSString *)gid completion:(MLIMBooleanResultBlock)block

Parameters

message

the message

gid

the target group id

block

A block to notify the result.

Declared In

MLIMClient.h

– sendSystemMessage:toRoom:completion:

Send system message to room. No offline notifications support.

- (void)sendSystemMessage:(MLIMMessage *)message toRoom:(NSString *)rid completion:(MLIMBooleanResultBlock)block

Parameters

message

the message

rid

the target room id

block

A block to notify the result.

Declared In

MLIMClient.h