CallU IM UI使用入门
一:集成说明
CocoaPods 集成(推荐)
支持 CocoaPods 方式和手动集成两种方式。我们推荐使用 CocoaPods 方式集成,以便随时获取最新版本。
在 Podfile 中增加以下内容。
pod 'CallUUI'
执行以下命令安装 LMPush。
pod install
如果无法安装 SDK 最新版本,执行以下命令更新本地的 CocoaPods 仓库列表。
pod repo update
手动集成(不推荐)
-
在 Framework Search Path 中添加 CallUApi 和 CallUUI 的文件路径,手动将 CallUApi.framework 和 CallUUI.framework 添加到您的工程“Frameworks and Libraries”中。CallUApi 和 CallUUI 使用 Swift 语言进行原生开发,关于 Objective-C 桥接操作,请自行搜索 Baidu。
-
在 Podfile 中增加以下内容。
pod 'CallUApi'
pod 'AWSS3'
pod 'SDWebImage'
pod 'SDWebImage/GIF'
pod 'IQKeyboardManager'
pod 'TSVoiceConverter'
pod 'MJRefresh'
pod 'MBProgressHUD'
pod 'SnapKit'
pod 'SQLite.swift'
pod 'GoogleMaps'
pod 'GooglePlaces'
pod 'GooglePlacePicker'
二:API 相关说明
1. 在AppDelegate中初始化
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UIManager.getInstance().initSdk() //init sdk
UIManager.getInstance().registerNotification(application: application, delegate: self) //注册推送, 也可以不调用,自己代码编写
return true
}
- 1.1 推送功能接入 如果你还需要接入推送功能,在下面的回调方法中要进行方法的注入,当APNS推送在接收到IM相关消息时,会自动处理:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
UIManager.getInstance().application(application, didRegisterForRemoteNotificationsWithDeviceToken:deviceToken)
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void){
UIManager.getInstance().userNotificationCenter(center, willPresent:notification, withCompletionHandler:completionHandler)
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void){
UIManager.getInstance().userNotificationCenter(center, didReceive:response, withCompletionHandler:completionHandler)
completionHandler()
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
UIManager.getInstance().application(application, didReceiveRemoteNotification:userInfo, fetchCompletionHandler:completionHandler)
}
- 1.2 用户登录 IM 平台的用户登录操作一般由服务端进行调用,将IM平台返回的信息在你当前系统的登录操作完成后,一起返回到app。当然,我们也提供了app端的登录操作封装代码,以供使用:
CUUserManager.getInstance().login(userName: "你的用户名", password: “你的密码”) { [weak self] (result: CUResponse<CULoginResponse>) in
}
获取IM平台用户登录信息后,需在UI Sdk中的登录信息中进行设置
UIManager.getInstance().setLoginResponse(response)
PS:UI Sdk中不提供“用记注册”功能,注册一般由服务端完成,例如在进行自有系统注册流程的同时,调用IM后台服务的注册接口,完成注册流程。
- 1.3 设置IM Sdk通知回调方法:当你的app中需要接收IM相关的APNS推送时,要先完成1.1中的相关代码调用,如果不进行推送,可以忽略以下内容。在IM Sdk中,要处理两种推送消息的处理逻辑:“收到新的IM消息”,“有新的好友请求”。
UIManager.getInstance().addNewMessageObserver(self, selector:#selector(onNewMessage(notification:)))
UIManager.getInstance().addNewFriendObserver(self, selector:#selector(onNewFriend(notification:)))
相关处理代码可参考如下:
//apns点击通知 进入聊天页面
@objc func onNewMessage(notification: Notification){
if let chatId:String = notification.object as? String{
let controller:CUIIMViewController = CUIIMViewController.instanceIMController()
controller.chatId = chatId
self.navigationController?.pushViewController(controller, animated: true)
}
}
//apns点击通知 进入好友请求列表
@objc func onNewFriend(notification:Notification){
let controller:CUIFriendRequestViewController = CUIFriendRequestViewController.instanceFriendRequestViewController()
self.navigationController?.pushViewController(controller, animated: true)
}
2. 创建会话列表界面
- 通过代码创建:
let viewController:CUISeeionsListViewController = CUISeeionsListViewController.CreateViewController()
为了方便自定义,会话列表界面没有设置title,因此可以将获取到的controller的view,进行本页面的填充
通过Storyboard方式引入:
3. 打开聊天界面
let controller:CUIIMViewController = CUIIMViewController.CreaetViewController()