iOS进阶第三方应用iOS技术专题

28.简单的环信单聊(用于商城聊天)

2016-10-12  本文已影响357人  IIronMan

这里的集成是带语音的

1.导入我整理过JoanKing环信整理文件 密码: 29m8
2.在pch文件导入
  #ifdef __OBJC__
  /**
   *   环信的设置
   */
  #import "EMSDKFull.h"
  #import "EaseUI.h"
  #import "ChatViewController.h"

  #endif
3.导入库

1.SDK 包含实时语音依赖库有:

 CoreMedia.framework
 AudioToolbox.framework
 AVFoundation.framework
 MobileCoreServices.framework
 ImageIO.framework
 libc++.dylib
 libz.dylib
 libstdc++.6.0.9.dylib
 libsqlite3.dylib
 libiconv.dylib

(如果使用的是 xcode7,后缀为 tbd。)

第 2 步:SDK 不支持 bitcode,设置:Xcodeproj->Build Settings->Enable Bitcode 设置为 NO。

4.代码配置

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

//AppKey:注册的AppKey,详细见下面注释。
//apnsCertName:推送证书名(不需要加后缀),详细见下面注释。
EMOptions *options = [EMOptions optionsWithAppkey:@"注册相应应用的APPkey"];
options.apnsCertName = @"推送证书的名字";
[[EMClient sharedClient] initializeSDKWithOptions:options];

//设置回调监听代理(设置自动登录之后才能在退出后台进行获取聊天的列表)
[[EMClient sharedClient] addDelegate:self delegateQueue:nil];
BOOL isAutoLogin = [EMClient sharedClient].options.isAutoLogin;

if (isAutoLogin) {
    
    NSLog(@"123==重新登录成功");
}

/*
 EaseUI的使用
 */
[[EaseSDKHelper shareHelper] hyphenateApplication:application
                    didFinishLaunchingWithOptions:launchOptions
                                           appkey:@"注册相应应用的APPkey"
                                     apnsCertName:@"推送证书的名字"
                                      otherConfig:@{kSDKConfigEnableConsoleLogger:[NSNumber numberWithBool:YES]}];

//代码注册离线推送

//iOS8 注册APNS
if ([application respondsToSelector:@selector(registerForRemoteNotifications)]) {
    [application registerForRemoteNotifications];
    UIUserNotificationType notificationTypes = UIUserNotificationTypeBadge |
    UIUserNotificationTypeSound |
    UIUserNotificationTypeAlert;
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:notificationTypes categories:nil];
    [application registerUserNotificationSettings:settings];
}
else{
    UIRemoteNotificationType notificationTypes = UIRemoteNotificationTypeBadge |
    UIRemoteNotificationTypeSound |
    UIRemoteNotificationTypeAlert;
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:notificationTypes];
}
   /*
    *  推送的方法: - (void)didReceiveMessages:(NSArray *)aMessages{}
    */
}

// 将得到的deviceToken传给SDK
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

   /**
    *  环信的离线推送
    */
    [[EMClient sharedClient] bindDeviceToken:deviceToken];

}

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

// APP将要从后台返回
- (void)applicationWillEnterForeground:(UIApplication *)application
{
   [[EMClient sharedClient] applicationWillEnterForeground:application];
}
   EMError *error = [[EMClient sharedClient] registerWithUsername:@"注册的账号" password:@"注册的秘密"];
    if (error==nil)
    {
          NSLog(@"注册成功");
    }

5.获取聊天列表(跳转进入)

#pragma mark  聊天列表的转入
-(void)clicKchat{

  EaseConversationListViewController *easeConversationListViewController = [EaseConversationListViewController new];
  [self.navigationController pushViewController:easeConversationListViewController animated:YES];

 }

5.在此我再加一个用户用其他手机登陆的提示按钮(下次在写),记得点喜欢哦!!!

上一篇下一篇

猜你喜欢

热点阅读