跑通圈组 Demo 源码

更新时间: 2024/03/15 18:18:27

网易云信在 GitHub 上提供开源的圈组 Demo 源码。您可参考 Demo 源码,在您的本地项目中快速构建即时通讯应用。

本文介绍如何快速跑通圈组 Demo 源码。

圈组 Demo (iOS) 源码仅支持在真机上运行。

前提条件

在开始运行示例项目之前,请确保您已:

  • 已通过功能概览了解圈组相关基础概念和功能。

  • 已在云信控制台创建应用,获取 App Key。

  • 注册云信 IM 账号,获取 accid 和 token。

  • 开发环境满足以下要求:

    • Xcode 12 及以上版本
    • iOS 10.0 及以上版本

如果您需要使用搭载 Apple M1 处理器芯片的设备(如 MacBook)运行圈组 Demo 源码,请务必在设备的操作系统中完成如下配置:

  1. 进入访达->应用程序

  2. 右键单击 Xcode,并选择显示简介

  3. 勾选 使用 Rosetta 打开

    AppleM1.png

跑通流程

  1. 前往 GitHub 下载圈组 Demo 源码

  2. 进入到 Podfile 所在目录(即根目录),执行 pod install

    若报错,请执行 pod update

  3. 双击 IMQChatExample.xcworkspace,打开项目。

  4. 在工程目录的 IMQChatExample/Main/AppKey.swift 文件中,将如下代码中的 <#请输入appkey#>替换成您的 App Key。

    
      public static let appKey = "<#请输入appkey#>"
    
    
  5. 在工程目录的 IMQChatExample/Main/AppDelegate.swift 文件中,将如下代码中的 <#accid#><#token#>分别替换成您的云信账号 ID(accid)和 token。

      func setupInit(){
            let account = "<#accid#>"
            let token = "<#token#>"
    
            // init
            let option = NIMSDKOption()
            option.appKey = AppKey.appKey
            option.apnsCername = AppKey.pushCerName //若不需要推送,可不填
            IMKitEngine.instance.setupCoreKitIM(option)
            ...
          
            //填写登录信息
            weak var weakSelf = self
            IMKitClient.instance.loginIM(account, token) { error in
            if let err = error {
                print("im login error : ", err)
            }else {
                ChatRouter.setupInit()
                let param = QChatLoginParam(account,token)
                IMKitClient.instance.loginQchat(param) { error, response in
                    if let err = error {
                        print("qchatLogin failed, error : ", err)
                    }else {
                        weakSelf?.initializePage()
                    }
                }
            }
        }
    
        }
    
  6. 将示例项目运行在您的真机设备上,即可开始体验圈组相关功能。

此文档是否对你有帮助?
有帮助
去反馈
  • 前提条件
  • 跑通流程