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.
- To use this SA, select an appropriate Millicast SDK from our list of releases.
- The SA can be opened with Xcode.
- In Xcode -> File -> Open...
- Select the SA project file SwiftSa.xcworkspace.
- 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.
- 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.
- Open the SA in Xcode as detailed in the earlier section (Opening the SA).
- Add the Millicast SDK framework file into the project via the project editor
- Open the project editor settings.
- In the Project navigator, click on the project name (at the top most level)
- Under the list of TARGETS, select your desired target, for e.g. "SwiftSa iOS" or "SwiftSa tvOS".
- Go to General -> Frameworks, Libraries, and Embedded Content.
- Add the new MillicastSDK framework:
- Click the "+" icon, which will pop up a window to select the new framework.
- Click "Add Other..." at the bottom, and then "Add Files...".
- Navigate to where the new MillicastSDK.xcframework is and select to "Open" this file.
- MillicastSDK.xcframework should now appear in the list of "Frameworks, Libraries, and Embedded Content".
- Repeat the steps above for any other target(s), that needs to add the new MillicastSDK.
- Open the project editor settings.
- Embed and sign the framework (for each target)
- Open the project editor and select the desired target.
- Go to General -> Frameworks, Libraries, and Embedded Content.
- Ensure the Millicast SDK framework's Embed value is "Embed & Sign".
- Validate Workspace (for each target)
- Open the project editor and select the desired target.
- Go to the Build Settings -> Validate Workspace
- Ensure the value is "Yes".
- 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:
- Ensure CocoaPods is installed on your system.
- Close the SA if it is opened in Xcode.
- On the command line, at the level of the Podfile, perform:
- For first time installation of SDK via CocoaPods:
pod install
- For upgrade of SDK previously installed via CocoaPods:
pod update
- For first time installation of SDK via CocoaPods:
- Open the SA in Xcode as detailed in the earlier section (Opening the SA).
- 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
- pod name:
- 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'
orplatform :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'
- For example, to use version 1.1.3 or higher, but lower than 1.2.0, you can change the pod line to:
- The pod line
- Continue with the steps in the previous section (SA usage) to install the SDK via CocoaPods.
- Open the SA in Xcode as detailed in the earlier section (Opening the SA).
- For adding the SDK via SPM, please follow the instructions here.
- Before running the SA, it is recommended to populate the Millicast credentials in the Constants.swift file.
- It is also possible to enter or change the credentials when the SA is running, at the Settings page.
- On Xcode, click on the Run button to run the SA on the device of your choice.
- To publish video, a device with a camera is required. Simulators will therefore not be able to publish video.
- Ensure the publishing credentials are populated.
- Go to the Publish page.
- If desired, tap on the camera description and/or resolution description to cycle through the available cameras and resolutions.
- 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.
- If desired to switch to another camera, click on "Switch Camera".
- 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).
- Click "Publish" to publish the captured video to Millicast.
- To stop publishing, click "Stop Publish".
- Ensure the subscribing credentials are populated.
- Go to the Subscribe page.
- Click "Subscribe" to start subscribing to the Millicast stream specified at Settings page.
- 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.
- To stop subscribing, click "Stop Subscribe".
- 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.
- The following values for the Subscriber Token field are acceptable:
- More details on Subscribe Token here.
- 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()