Skip to content

millicast/Millicast-ObjC-SDK-iOS-Sample-App-in-Swift

Repository files navigation

The Swift Sample App (SA) demonstrates how the Millicast Objective C SDK can be used in a Swift project to publish/subscribe to/from the Millicast Platform.

Millicast SDK:

  • To use this SA, select an appropriate Millicast SDK from our list of releases.

Opening the SA

  1. The SA can be opened with Xcode.
  2. In Xcode -> File -> Open...
  3. Select the SA project file SwiftSa.xcworkspace.

Install the Millicast Objective C SDK

Ways to add the SDK

  • There are currently three ways to add the Millicast Objective C SDK, as shown below.
  • Proceed with only one of these ways at any one time.

Add SDK framework file manually.

  1. Download the selected version of SDK file from the list of release indicated above.
    • After uncompressing the archive, the SDK framework can usually be found as a package named MillicastSDK.xcframework.
  2. Open the SA in Xcode as detailed in the earlier section (Opening the SA).
  3. Add the Millicast SDK framework file into the project via the project editor
    1. Open the project editor settings.
      • In the Project navigator, click on the project name (at the top most level)
    2. Under the list of TARGETS, select your desired target, for e.g. "SwiftSa iOS" or "SwiftSa tvOS".
    3. Go to General -> Frameworks, Libraries, and Embedded Content.
    4. Add the new MillicastSDK framework:
      1. Click the "+" icon, which will pop up a window to select the new framework.
      2. Click "Add Other..." at the bottom, and then "Add Files...".
      3. Navigate to where the new MillicastSDK.xcframework is and select to "Open" this file.
      4. MillicastSDK.xcframework should now appear in the list of "Frameworks, Libraries, and Embedded Content".
    5. Repeat the steps above for any other target(s), that needs to add the new MillicastSDK.
  4. Embed and sign the framework (for each target)
    1. Open the project editor and select the desired target.
    2. Go to General -> Frameworks, Libraries, and Embedded Content.
    3. Ensure the Millicast SDK framework's Embed value is "Embed & Sign".
  5. Validate Workspace (for each target)
    1. Open the project editor and select the desired target.
    2. Go to the Build Settings -> Validate Workspace
    3. Ensure the value is "Yes".

Add SDK via CocoaPods.

SA usage

  • The required CocoaPods settings listed below are mainly for reference, as they have already been set up in the SA.
  • The only action required to use the SA is as follows:
    1. Ensure CocoaPods is installed on your system.
    2. Close the SA if it is opened in Xcode.
    3. On the command line, at the level of the Podfile, perform:
      1. For first time installation of SDK via CocoaPods:
        pod install
        
      2. For upgrade of SDK previously installed via CocoaPods:
        pod update
        
    4. Open the SA in Xcode as detailed in the earlier section (Opening the SA).

CocoaPods settings

  • The following have already been set up in the SA.
  • If you wish to add the SDK to your own app, you can follow the following steps.
  • CocoaPods details:
    • pod name: MillicastSDK
  • To create an iOS target:
    • In Podfile, add:

          target 'SwiftSa iOS' do
            platform :ios, '14.5'
            # Comment the next line if you don't want to use dynamic frameworks
            use_frameworks!
            # Pods for SwiftSa iOS
            pod 'MillicastSDK'
          end
  • To create a tvOS target:
    • In Podfile, add:

          target 'SwiftSa tvOS' do
            platform :tvos, '14.5'
            # Comment the next line if you don't want to use dynamic frameworks
            use_frameworks!
            # Pods for SwiftSa tvOS
            pod 'MillicastSDK'
          end
  • Where for all types of targets:
    • The pod line pod 'MillicastSDK' targets the latest version of SDK available on CocoaPods.
    • The platform line platform :ios, '14.5' or platform :tvos, '14.5' targets iOS or tvOS version 14.5. This version may be adjusted upwards according to needs.
    • To target a specific version of the SDK, change the pod line by following the instructions here.
      • For example, to use version 1.1.3 or higher, but lower than 1.2.0, you can change the pod line to:
              pod 'MillicastSDK', '~> 1.1.3'
  • Continue with the steps in the previous section (SA usage) to install the SDK via CocoaPods.

Add SDK via Swift Package Manager (SPM).

  1. Open the SA in Xcode as detailed in the earlier section (Opening the SA).
  2. For adding the SDK via SPM, please follow the instructions here.

Run the SA

  1. Before running the SA, it is recommended to populate the Millicast credentials in the Constants.swift file.
  2. It is also possible to enter or change the credentials when the SA is running, at the Settings page.
  3. On Xcode, click on the Run button to run the SA on the device of your choice.

To publish using the SA

  1. To publish video, a device with a camera is required. Simulators will therefore not be able to publish video.
  2. Ensure the publishing credentials are populated.
  3. Go to the Publish page.
  4. If desired, tap on the camera description and/or resolution description to cycle through the available cameras and resolutions.
  5. Click "Capture" to start capturing on the selected camera, at the selected resolution.
    • If capturing is successful, the local video can be seen on the screen.
  6. If desired to switch to another camera, click on "Switch Camera".
  7. To mute/unmute audio or video, toggle the respective buttons.
    • This affects both the captured/published media, as well as the subscribed media on Subscriber(s).
  8. Click "Publish" to publish the captured video to Millicast.
  9. To stop publishing, click "Stop Publish".

To subscribe using the SA

  1. Ensure the subscribing credentials are populated.
  2. Go to the Subscribe page.
  3. Click "Subscribe" to start subscribing to the Millicast stream specified at Settings page.
  4. To mute/unmute audio or video, toggle the respective buttons.
    • This affects only the subscribed media on this Subscriber, and not on other Subscriber(s) or the Publisher.
  5. To stop subscribing, click "Stop Subscribe".

Settings page

  • Account setting changes on the UI are not applied until the apply button is tapped.
    • Setting fields change color to alert user when UI values differ from applied values.
  • Subscribe Token
    • If the publisher settings requires a secure viewer, a valid Subscribe Token has to be set.
    • If a secure viewer is not required:
      • The following values for the Subscriber Token field are acceptable:
        • Completely blank (no white spaces).
        • A valid Subscriber Token.
      • Any other values may result in failure to connect.
    • More details on Subscribe Token here.

Miscellaneous

  • The SA enables Background Mode for "Audio, AirPlay, and Picture in Picture".
    • This allows the SA to continue subscribing and not lose its connection to the Millicast backend when it is moved to the background for any reason.
    • SA also adds the AVAudioSession mixWithOthers category option.
      • This allows playing in the background without interrupting other Apps' audio.
      • Note: Mute SA subscribed audio when not desired in the background.
  • AVAudioSession configuration:
    • When publishing, the SDK will set the AVAudioSession to the playAndRecord category, with voiceChat mode and allowBluetooth option.
    • If desired, the App can configure the AVAudioSession with its own settings.
    • The SA uses the playAndRecord category when publishing, and playback category otherwise.
      • This allows the Bluetooth A2DP profile to be used when not capturing audio.
      • Bluetooth A2DP allows better audio quality and stereo audio compared to the mono audio on Bluetooth HFP.
    • To see how the SA does this, please refer to these methods:
      • MillicastSA.swift: MillicastSA.setupNotifications()
      • Utils.swift: Utils.configureAudioSession()