====== iOS SDK Quickstart ====== ===== One-to-One Chat ===== ==== Step 1 - Install SDK ==== === Option 1: Use CocoaPods (Recommended) === The Hyphenate SDK for iOS is available on [[https://cocoapods.org/|CocoaPods]]. CocoaPods is an open source dependency manager for Cocoa projects. 1. If you have not installed CocoaPods tool yet, please check out [[https://guides.cocoapods.org/using/getting-started.html|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 === Option 2: Download SDK from Hyphenate === 1. [[https://github.com/HyphenateInc/Hyphenate-SDK-iOS|Download]] Hyphenate SDK. 2. Import the SDK to your own project. For details, see [[im:iosclientintegration:iossdkimport|Install the Hyphenate SDK]]. ==== Step 2 - Initialize the SDK ==== 1. If CocoaPods is used, you need to import the SDK header file. // Hyphenate iOS lite SDK #import // Hyphenate iOS SDK (Support real-time Voice & Video Calling features) #import 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]; } ==== Step 3 - Login ==== Call the login API. [[EMClient sharedClient] loginWithUsername:@"8001" password:@"111111" completion:^(NSString *aUsername, EMError *aError) { if (!aError) { NSLog(@"Login successful"); } else { NSLog(@"Login failed"); } }]; ==== Step 4 - Import EaseUI ==== Option 1: Download Hyphenate SDK and Import the EaseUI directory. {{:im:300iosclientintegration:ios_quickstart_release_catalog.jpg|}} Option 2: [[https://github.com/easemob/easeui_ios/tree/sdk3.x|Download]] the EaseUI source code and import it to your project. https://github.com/easemob/easeui_ios/tree/sdk3.x/EaseUI/EaseUI ==== Step 5 - Initialize the One-to-One Chat Interface ==== //Hyphenate ID: @"8001" //Conversation type: EMConversationTypeChat EaseMessageViewController *chatController = [[EaseMessageViewController alloc] initWithConversationChatter:@"8001" conversationType:EMConversationTypeChat]; For more information about one-to-one chat, see [[im:iosclientintegration:emmsg|Messaging]]. ===== Group Chat ===== Prerequisite: You've completed the previous steps of integrating the one-to-one chat function. ==== Create a Group ==== 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); } ==== Initialize the Group Chat Interface ==== // Group ID: @"groupId" // Conversation type: EMConversationTypeGroupChat EaseMessageViewController *chatController = [[EaseMessageViewController alloc] initWithConversationChatter:@"groupId" conversationType:EMConversationTypeGroupChat]; For more information about group chat, see [[im:iosclientintegration:groupmgmt|Group Management]]. ===== Contacts ===== Prerequisite: You've completed the previous steps of integrating the one-to-one chat function. ==== Add a friend ==== [[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 ==== // Delete a friend [[EMClient sharedClient].contactManager deleteContact:@"8001" completion:^(NSString *aUsername, EMError *aError) { if (!aError) { NSLog(@"Delete successful"); } }]; ==== Obtain the Friend List ==== // 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 [[im:iosclientintegration:buddymgmt|Contact Management]].