# Getting Started

The VChatCloud Swift SDK is a development kit that makes it easy to implement VChatCloud services using Swift.

If you want to build an app with chat features, we recommend building a client app on top of the sample app. If you already have an app and you want to add chat, proceed with this guide to integrate chat into the app. This guide will guide you through installing chat SDK on the app, creating channel objects, and sending your first message.

If you want to use the sample app, press here to go.

Before you start

First, you need to create a chat room in CMS. If the chat room is already created, check the ChannelKey value.
To create a new one, press here.

# Send your first message

# Add dependencies

Dependencies can be added using the Swift Package Manager in XCode.

  1. Click File - Add Package Dependencies... in the top menu of XCode to see a pop-up.
  2. Enter the address https://github.com/e7works-git/VChatCloud-Swift-SDK.git in the search box at the top right of the pop-up window.
  3. Click vchatcloud-swift-sdk in the list and click Add Package to add.
  4. The SDK package is automatically installed and ready to use.

WARNING

Currently, we only support the Swift Package Manager.

# Import packages

Where you want to use SDK, add the phrase below to bring up the package.

import VChatCloudSwiftSDK
1

# Initialize SDK

Refer to ChannelDelegate to implement a new class, then initialize the SDK and import the Channel object. After that, check the Channel Key checked by CMS to set the necessary parameters for the UserViewModel and access the chat room.

import VChatCloudSwiftSDK

let channelKey = "YOUR_CHANNEL_KEY" // Please change it to the actual channel key.

do {
    if let roomData = await VChatCloudAPI.getRoomInfo(roomId: channelKey),
       let likeCount = await VChatCloudAPI.getLike(roomId: channelKey) {
        chatroomViewModel.channelKey = channelKey
        chatroomViewModel.title = roomData.title
        chatroomViewModel.rtcStat = roomData.rtcStat
        chatroomViewModel.roomType = roomData.roomType
        chatroomViewModel.lockType = roomData.lockType
        chatroomViewModel.userEmail = roomData.userEmail
        chatroomViewModel.userMax = roomData.userMax
        chatroomViewModel.like = likeCount.like_cnt
    }

    userViewModel.nickname = nickname // Nicknames for user settings
    userViewModel.clientKey = clientKey // User unique key, should not be duplicated
    userViewModel.grade = "user" // User grade
    userViewModel.userInfo = ["profile":"1"] // Profile number to use

    let channel = try await VChatCloud.shared.connect(chatroomViewModel: chatroomViewModel, userViewModel: userViewModel)
    channel.delegate = MyChannel.shared
    try await channel.join()
} catch {
    if let channelError = error as? ChannelError {
        VChatCloud.shared.disconnect()
    }
    debugPrint("error >>>")
    debugPrint(error.localizedDescription)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

# Send a message

Send messages using the sendMessage method of the Channel object.

channel.sendMessage("Hello VChatCloud!");
1
Copyright 2022. E7Works Inc. & JOYTUNE Corp. All Rights Reserved.