Development Manual

Last Updated: Jan 25th, 2016

SDK introduction

HTMessage SDK provides an integrated development structure for clients to help them develop their own IM applications. HTMessage SDK composes of two parts:

  • HTMessage SDK Framework, SDK kernel

  • Demo of a High Analogous WeChat by using HTMessage SDK

HTClient: Is the entrance of the SDK, mainly to complete the login, exit, connection management, and messaging functions. Access to other modules

HTMessageManager:Managing message storage and receiving messages

HTConversationManager:Managing the conversation list

HTGroupManager:Managing group related operations

SDK integration

From the official website to download the HTMessageSDKFramework into the project

Add dependency libraries to Build Phases → Link Binary With Libraries , including the dependencies used in Demo


  • SDK does not support bitcode, set NO to Build Settings - Linking - Enable Bitcode
  • After the above steps are completed, the compiler works. If there is no error, Congratulations, integrated SDK success, you can proceed to the next step.


SDK rapid integration

1 Initialize SDK

  • Header file

    #import 
  • Initialize SDK

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
      {
          ...
          [[HTClient sharedInstance] initializeSDK];
          ...
          return YES;
      }
  • Login HTMessage

    [[HTClient sharedInstance] loginWithUsername:@"10000" password:@"1234" completion:^(BOOL result) {
          if (result) {
              NSLog(@"Landing success");
          }else{
              NSLog(@"Landing success");
          }
      }];
  • Exit HTMessage

    [[HTClient sharedInstance] logout];
  • Single chat page

    HTChatViewController *HTChatVC = [[HTChatViewController alloc] initWithConversationChatter:@"100001" conversationType:@"1"];
  • Create Group

    HTGroup * group = [HTGroup new];
      gModel.groupName = @"Group name";
      gModel.groupDescription = @"Group description";
      gModel.groupAvatar = @"Group portrait";
      [[HTClient sharedInstance].groupManager createGroupWithGroupModel:group withMembers:members success:^(HTGroup *aGroup) {
    
      } failure:^(NSError *error) {
    
      }];
  • Group chat interface

    HTChatViewController *HTChatVC = [[HTChatViewController alloc] initWithConversationChatter:@"groupId" conversationType:@"1"];

news

  • Text message

    HTMessage *message = [HTMessageSDKHelper sendTextMessage:@"Text content" to:@"Send object" messageType:@"Chat type" messageExt:@"Expand content"];
      messageType:
                   @"1" Single chat message
                   @"2" Group chat message
      messageExt:
                   @{}  Expand the content of the dictionary type, can pass nil
  • Picture message

    HTMessage *message = [HTMessageSDKHelper sendImageMessageWithImage:@"Picture UIImage object" to:@"Send object" messageType:@"Chat type" messageExt:@"Expand content"];
  • Voice message

    HTMessage *message = [HTMessageSDKHelper sendAudioMessageWithLocalPath:@"AMR format voice file path" duration:@"Speech duration" to:@"Send object" messageType:@"Chat type" messageExt:@"Expand content"];
  • Video message

    HTMessage * message = [HTMessageSDKHelper sendVideoMessageWithURL:@"Mp4 format video file path" to:@"Send object" messageType:@"Chat type" andSSImage:@"Video screenshot UIImage object" andVideoTime:@"Video length" messageExt:@"Extended field"];
  • Location message

    HTMessage * message = [HTMessageSDKHelper sendLocationMessageWithLatitude:@"dimension" longitude:@"longitude" address:@"Address Details" to:@"Chat object" messageType:@"Chat type" andSSImage:@"Screenshot UIImage object" messageExt:@"Extended field"];
  • send message

    [[HTClient sharedInstance] sendMessage:message completion:^(HTMessage *message, NSError *error) {
          if (error) {
              NSLog(@"error = %@",error);
          }
      }];
  • receive messages

    1、Registered agent"HTMessageDelegate"
      2、Implementation method
    
       General message received
      - (void)didReceiveMessages:(NSArray *)aMessages;
    
       Receive transmitted message
      - (void)didReceiveCMDMessage:(NSArray *)aCMDMessages;

Intergration preparation

  1. Add htmessage.jar to libs

  2. Add dependencies in gradle:

dependencies {
   
    compile 'com.anupcowkur:reservoir:3.1.0'
    compile 'com.squareup.okhttp3:okhttp:3.3.1' 
    compile 'io.reactivex:rxandroid:1.2.1'
    compile 'io.reactivex:rxjava:1.1.6'
    compile 'com.android.support:support-v4:25.0.0'
    compile 'com.segment.backo:backo:1.0.0'
    compile 'com.jaredrummler:android-processes:1.0.9'
    compile 'com.alibaba:fastjson:1.2.24'
    compile 'com.alibaba:fastjson:1.1.56.android'
}

SDK initialization

1.Add the code to initialize SDK in the Application class:

@Override
public void onCreate() {
    ......
    
    HTClient.init(applicationContext);
    
    ......
}

IM registration

HTClient.getInstance().register(username, password, new HTClient.HTCallBack() {
//Asynchronous callback registration results
    @Override
    public void onSuccess() {
         //successful registration
    }

    @Override
    public void onError() {
         //registration failed
     }
});

IM server login

HTClient.getInstance().login(username, password, new HTClient.HTCallBack() {
//Asynchronous callback login results
    @Override
    public void onSuccess() {
         //Login success
    }

    @Override
    public void onError() {
         //Login failed
     }
});

IM server logout

HTClient.getInstance().logout(new HTClient.HTCallBack() {
 //Call-backs
            @Override
            public void onSuccess() {
 
                 //Exit success
            }

            @Override
            public void onError() {
                 //Exit failure
            }
        });

Send message

HTClient.getInstance().chatManager().sendMessage(htMessage, new HTChatManager.HTMessageCallBack() {
//Call-backs @Override
        public void onProgress(  ) {
            //Send in

        }

        @Override
        public void onSuccess(   ) {
            //Send success
        }

        @Override
        public void onFailure(   ) {
            //fail in send
        }

    });


}

Receive message listener

private HTClient.MessageLisenter messageLisenter = new HTClient.MessageLisenter() {
    @Override
    public void onHTMessage(HTMessage htMessage) {
       //Received general information - text, voice, image, video, location, etc.
    }

    @Override
    public void onCMDMessgae(CmdMessage cmdMessage) {

       //Receive transmitted message
    }
};

Register monitor

HTClient.getInstance().setMessageLisenter(messageLisenter);

Get a group entity

HTGroup htgroup=GroupManager.getInstance().getGroup(groupId);

Create Group

GroupManager.getInstance().createGroup(members, groupName, groupDsc,groupImage, new GroupManager.CallBack() {
    @Override
    public void onSuccess(String data) {
         
        }
    @Override
    public void onFailure() {
         
    }
});

Group kicking

HTClient.getInstance().groupManager().deleteMember(groupId, memberUserId,memberUserNick, new GroupManager.CallBack() {
        @Override
        public void onSuccess(String data) {
           //Success
        }

        @Override
        public void onFailure() {
            //fail 
        }
    });
}

Group delete group

HTClient.getInstance().groupManager().deleteGroup(groupId, new GroupManager.CallBack() {
    @Override
    public void onSuccess(String data) {
        //
    }

    @Override
    public void onFailure() {
        //
    }
});

Group member exit group

HTClient.getInstance().groupManager().leaveGroup(groupId, HTApp.getInstance().getUserJson().getString(HTConstant.JSON_KEY_NICK), new GroupManager.CallBack() {
    @Override
    public void onSuccess(String data) {
        
    }

    @Override
    public void onFailure() {
         
    }
});

Group of people

GroupManager.getInstance().addMembers(map, groupId, new GroupManager.CallBack() {
            @Override
            public void onSuccess(String data) {
                
            }

            @Override
            public void onFailure() {
                
            }
        });
    }

Update group data

GroupManager.getInstance().updateGroupInfo(groupId, groupNewName, groupDesc, imageUrl, new GroupManager.CallBack() {
    @Override
    public void onSuccess(String data) {
       
    }

    @Override
    public void onFailure() {
        
    }
});

We Are Only A Phone Call Away+86 0551-66771882

Choose Colour