Codementor Events

How I made iOS broadcasting app in couple of days

Published Jan 30, 2020Last updated Aug 26, 2021
How I made iOS broadcasting app in couple of days

Hey, my name is Alex Polymath.

My primary skill is front-end development. And I’m not a Swift expert at all.
But when you work on a startup you just push yourself to work on things you have no experience with.
So my next experiment was making small iOS app for live streaming.
So, here are a couple of screenshots. Nothing smart, ha.

1_1wsQ6NNNTTSi0OsRTLoXOA.png

1_eZ_MkjLPrTEdNYPVT-_V0A.png

Demo

Chapter 1 — Psychological aspect

From time to time we all have fancy ideas. But most of them are never done.
The most frequent reason is that your idea looks shiny and cool. But when you start to implement some stuff, it doesn’t look so shiny and cool. There is always some technical risks. So you drop the idea in the middle of the way or spend stupid amount of time for implementing it.

Same happened to me many times.
I could spend few months for making this app, because:

  • I’m not a Swift developer -> So I could spend few weeks for learning basics.
  • Because I don’t know how to handle screen rotation so that library I was using worked fine -> Just stick to one screen position
  • Because translatesAutoresizingMaskIntoConstraints works very strange, so that you can’t set up specific size of the elements -> Just use view.bounds.midX to position elements.
  • Because I need registration -> I don’t need registration
  • Because I need about page -> I don’t need about page
  • etc

It’s kind of a hard thing to make simple things, because you thing it will be ugly. But most of us were taught in school to make things good and with effort.

Chapter 2— Swift parts

There are few simple things I needed for my app:

  • library for RTMP streaming
  • Persistent storage (Core Data)
  • Display UITextField and UIButton and align them in the center of the screen
  • Navigate between UIViewControllers

Stage 1 (3–4 hours)

So first of all I needed ios rtmp streaming library. Fortunately there is a good one LFLiveKit. Swift demo is pretty straightforward. All you need to do is create blank project and install library via pod.

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'RTMP Streamer' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!
  pod 'LFLiveKit'
  # Pods for RTMP Streamer

end

Library is super cool. I just created separate UIVIewController and copied swift demo.

Stage 2 — Persistent storage

For some reason it was kind of a struggle for me to find easy way to save simple string. I used Core Data Metadata. I took me a while to google proper way to make it persistent. All my app needed is just simply save a string

func StorageSave(key: String, value: String){
    
    let appDelegate = UIApplication.shared.delegate as! AppDelegate


    let context = appDelegate.persistentContainer.viewContext
    let store = context.persistentStoreCoordinator?.persistentStores.first
    
    let coordinator = context.persistentStoreCoordinator

   

    
    if let store = context.persistentStoreCoordinator?.persistentStores.first {
        let metadata = fillMetadata(store: store, key: key, value: value)
        store.metadata = metadata
        do {
            try coordinator?.setMetadata(["push_url": value], for: store)
            try context.save()
        } catch {
            
        }
        
    }
    
   
    
    
}

Stage 3— Align UITextField and UIButton

First I tried to make it easy way with constraints like this.

myView.translatesAutoresizingMaskIntoConstraints = true
myView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
myView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true

But this way didn’t work for me because I wanted specific size of button and textfield. While translatesAutoresizingMaskIntoConstraints makes it really difficult.

So then I found super simple way

myView.frame.origin.x = view.bounds.midX - myView.bounds.midX
myView.frame.origin.y = view.bounds.midY - myView.bounds.midY

Stage 4— Navigate between UIViewControllers

Fortunately it was the easier part.

  • First you just add navigation controller:
    Open story board -> select UIViewController -> Editor -> Embed In -> Navigation Controller.

  • Then create storyboard id for each uiviewcontroller

1_qIKvKidhMLqQwxrhGerqBA.png

  • And the final part — just push to another screen with this command.
let vc = UIStoryboard.init(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "streamingpage") as? UIViewController
self.navigationController?.pushViewController(vc!, animated: true)

Full code & contacts

You can buy the full project source code here just for 9$

For those got bought the project receive 50% discount for my mentor session
https://www.codementor.io/@alexander-k

Follow me in twitter
@alexpolymath

Discover and read more posts from Alex Polymath
get started
post commentsBe the first to share your opinion
Michael Scott
3 years ago

I think your application will be a success because Livestream is gaining momentum more and more. This is a great way not only to make money, but also to promote your brand and product. I also decided to use streaming for this purpose, especially since anyone can do it. This blog helped me get started https://livestream.studio/ Absolutely free, I found all the information and advice for beginners. It helped me to decide and try streaming, and I’m already making some progress in this.

Show more replies