環信集積

4940 ワード

`・環信オフィシャル文書http://docs.easemob.com/im/300iosclientintegration/10prepareforsdkimport
1.設定証明書
2.SDKの導入
3.高速集積
3.1 delegate配置Appkeyで最初にchatManagerを初期化する

#import "AppDelegate.h"
//Lite  
#import 
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    //AppKey:   AppKey,       。
    //apnsCertName:     (      ),       。
    EMOptions *options = [EMOptions optionsWithAppkey:@"vgios#xmg1chat"];
    options.apnsCertName = nil;
    [[EMClient sharedClient] initializeSDKWithOptions:options];
    
    
    //   nil            
    [[EMClient sharedClient].chatManager addDelegate:self delegateQueue:nil];
    return YES;
}


#pragma mark        
-(void)didAutoLoginWithInfo:(NSDictionary *)loginInfo error:(EMError *)error{
    if (!error) {
        NSLog(@"%s        %@",__FUNCTION__, loginInfo);
    }else{
        NSLog(@"       %@",error);
    }
    
}

// APP    
- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [[EMClient sharedClient] applicationDidEnterBackground:application];
}

// APP       
- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [[EMClient sharedClient] applicationWillEnterForeground:application];
}
3.2登録アカウント
 EMError *error = [[EMClient sharedClient] registerWithUsername:@"zbccc" password:@"zbccc"];
    if (error==nil) {
        NSLog(@"    ");
    }
    
    if (error) {
        NSLog(@"%@",error.errorDescription);
    }

3.2ログイン
  
    [[EMClient sharedClient] loginWithUsername:@"zbccc"
                                      password:@"zbccc"
                                    completion:^(NSString *aUsername, EMError *aError) {
                                        if (!aError) {
                                            NSLog(@"    ");
                                        } else {
                                            NSLog(@"    ");
                                        }
                                    }];


//    
EMError *error = [[EMClient sharedClient] loginWithUsername:@"8001" password:@"111111"];
if (!error)
{
   [[EMClient sharedClient].options setIsAutoLogin:YES];
}
3.3親友を追加する
  [[EMClient sharedClient].contactManager addContact:@"8001"
                                           message:@"       "
                                        completion:^(NSString *aUsername, EMError *aError) {
                                            if (!aError) {
                                                NSLog(@"      ");
                                            }
                                        }];

//      
[[EMClient sharedClient].contactManager approveFriendRequestFromUser:@"8001"
                                                          completion:^(NSString *aUsername, EMError *aError) {
                                                              if (!aError) {
                                                                  NSLog(@"      ");
                                                              }
                                                          }];

//      
[[EMClient sharedClient].contactManager declineFriendRequestFromUser:@"8001"
                                                          completion:^(NSString *aUsername, EMError *aError) {
                                                              if (!aError) {
                                                                  NSLog(@"      ");
                                                              }
                                                          }];

3.4友達を得る
//           
[[EMClient sharedClient].contactManager getContactsFromServerWithCompletion:^(NSArray *aList, EMError *aError) {
    if (!aError) {
        NSLog(@"    ");
    }
}];
//           
NSArray *userlist = [[EMClient sharedClient].contactManager getContacts];

3.5友達の削除
//     
[[EMClient sharedClient].contactManager deleteContact:@"8001"
                                           isDeleteConversation: YES
                                           completion:^(NSString *aUsername, EMError *aError) {
                                               if (!aError) {
                                                   NSLog(@"    ");
                                               }
                                           }];

APNsオフラインプッシュhttp://docs.easemob.com/im/300iosclientintegration/75apns