1. 程式人生 > >ios-swift-環信整合

ios-swift-環信整合

說明:目前swift環信整合 通過pod方式整合後開啟聊天介面會一直報如下的錯,目前還沒找到解決方式,但是同手動整合 sdk以及EaseUI就可以正常使用,本片部落格,介紹的就是通過手動方式整合,如果哪個同僚解決了通過 pod方式整合報的錯誤,請聯絡我:我的微信:13022861472
這裡寫圖片描述

第一步,從環信官網下載環信 SDK

這裡寫圖片描述

2.將 ‘HyphenateFullSDK’匯入專案

HyphenateFullSDK:是包含音視訊的
HyphenateSDK:是不包含音視訊的
這裡寫圖片描述

3.向General → Embedded Binaries 中新增依賴庫

新增動態庫:需要在TARGETS -> General -> Embedded Binaries 中新增動態庫,
這裡寫圖片描述


如果 Linked Frameworks and Libraries 中有兩個 ‘Hyphenate.framework’庫,就刪掉一個
這裡寫圖片描述

4. 新增其它第三方的依賴庫

在 Build Phases ->Linked Frameworks and Libraries處新增
這裡寫圖片描述
這些是要新增的庫(11個)
Pods_EMTest除外
這裡寫圖片描述

5.配置一些資訊

在iOS9下,系統預設會攔截對http協議介面的訪問,因此無法獲取http協議介面的資料。此處設定為暫時退回到http協議。
這裡寫圖片描述
這裡寫圖片描述

6.匯入EaseUI庫

這裡寫圖片描述

bitcode是被編譯程式的一種中間形式的程式碼。包含bitcode配置的程式將會在App store上被編譯和連結。bitcode允許蘋果在後期重新優化程式的二進位制檔案,而不需要重新提交一個新的版本到App store上;第三方SDK沒有支援Bitcode包就選no
這裡寫圖片描述

7.建立橋接檔案

這裡寫圖片描述
這裡寫圖片描述

8.建立 pch檔案

這裡寫圖片描述
這裡寫圖片描述

9.繼承 EaseMessageViewController 實現聊天介面

//
//  ChatViewController.swift
//  HuanXinDome
//
//

import UIKit

class ChatViewController: EaseMessageViewController {
    //跟對方聊天時,呼叫的初始化方法,第一個引數為對方的環信註冊的id ,第二個引數為聊天的型別 EMConversationTypeChat:單聊
    override init!(conversationChatter: String!, conversationType: EMConversationType) {
        super.init(conversationChatter: conversationChatter, conversationType: conversationType)
    }

    override
init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName: nil, bundle: nil) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. } */ }

9.初始化,登入,進行聊天

//
//  AppDelegate.swift
//  HuanXinDome
//
//  Created by 陝西幫你電子科技有限公司 on 2018/6/15.
//  Copyright © 2018年 陝西幫你電子科技有限公司. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        //環信配置
        let options:EMOptions = EMOptions.init(appkey: "申請的appkey")
        options.apnsCertName = "建立的推送證書名字"
        let error = EMClient.shared().initializeSDK(with: options)
        if error == nil{
            print("環信初始化成功")
            let emId = "13233253173"//登入的環信id
            let emPwd = "pd13233253173"//密碼
            let error = EMClient.shared().login(withUsername: emId, password: emPwd)
            if error == nil{
                self.window = UIWindow.init(frame: UIScreen.main.bounds)
                print("登入成功")
                let dui_emId = "15991788992" //要聊的對方的環信id
                //開啟聊天介面與對方聊天(第一個引數為聊天對方的id,第二個引數為聊天的型別(此處為單聊))
                let vc = ChatViewController.init(conversationChatter: dui_emId, conversationType: EMConversationTypeChat)
                vc?.title = "你正在和15991788992聊天"
                let nav = UINavigationController.init(rootViewController: vc!)
                self.window?.rootViewController = nav
                self.window?.makeKeyAndVisible()
            }

        }
        return true
    }

    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }


}

完成
Dome地址