Talk to us
Talk to us
menu

Blog Post

start building
Developer

How To Build Streaming Services With iOS UIKit

How To Build Streaming Services With iOS UIKit

People favor dynamic images. We watch TV, look for humorous videos on YouTube, and subscribe to streaming services like Netflix and HBO Max, so they are all around us. Both the user base and the number of publishing options for video content are expanding. Unsurprisingly, company owners are becoming more interested in learning how to create a live streaming application.

Furthermore, because of the pandemic’s restrictions and lockdowns, this sector has grown to be very profitable. more people began watching online live streaming, and it is currently anticipated that as a result of streaming, users will yearly spend more than $17 billion on social apps by the year 2025.

In this article, I will walk you step-by-step through building a best streaming service using the iOS Live Streaming Kit SDK.

Introduction to iOS Live Streaming Kit

iOS Live Streaming Kit is a brand-new pre-built UIKits by ZEGOCLOUD. it’s a best streaming service, You can use it complete the development of a live streaming app within 10 minutes.

streaming services

As shown in the figure, iOS Live Streaming Kit is responsible for handling all the logic and UI of the stream services function. Include:

  • UI and interaction of the live Streaming module
  • Message sending and display
  • Audio and video data transmission
  • Camera and microphone management
  • Live Viewer Statistics

You only need to implement business-related logic. For example:

  • User login registration
  • Live List Management
  • Top up and send gifts, etc.

Preparation

  • A ZEGOCLOUD developer account — Sign up
  • Xcode 12.3 or later
  • Devices with iOS 12.0 or later
  • Basic understanding of iOS development

Implement live streaming

1. Create project

First, Use Xcode create a project.
create_project

2. Add ZegoUIKitPrebuiltLiveStreaming as dependencies

2.1 Create podfile

You need to use cocopods to import the SDK. First, you need to execute pod init in your project root directory to create a podfile.

pod init

Then open the created podfile and add pod 'ZegoUIKitPrebuiltLiveStreaming' in the file.

pod 'ZegoUIKitPrebuiltLiveStreaming'  

Finally, execute the pod install command to download the SDK.

pod  install
add cocoapods

3. Open project

After you finish step 2, a .xcworkspace file will be generated in the root directory, double-click .xcworkspace file to open the project.

open project

4. add Permissions

Next, you need to add permission requests for camera and microphone in the Info.plist file.

<key>NSCameraUsageDescription</key>
<string>We require camera access to connect to a call</string>
<key>NSMicrophoneUsageDescription</key>
<string>We require microphone access to connect to a call</string>
add mic camera permission

5. Start a live

There are two roles in the streaming service, the host and the audience. The host is to start the streaming services, and the audience is to join the streaming services. Let’s first talk about how the host starts streaming services.

5.1 Import SDK

First you need to import ZegoUIKitSDK and ZegoUIKitPrebuiltLiveStreaming SDKs in ViewController.

import ZegoUIKit
import ZegoUIKitPrebuiltLiveStreaming
import sdk

5.2 Add SDK authentication parameters

Next, you need to add appID and appSign as SDK authentication parameters, which can be obtained from the [ZEGOLCOUD console](). However, in practical applications, it is recommended to use [token authentication]() to prevent leakage of authentication parameters.

let appID: UInt32 = YourAppID
let appSign: String = YourAppSign
add app id

5.3 Create a live id

you need a liveID, you need create a live ID

create live id

5.4 Add user info

Next, user information needs to be set, Live Streaming Kit SDK needs to pass userID and userName as user information. Here as a demo, Use random numbersc for user ID and user name. In practical applications, you can use the user ID and user name used by your business background.

create user id

5.5 Start Live

Finally, you can start the live. If it is a Host, use kRoleHost as a parameter. Live String Kit will judge according to the parameters, if it is a Host, it will use the liveID to create a new live room.

@IBAction func startLiveButtonClick(_ sender: Any) {
    let config: ZegoUIKitPrebuiltLiveStreamingConfig = ZegoUIKitPrebuiltLiveStreamingConfig(kRoleHost)
    let liveVC: ZegoUIKitPrebuiltLiveStreamingVC = ZegoUIKitPrebuiltLiveStreamingVC(self.appID, appSign: self.appSign, userID: self.userID, userName: self.userName ?? "", liveID: self.liveIDTextField.text ?? "", config: config)
    liveVC.modalPresentationStyle = .fullScreen
    self.present(liveVC, animated: true, completion: nil)

  }
start live

5.6 Join live

If it is an audience, use kRoleAudience as a parameter, and Live Streaming Kit will judge according to the parameters. If it is an Audience, it will use the liveID to join the live room. If the live room does not exist, it will fail to join.

@IBAction func watchLiveButtonClick(_ sender: Any) {
    let config: ZegoUIKitPrebuiltLiveStreamingConfig = ZegoUIKitPrebuiltLiveStreamingConfig(kRoleAudience)
    let liveVC: ZegoUIKitPrebuiltLiveStreamingVC = ZegoUIKitPrebuiltLiveStreamingVC(self.appID, appSign: self.appSign, userID: self.userID, userName: self.userName ?? "", liveID: self.liveIDTextField.text ?? "", config: config)
    liveVC.modalPresentationStyle = .fullScreen
    self.present(liveVC, animated: true, completion: nil)
  }
watch live

Run a demo

Conclusion

The market for streaming services is expanding yearly. Real-time communication via streams is getting more popular. This tendency was driven by the epidemic as well as internet musical performances and events. There are many application cases, such as in education and healthcare. It implies that it might be worthwhile to consider constructing a stream services application.

Take action now, You can download the sample demo source code of this article, or consult us 24h technical support.

Read more

ZEGOCLOUD
ZEGOCLOUD With our fully customizable and easy-to-integrate Live SDK, you can quickly build reliable, scalable, and interactive live streaming into your mobile, web, and desktop apps.

Related posts