WebRTC on iOS: setup the library

Standard

Setup environment

Install depot tools following this link.

Download WebRTC pod

Download pre-built WebRTC library for iOS is done by using CocoaPods.  To do so, one must first initializes ‘pod’ within your Xcode project top-level directory:

$ pod init       # create Podfile

The above command will generate an ’empty’ Podfile.  Now edit the Podfile so it has the following contents:

source 'https://github.com/CocoaPods/Specs.git'
target 'YOUR_APPLICATION_TARGET_NAME_HERE' do
platform :ios, '9.0'
pod 'GoogleWebRTC'
end

Now update Pod Specs and install WebRTC:

$ pod update
$ pod install

Get and build WebRTC source

To get the source code for example iOS application, do the following:

$ fetch --nohooks webrtc_ios
$ gclient sync

To create a new branch for yourself:

$ git new-branch 

Now let’s build a sample app called AppRTCMobile to run on iPhone:

$ gn gen out/ios_64 --args='target_os="ios" target_cpu="arm64"'

or

$ gn gen out/ios_sim --args='target_os="ios" target_cpu="x64"'

for running on iPhone simulator.

In the above commands, GN is a CMake equivalent, and ‘target_cpu=arm64’ is for running on iPhone because it has a 64-bit ARM processor; and ‘target_cpu=x64’ is for running on iPhone simulator on a Mac.

After the GN step, we are ready to ‘make’ equivalent command, ‘ninja’.

$ ninja -C out/ios_64 AppRTCMobile

Or for simulator,

$ ninja -C out/ios_sim AppRTCMobile

The ‘ninja’ step will build the ‘AppRTCMobile.app’ that can be loaded onto a simulator or to load onto an actual iPhone target. To load onto a simulator, start simulator under Xcode->Open Developer Tools->Simulator, then in Simulator, find Hardware->iOS 11.2->iPhone 6s. You can replace “iOS 11.2” with other version of iOS, and “iPhone 6s” with other targets. Now, with Simulator running, run the below to find the iPhone ID, you will get something like this:

$ xcrun simctl list | grep "iPhone 6s"
iPhone 6s (com.apple.CoreSimulator.SimDeviceType.iPhone-6s)
iPhone 6s Plus (com.apple.CoreSimulator.SimDeviceType.iPhone-6s-Plus)
iPhone 6s (631A7702-413A-45D4-9265-5D04162EA1B9) (Booted)
iPhone 6s Plus (8986A95B-3F02-4230-BBEC-D58F9BCE6130) (Shutdown)
iPhone 6s (8EC2C223-57CC-4993-BA89-8703381C054C) (Shutdown) (unavailable, runtime profile not found)
iPhone 6s Plus (BEAC79E7-51F4-44D0-8049-B1E5F0E43BEF) (Shutdown) (unavailable, runtime profile not found)
iPhone 6s (75CC9807-BB0D-4344-B30F-40C44D5C14D3) (Shutdown) (unavailable, runtime profile not found)
iPhone 6s Plus (A9857F88-93E7-4D07-98B8-F02A93AC4844) (Shutdown) (unavailable, runtime profile not found)
iPhone 6s (F3E4EFAC-CCCB-4A8E-8AF9-FAFF069F2403) (Shutdown) (unavailable, runtime profile not found)
iPhone 6s Plus (B87D5A45-1786-44C5-ABF7-D6753187E214) (Shutdown) (unavailable, runtime profile not found)
iPhone 6s (A446BA65-737A-47DB-B1A8-05C409ACA90D) (Shutdown) (unavailable, runtime profile not found)
iPhone 6s Plus (7EC178BB-7DD6-4998-8048-EE5BF58E8A58) (Shutdown) (unavailable, runtime profile not found)

Notice one iPhone 6s is booted, while others are not. Select that iPhone’s ID, which is 631A7702-413A-45D4-9265-5D04162EA1B9. Now you can install AppRTCMobile.app this way:

$ xcrun simctl install 631A7702-413A-45D4-9265-5D04162EA1B9 ./AppRTCMobile.app

Screen Shot 2018-03-12 at 1.13.14 AM

References