The Hyphenate SDK for iOS is available on CocoaPods. CocoaPods is an open source dependency manager for Cocoa projects.
1. If you have not installed CocoaPods tool yet, please check out CocoaPods Getting Started for more detail.
2. Create a file named Podfile in the root directory of the Xcode project, and add the following line to the Podfile.
# Hyphenate iOS lite SDK
pod 'HyphenateLite'
# Hyphenate iOS SDK (Support real-time Voice & Video Calling features)
pod 'Hyphenate'
3. Open the Terminal, navigate to the directory that contains the Podfile, and run the following command.
pod install
1. Download Hyphenate SDK.
2. Import the SDK to your own project. For details, see Install the Hyphenate SDK.
1. If CocoaPods is used, you need to import the SDK header file.
// Hyphenate iOS lite SDK
#import <HyphenateLite/EMSDK.h>
// Hyphenate iOS SDK (Support real-time Voice & Video Calling features)
#import <Hyphenate/EMSDKFull.h>
2. Implementation in AppDelegate.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//AppKey: the registered AppKey on Hyphenate console
//apnsCertName: the name of APNs certificate (no need to add suffix) on Hyphenate console
EMOptions *options = [EMOptions optionsWithAppkey:@"douser#istore"];
options.apnsCertName = @"istore_dev";
[[EMClient sharedClient] initializeSDKWithOptions:options];
return YES;
}
// The APP enters background
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[EMClient sharedClient] applicationDidEnterBackground:application];
}
// The APP enters foreground
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[[EMClient sharedClient] applicationWillEnterForeground:application];
}
Call the login API.
[[EMClient sharedClient] loginWithUsername:@"8001"
password:@"111111"
completion:^(NSString *aUsername, EMError *aError) {
if (!aError) {
NSLog(@"Login successful");
} else {
NSLog(@"Login failed");
}
}];
Option 1: Download Hyphenate SDK and Import the EaseUI directory.
Option 2: Download the EaseUI source code and import it to your project.
https://github.com/easemob/easeui_ios/tree/sdk3.x/EaseUI/EaseUI
//Hyphenate ID: @"8001"
//Conversation type: EMConversationTypeChat
EaseMessageViewController *chatController = [[EaseMessageViewController alloc] initWithConversationChatter:@"8001" conversationType:EMConversationTypeChat];
For more information about one-to-one chat, see Messaging.
Prerequisite: You've completed the previous steps of integrating the one-to-one chat function.
EMError *error = nil;
EMGroupOptions *setting = [[EMGroupOptions alloc] init];
setting.maxUsersCount = 500;
setting.style = EMGroupStylePublicOpenJoin;// Select a group type
EMGroup *group = [[EMClient sharedClient].groupManager createGroupWithSubject:@"group name" description:@"group description" invitees:@[@"6001",@"6002"] message:@"You are invited to join the group!" setting:setting error:&error];
if(!error){
NSLog(@"Created -- %@",group);
}
// Group ID: @"groupId"
// Conversation type: EMConversationTypeGroupChat
EaseMessageViewController *chatController = [[EaseMessageViewController alloc] initWithConversationChatter:@"groupId" conversationType:EMConversationTypeGroupChat];
For more information about group chat, see Group Management.
Prerequisite: You've completed the previous steps of integrating the one-to-one chat function.
[[EMClient sharedClient].contactManager addContact:@"8001"
message:@"I want to add you as a friend."
completion:^(NSString *aUsername, EMError *aError) {
if (!aError) {
NSLog(@"Invitation sent successfully!");
}
}];
// Accept a friend request
[[EMClient sharedClient].contactManager approveFriendRequestFromUser:@"8001"
completion:^(NSString *aUsername, EMError *aError) {
if (!aError) {
NSLog(@"The friend request has been accepted");
}
}];
// Decline a friend request
[[EMClient sharedClient].contactManager declineFriendRequestFromUser:@"8001"
completion:^(NSString *aUsername, EMError *aError) {
if (!aError) {
NSLog(@"The friend request has been declined");
}
}];
// Delete a friend
[[EMClient sharedClient].contactManager deleteContact:@"8001"
completion:^(NSString *aUsername, EMError *aError) {
if (!aError) {
NSLog(@"Delete successful");
}
}];
// Obtain all friends from the server
[[EMClient sharedClient].contactManager getContactsFromServerWithCompletion:^(NSArray *aList, EMError *aError) {
if (!aError) {
NSLog(@"Obtain friends successfully");
}
}];
// Obtain all friends from the database
NSArray *userlist = [[EMClient sharedClient].contactManager getContacts];
For more information about group chat, see Contact Management.