Building A Video Streaming App Using SwiftUI And EnableX-iOS Toolkit

Jason Wills
3 min readMar 14, 2022

--

Want to build your own live streaming iOS app? SwiftUI and EnableX-iOS can help you realise this dream.

In this post, you’ll learn to build a kick-ass app for live video streaming using the SwiftUI toolkit and EnableX-iOS toolkit.

It lets you add cool features and functionalities to enhance end users’ experience and enable monetisation options.

What Is SwiftUI?

SwiftUI, Apple’s modern framework, helps craft exciting UI/UX for iOS, tvOS, macOS and watchOS.

Unlike UIKit and AppKit, it’s a cross-platform framework that lets developers design and build new iOS apps with ease. The popularity of SwiftUI can also be attributed to its ability to provide a clean view and excellent video layout structure, not to mention the robust controls it offers. Additionally, it provides a strong mechanism to handle events like taps, swipes and other gestures that are vital to create engaging end users’ experiences.

Moreover, it also empowers developers to manage the data flow from your app’s model down to the views and controls level enabling the users to view and interact with it.

SwiftUI is Now More Powerful Than Ever

It has recently added some exciting new features to its repertoire:

· Better app experience and tools

· Improved accessibility

· SwiftUI enhancements on macOS

· More powerful widgets for iPadOS

· Declarative syntax

Creating a SwiftUI Project

First, you’ll need to get started with SwiftUI project in the Xcode. Follow the steps given below to create a Swift UI project:

Xcode ->File -> New -> Project -> select SwiftUI for interface.

Your SwiftUI project is created.

Now, open your terminal, move to the project directory and initiate the pod library using the command:pod init.

After the pod initiation step is over, open your project folder, open the “Podfile”, and add the required pod library as given below:

· pod ‘EnxRTCiOS’

· pod ‘Socket.IO-Client-Swift’, ‘~> 15.0.0’

Next, install the above-mentioned library by using the command given below.

“Pod install”

You can go live now as required library has been added successfully.

How to Call EnableX iOS Toolkit APIs

The process is straightforward since the EnableX-iOS toolkit is based on the UIkit framework.

To make this happen in SwiftUI, you’ll need to write a UIViewControllerRepresentable/ UIViewRepresentable.

// UIViewControllerRepresentable is responsible to facilitate communication between UIkit and SwiftUI and vice versa.

struct EnxConfView : UIViewControllerRepresentable{

let enxBrizCalss = BridgingClass()

func makeUIViewController(context: Context) -> BridgingClass{

enxBrizCalss.view.backgroundColor = .black

return enxBrizCalss

}

func updateUIViewController(_ uiViewController: BridgingClass, context: Context) {}

typealias UIViewControllerType = BridgingClass

}

How To Create A Bridging Class

Bridging class is responsible to communicate with EnableX classes and respond to UIViewControllerRepresentable.

class BridgingClass: UIViewController, {

// Here a UIViewcontroller is created and all UIkit APIs are handled.

}

After you’re done with creating a bridge class, it updates the UIViewControllerRepresentable and SwiftUI.

Your UIKit components are ready for use in SwiftUI.

Next, you need to create a global variable of EnxConfView in SwifUI. Here is how you can do this:

struct EnxConfrenceView: View {

var someView : EnxConfView!

var body: some View {

VStack (alignment: .center){

someView

.ignoresSafeArea()

}

}

init(){

someView = EnxConfView()

}

To help SwiftUI and UIkit communicate, create a ‘Protocol’ or ‘Notification’ class.

To get the demo app with SwiftUI and EnableX- iOS toolkit, read our detailed step tutorial:

Build a Video Chat Application With EnableX-SwiftUI

We hope you enjoyed this post.

To find out more examples & sample codes, visit our GitHub repository.

Click here to Build something exciting!

--

--

Jason Wills
Jason Wills

Written by Jason Wills

Hi there. I am a product specialist with great interest in WebRTC, Conversational AI and anything that is relating to producing engaging communications

No responses yet