# Using the Sample App

Let's find out the necessary process to run the sample app.

# Required Changes

Precautions

After downloading the sample code, you need to change the value of channelKey. You can check and change the part you want to change through the explanation below.

# Source code 💾

# Change channelKey

  1. Download the iOS sample app.
  2. Release the compressed file and open the view/Login/LoginView.shift file to the editor.
  3. Copy the Channel Key of the chat room you opened on the CMS screen.
  4. Add the value of the variable name channelKey within the goLogin function with the value of channelKey copied from number 3.
  • view/Login/LoginView.swift
let channelKey = "YOUR_CHANNEL_KEY"
1

# Channel

Channel classes allow you to enter chat rooms and send messages. The code below only covers entering the chat room, and for detailed descriptions of methods such as sending messages, please refer to the Channel on the left menu list.

do {
    let channelKey = "YOUR_CHANNEL_KEY"

    // Defines the user's clientKey value, but must be set so that users do not overlap.
    clientKey = clientKey.isEmpty ? randomString(length: 10) : clientKey

    userViewModel.nickname = nickname
    userViewModel.clientKey = clientKey
    userViewModel.grade = "user"
    userViewModel.userInfo = ["profile":profileIndex.description]

    // Use VChatCloud API to retrieve room information.
    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
    }

    // Access the chat server.
    let channel = try await VChatCloud.shared.connect(chatroomViewModel: chatroomViewModel, userViewModel: userViewModel)
    // Register the object in channel.delegate to delegate the processing of channel events.
    channel.delegate = MyChannel.shared
    // Access the chat room.
    try await channel.join()
} catch {
    if let channelError = error as? ChannelError {
        VChatCloud.shared.disconnect()
    } else {
        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
33
34
35
36
37
38
Copyright 2022. E7Works Inc. & JOYTUNE Corp. All Rights Reserved.