Skip to content

openimsdk/open-im-ios-demo

Repository files navigation

OpenIM iOS Demo 💬💻

OpenIM DocsOpenIM Serveropenim-sdk-iosopenim-sdk-core


OpenIM iOS Demo is a set of UI components implemented based on Open-IM SDK, which includes functions such as conversation, chat, relationship chain, group, etc. Based on UI components, you can quickly build your own business logic.

Dev Setup 🛠️

  1. Development environment requirements

    • Xcode 15 and above

    • The minimum deployment target is iOS 13.0.

  2. Git Clone:

    https://github.com/OpenIMSDK/Open-IM-iOS-Demo.git
  3. Execute the following command on the terminal to install the dependent library.

    cd Open-IM-iOS-Demo/Example
    pod install
  4. If the installation fails, execute the following command to update the local CocoaPods warehouse list.

    pod repo update
  5. Compile and run: Enter the Open-IM-iOS-Demo/Example folder, open OpenIMSDKUIKit.xcworkspace to compile and run.

  6. Experience your own server 6.1 If you have Deploy OpenIM Server yourself, you can modify the server in the file AppDelegate.swift The address is the server address built by yourself;

    6.2 After downloading the app, click "Welcome to OpenIM" on the [Login] page to enter the setting page, make relevant settings, save and restart to use.

  7. Start development! 🎉

Usage 🚀

Commonly used chat software is composed of several basic interfaces such as session list, chat window, friend list, audio and video calls, etc. Refer to the following steps, you only need a few lines of code to quickly build these UI interfaces in the project.

Step 1: Change your own server IP address:

AppDelegate.swift

// Default IP address to be used
let defaultHost = ""; // Replace with the desired host

Step 2: Login

  1. Log in to your own business server to obtain userID and token;
  2. Use 1. to obtain userID and token to log in to the IM server;
// 1: Log in to your own business server to obtain userID and token;

  static func loginDemo(phone: String, pwd: String, completionHandler: @escaping ((_ errMsg: String?) -> Void)) {
      let body = JsonTool.toJson(fromObject: Request.init(phoneNumber: phone, pwd: pwd)).data(using: .utf8)
     
      var req = try! URLRequest.init(url: "your login api", method: .post)
      req.httpBody = body
     
      Alamofire.request(req).responseString { (response: DataResponse<String>) in
          switch response. result {
          case.success(let result):
              if let res = JsonTool.fromJson(result, toClass: Response.self) {
                  if res.errCode == 0 {
                      completionHandler(nil)
                      // log in to the IM server
                      loginIM(uid: res.data.userID, token: res.data.token, completionHandler: completionHandler)
                  } else {
                      completionHandler(res.errMsg)
                  }
              } else {
                  let err = JsonTool.fromJson(result, toClass: DemoError.self)
                  completionHandler(err?.errMsg)
              }
          case.failure(let err):
              completionHandler(err. localizedDescription)
          }
      }
  }
  static func loginIM(uid: String, token: String, completionHandler: @escaping ((_ errMsg: String?) -> Void)) {
      IMController.shared.login(uid: uid, token: token) { resp in
          print("login onSuccess \(String(describing: resp))")
          completionHandler(nil)
      } onFail: { (code: Int, msg: String?) in
          let reason = "login onFail: code \(code), reason \(String(describing: msg))"
          completionHandler(reason)
      }
  }

Step 3: Construct conversation list, chat window, address book interface, settings:

  // session list
  let chat = ChatListViewController()
  // chat window
  let message = MessageListViewController()
  // address book
  let contactVC = ContactsViewController()
  // set up
  let mineNav = MineViewController()

Community 👥

Community Meetings 📆

We want anyone to get involved in our community and contributing code, we offer gifts and rewards, and we welcome you to join us every Thursday night.

Our conference is in the OpenIM Slack 🎯, then you can search the Open-IM-Server pipeline to join

We take notes of each biweekly meeting in GitHub discussions, Our historical meeting notes, as well as replays of the meetings are available at Google Docs 📑.

Who are using OpenIM 👀

Check out our user case studies page for a list of the project users. Don't hesitate to leave a 📝comment and share your use case.

License 📄

OpenIM is licensed under the Apache 2.0 license. See LICENSE for the full license text.