iOS integration

更新时间:
复制 MD 格式

AUI Kits is Alibaba Cloud's cross-platform service for real-time audio and video communication, supporting scenarios like voice chat and multi-user interaction. Its stable and flexible communication helps you quickly build applications with a low-code approach. This topic shows you how to integrate the voice chat room feature on iOS.

Source code

Download source code

To download the source code, see the GitHub open-source project.

Directory structure

├── iOS  // Root directory for the iOS platform
│   ├── AUIVoiceRoom.podspec                      // podspec file
│   ├── Source                                    // Source code files
│   ├── Resources                                 // Resource files
│   ├── Example                                   // demo code
│   ├── AUIRoomCore                               // Core component for interactive voice chat scenarios
│   ├── AUIBaseKits                               // Base UI components   
│   ├── README.md                                 // Readme  

Environment requirements

  • Xcode 14.0 or later. We recommend that you use the latest stable release.

  • CocoaPods 1.9.3 or later.

  • A physical device running iOS 10.0 or later.

Prerequisites

Run the demo

  1. After you download the source code, navigate to the Example directory and run pod install  --repo-update to install the SDK dependency.

  2. Open the project file AUIVoiceRoomExample.xcworkspace. In Signing & Capabilities, update the Team and Bundle Identifier.

    1. For Team, select your Apple developer account.

    2. For Bundle Identifier, enter your app's bundle ID.

    Select the Automatically manage signing checkbox.

  3. Open the iOS/Source/AUIVoiceRoomManager.swift file and update the server domain name.

    let VoiceRoomServerDomain = "your_application_server_domain_name"
  4. Open the iOS/AUIRoomCore/Source/Core/Service/ARTCRoomRTCService.swift file and update the appId for your real-time audio and video application.

    @objcMembers public class AUIRoomConfig: NSObject {
        
        public var appId = "your_appId"
        ...
    }
  5. Build and run the project on a physical device.

Build a voice chat room

Follow these steps to quickly integrate AUIVoiceRoom into your app and add voice chat room capabilities.

Integrate source code

  1. Import AUIVoiceRoom.

    After you download the repository, copy the iOS folder to your app's code directory, rename it to AUIVoiceRoom, and place it at the same level as your Podfile. You can delete the Example directory.

  2. Update your Podfile to include the following:

    1. AliVCSDK_ARTC: An audio and video client SDK for real-time audio and video. You can also use AliVCSDK_Standard or AliVCSDK_InteractiveLive. For more information, see iOS client.

    2. AUIFoundation: The base UI component.

    3. AUIMessage: The interactive messaging component.

    4. AUIRoomCore: The core component for interactive voice chat scenarios.

    5. AUIVoiceRoom: The source code for the voice chat room UI component.

    # Requires iOS 10.0 or later
    platform :ios, '10.0'
    
    target 'YourAppTarget' do
        # Integrate the appropriate audio and video client SDK for your use case.
        # Supported SDKs: AliVCSDK_ARTC, AliVCSDK_Standard, AliVCSDK_InteractiveLive
        pod 'AliVCSDK_ARTC', '~> 6.10.0'
    
        # AUIFoundation
        pod 'AUIFoundation', :path => "./AUIVoiceRoom/AUIBaseKits/AUIFoundation/"
    
        # AUIMessage
        pod 'AUIMessage/AliVCIM', :path => "./AUIVoiceRoom/AUIBaseKits/AUIMessage/"
    
        # AUIRoomCore
        pod 'AUIRoomCore/AliVCSDK_ARTC', :path => "./AUIVoiceRoom/AUIRoomCore/"
        
        # AUIVoiceRoom
        pod 'AUIVoiceRoom',  :path => "./AUIVoiceRoom/"
    end
  3. Run pod install --repo-update to complete the source code integration.

Project configuration

  1. Open your project's Info.plist file and add the NSMicrophoneUsageDescription permission.

  2. Open your project settings. In Signing & Capabilities, enable Background Modes.

Source code configuration

  1. In AUIVoiceRoomManager.swift, update the application server domain name.

    // AUIVoiceRoomManager.swift
    let VoiceRoomServerDomain = "your_application_server_domain_name"
  2. In ARTCRoomRTCService.swift, update the appId for your real-time audio and video application.

    // ARTCRoomRTCService.swift
    @objcMembers public class AUIRoomConfig: NSObject {
        
        public var appId = "your_appId"
        ...
    }

API calls

You can now use the component API in other modules or your app's home page to add voice chat room features. The source code can also be modified as needed.

// Initialize before entering a voice chat room. Make sure the user is logged in to the app.
let user = ARTCRoomUser(uid) // Current user information
user.userNick = nick
user.userAvatar = avatar
let serverAuth = auth  // The token obtained after app login, used for server-side security verification
AUIVoiceRoomManager.shared.setup(currentUser: user!, serverAuth: serverAuth)

// Open the voice chat room list
let listVC = AUIVoiceRoomListViewController()
self.navigationController?.pushViewController(listVC, animated: false)

// Create a voice chat room
AUIVoiceRoomManager.shared.createRoom(currVC: self)

// Join a voice chat room
AUIVoiceRoomManager.shared.enterRoom(roomId: roomInfo.roomId, currVC: self)

Results

For more information, see the demo.

FAQ

For more information about AUI Kits or for support, join our AUI customer support group on DingTalk by searching for group ID 35685013712.