Opening Chat 2.x - Bandyer/Bandyer-iOS-SDK GitHub Wiki

This guide will show you how to interact with the Channel view controller. If you are integrating a 1.x version of the SDK you should take a look at this guide instead.

Table of contents:

Overview

The Channel view controller is the UI designed for you surrounding the chat services. Using this controller is real easy to send/receive messages. All the job is made for you, you have just to init the view controller and configure it, following these steps:

  1. Start the chat client.
  2. Create an intent containing the information needed to open a chat (Required).
  3. Configure the navigation bar appearance (Optional).
  4. Provide the intent and the configuration to the view controller.

From now on we are assuming you read the previous guides regarding the chat client life cycle.

The OpenChat Intent

In order to tell the SDK who you want to chat with you must create an OpenChatIntent. You must provide this object the user alias for the user you want to chat with, or a chat notification object received when an in-app notification is tapped by the user.

// This is the notification instance received by the SDK
let notification: ChatNotification 

//here we are creating a OpenChatIntent instance
let intent = OpenChatIntent.openChat(from: notification)
let userAlias = "" // This is the id of the user we want to chat with

// Here we are creating a OpenChatIntent instance
let intent = OpenChatIntent.openChat(with: userAlias)
// This is the notification instance received by the SDK
BDKChatNotification *notification; 

// Here we are creating a BDKOpenChatIntent instance
BDKOpenChatIntent *intent = [BDKOpenChatIntent openChatFrom:notification];
NSString *userAlias; // This is the id of the user we want to chat with

// Here we are creating a BDKOpenChatIntent instance
BDKOpenChatIntent *intent = [BDKOpenChatIntent openChatWith:userAlias];

The intent will carry all the necessary information for opening the chat UI. Once initialized, you have to pass it to a ChannelViewController instance through the intent property.

The configuration

The ChannelViewControllerConfiguration class is the object responsible for holding the configuration options of the ChannelViewController.

By default, if the default initializer is used or no configuration object is provided to the ChannelViewController, the video and audio call buttons are showed on the view controller's navigation bar.

// Here we are configuring the channel view controller:
// if audioButton is true, the channel view controller will show audio button on nav bar;
// if videoButton is true, the channel view controller will show video button on nav bar;
        
let configuration = ChannelViewControllerConfiguration(audioButton: true, videoButton: true)
// Here we are configuring the channel view controller:
// if audioButton is true, the channel view controller will show audio button on nav bar;
// if videoButton is true, the channel view controller will show video button on nav bar;

BDKChannelViewControllerConfiguration* configuration = [[BDKChannelViewControllerConfiguration alloc] initWithAudioButton:YES videoButton:YES];

The ChannelViewController

Once you have created an OpenChatIntent intent and a ChannelViewControllerConfiguration object, you can initialize a ChannelViewController instance and present it.

class MyViewController: UIViewController {

    func openChat(with user: String) {
        let intent = OpenChatIntent.openChat(with: user)
        let configuration = ChannelViewControllerConfiguration(audioButton: true, videoButton: true)

        let channelViewController = ChannelViewController()
        channelViewController.configuration = configuration
        channelViewController.intent = intent
        channelViewController.delegate = self
    
        present(channelViewController, animated: true)
    }
}

//MARK: Channel view controller delegate
extension MyViewController: ChannelViewControllerDelegate {

    public func channelViewControllerDidFinish(_ controller: ChannelViewController) {
        // This delegate method is invoked when the Channel View Controller has finish his job.
        // Here you must dismiss BCHChannelViewController.
    }

    public func channelViewController(_ controller: ChannelViewController, didTapAudioCallWith users: [String]) {
        // This delegate method is invoked when the user press on the audio call button on the NavigationBar.
        // Here you must present Call View controller.
    }

    public func channelViewController(_ controller: ChannelViewController, didTapVideoCallWith users: [String]) {
        // This delegate method is invoked when the user press on the video call button on the NavigationBar.
        // Here you must present Call View controller.
    }
}
@implementation MyViewController

- (void)openChatWithUser:(NSString *)user
{
    BDKOpenChatIntent *intent = [BDKOpenChatIntent openChatWith:user]
    BDKChannelViewControllerConfiguration* configuration = [[BDKChannelViewControllerConfiguration alloc] initWithAudioButton:YES videoButton:YES];

    BDKChannelViewController *channelViewController = [[BDKChannelViewController alloc] init];
    channelViewController.configuration = configuration;
    channelViewController.intent = intent;
    channelViewController.delegate = self;
    
    [self presentViewController:channelViewController animated:YES, completion:NULL];
}

#pragma mark - Channel view controller delegate

- (void)channelViewControllerDidFinish:(BDKChannelViewController *)controller
{
    // This delegate method is invoked when the Channel View Controller has finish his job.
    // Here you must dismiss BCHChannelViewController.
}

- (void)channelViewController:(BDKChannelViewController *)controller didTapAudioCallWith:(NSArray *)users
{
    // This delegate method is invoked when the user press on the audio call button on the NavigationBar.
    // Here you must present Call View controller.
}

- (void)channelViewController:(BDKChannelViewController *)controller didTapVideoCallWith:(NSArray *)users
{
    // This delegate method is invoked when the user press on the video call button on the NavigationBar.
    // Here you must present Call View controller.
}

@end

That's it! the steps you've seen are the only steps required to start sending/receiving messages.

Where to go from here

The next guide In-app notifications will teach you how to show an in-app notification every time a message is received. Also, if you haven't already, we suggest you to take a look at our sample apps (objective-c, swift) to see how to start sending/receiving messages in a real app.

What's next