Virtual Avatar
  • iOS : Objective-C
  • Android
  • Overview
  • Client SDKs
  • Demo app
  • Getting started
    • Integrate the SDK
    • Create a virtual avatar
    • ZegoCharacterHelper instructions
  • Guides
  • Best practice
  • Error codes
  • Server APIs
  • Documentation
  • Virtual Avatar
  • Client SDKs
  • Run the sample code

Run the sample code

Last updated:2023-02-09 11:15

This document describes how to quickly run the sample source code and experience the Avatar service.

Prepare the environment

Before running the sample source code, ensure that the development environment satisfies the following requirements:

  • Xcode is in version 7.0 or later.
  • The iOS system is in version 13.0 or later and supports audio and video iOS devices or simulators (real devices are recommended).
  • iOS devices have been connected to the Internet.

Prerequisites

  • You have created a project in the ZEGO Admin Console and obtained invalid AppID and AppSign for the project.
  • You have contacted ZEGOCLOUD business personnel to obtain the Bundle ID of your project and grant related permissions.
  • You have obtained the SDK and the sample source code package from the Download page.

Directory structure of the sample source code

The following part is the subdirectory structure of the Avatar source code file. The file paths mentioned below are relative to this directory.

├── Podfile
├── Podfile.lock
├── ZegoAvatarExample
│   ├── AppDelegate.h
│   ├── AppDelegate.m
│   ├── Assets.xcassets
│   ├── Base.lproj
│   ├── Controller                      # Basic ViewController
│   ├── Express                         # Sample code collected by Express
│   ├── Helper                          # ZegoCharacterHelper directory
│   ├── Info.plist
│   ├── Libs                            # Avatar SDK directory
│   ├── LicenseHelper                   # Code related to online authentication
│   ├── SceneDelegate.h
│   ├── SceneDelegate.m
│   ├── Tools
│   ├── View                            # API example page
│   ├── ViewController.h
│   ├── ViewController.m                # Entry page
│   ├── assets                          # Model resources
│   └── main.m
├── ZegoAvatarExample.xcodeproj
├── ZegoAvatarExample.xcworkspace
├── ZegoAvatarExampleTests
└── ZegoAvatarExampleUITests

Run the sample source code

  1. Open App Store, search for "Xcode", and download and install Xcode.

  2. Use Xcode to open the ZegoAvatarExample.xcworkspace file.

    1. Open Xcode and choose File > Open... in the upper left corner.

      /Pics/ZegoAvatar/iOS/ios_open_project.png

    2. In the decompressed sample source code folder, select the ZegoAvatarExample.xcworkspace file and click Open.

      /Pics/ZegoAvatar/iOS/ios_select_project.png

  3. In the sample project, CocoaPods is required to manage third-party libraries. If CocoaPods is not installed, please visit CocoaPods official website and follow the installation steps to install CocoaPods.

    Once the installation is completed, open the terminal, visit the "example" directory, and run the pod install command to install the dependency libraries.

    /Pics/ZegoAvatar/iOS/pod_install.png

  4. Log in by using your Apple Developer account.

    1. Open Xcode and choose Xcode > Preferences... in the upper left corner.

    2. Click the Accounts tab. Click + in the lower left corner, select and add an Apple ID, and then click Continue.

      /Pics/ZegoAvatar/iOS/add_account.png

    3. Enter the Apple ID and Password to log in.

      /Pics/ZegoAvatar/iOS/fill_account.png

  5. Modify the Bundle Identifier and developer certificate.

    1. Open Xcode and click ZegoAvatarExample in the left pane.

      /Pics/ZegoAvatar/iOS/select_proj_sign.png

    2. Select ZegoAvatarExample for TARGETS. Click the Signing & Capabilities tab, and select your developer certificate under Team.

      /Pics/ZegoAvatar/iOS/select_sign.png

    3. Find Bundle Identifier in the figure above and fill in the Bundle ID corresponding to your developer certificate.

      /Pics/ZegoAvatar/iOS/bundleid.png

  6. The authentication information (AppID and AppSign) required for SDK initialization is missing in the sample source code. You need to modify the ZegoAvatarConfig.h file in the example/ZegoAvatarExample/LicenseHelper directory. Enter the obtained information stated in Prerequisites correctly. Otherwise, the sample source code cannot be run.

    /Pics/ZegoAvatar/iOS/modify_appid.png

  7. Model resources are large and are not packaged in the "example" path. In this case, you need to find the "assets" folder in the decompressed folder, and add the content under the folder to the "ZegoAvatarExample/assets" path. SDK and ZegoCharacterHelper have been updated synchronously when the sample source code is packaged and do not need to be copied manually.

    /Pics/ZegoAvatar/iOS/add_assets.png

    The result is as follows:

    /Pics/ZegoAvatar/iOS/add_assets_result2.png

  1. Connect the iOS device to the development computer, click Generic iOS Device in the upper left corner of Xcode to select the iOS device (or simulator).

    /Pics/ZegoAvatar/iOS/select_device.png

  2. Click Build in the upper left corner of Xcode to compile and run the sample source code.

    /Pics/ZegoAvatar/iOS/start_demo.png

Page Directory