iOS AppRTC Deep Dive (Pt. 1)
At Pristine, we use WebRTC in our EyeSight mobile applications. Our target markets are healthcare physicians and hospitals, meaning we have to comply with HIPAA. Research shows that iOS is used by 68% of healthcare physicians [May 2013] in the United States, so HIPAA compliance (by way of WebRTC support) on iOS is mission critical.
Understanding the Build Process
The iOS build process is nearly identical to the Android build process, with a few slight changes.
1. Set the target_os=['mac']
initially, then re-sync with target_os=['ios', 'mac']
- WEBRTC_DEBUG=true
is set by default
2. Incorporate static libraries instead of shared objects (Apple requires static libraries)
- Copy the libWebRTC-LATEST-Universal-Debug.a & public *.h files into your xcode project
3. Automatically generate a fat *.a library for ARMv7 & x86 (ia32) in webrtc/libWebRTC-LATEST-Universal-Debug.a
4. The headers needed are referenced in webrtc/headers
after a build
Obtaining the scripts
Clone/Pull from our Build Scripts GitHub repo:
git clone https://github.com/pristineio/webrtc-build-scripts.git
Shoutout to those who just need to pull instead of clone :) you know who you are
Executing build scripts via terminal
This has been tested on a Retina MacBook Pro Running OSX 10.9.3
- Set the
WEBRTC_DEBUG
,WEBRTC_RELEASE
, orWEBRTC_PROFILE
environment variable totrue
if you want to build that type. - Source the iOS build scripts by pasting this into the terminal.
# Add helper functions to your environment
source ios/build.sh
# Clone, make, compile (WebRTC)
dance
That's it!
The build dance process takes quite a bit of time. First the, scripts will clone WebRTC (~2 GB of data), then will compile for Debug mode for the Simulator (ia32) and ios (ARMv7) devices (>4000 object files, millions of lines of code).
Executing build scripts via xcode
- Open ios/WebRTC.xcodeproj in xcode or type
open ios/WebRTC.xcodeproj
in the terminal - Open the Schemes List:
- Set the active scheme to WebRTC Dance: (32 or 64 bit, it is ignored)
- Optionally to build for profile or release, edit the scheme and add the runtime environment variables for WebRTC Dance scheme
WEBRTC_RELEASE
orWEBRTC_PROFILE
with the value set totrue
- Build and run the current scheme (WebRTC Dance) by clicking the Play button
This will effectively runsource build.sh
anddance
in an bash console printing to xCode - Monitoring the progress of the build:
- Click on the Log Navigator
- Click on the most recent WebRTC Dance Debug
- If you see a spinning wheel on the right side next, that means it is still running.
- This download will take about 2 GB of space on your system. YMMV on download times
- Log messages similar to these means that the build process is downloading from Google Code
A trunk/webrtc/modules/audio_processing/aec/aec_resampler.c
A trunk/talk/p2p/base/p2ptransportchannel.h
- Log messages similar to these mean that the build system is compiling
[440/2210] CC obj/third_party/icu/source/common/icuuc.cmemory.o
[906/2210] RULE Compile assembly source/libvpx/vp8/common/x86/loopfilter_sse2.asm
[2016/2210] CXX obj/webrtc/voice_engine/voice_engine.voe_network_impl.o
[2208/2210] LIBTOOL-STATIC libjingle_peerconnection_objc.a, POSTBUILDS
[2171/2210] OBJCXX obj/talk/app/webrtc/objc/libjingle_peerconnection_objc.RTCEnumConverter.o
- Log messages similar to these means that the build process is downloading from Google Code
- Usually the compile process takes ≥10mins on an Intel Core i7 and ≥20 mins on an Intel Core i5
- Near the end of a successful build, you will see a message on the console or logs about some simulator file not having symbols near the end of the script. A
Finished Dancing!
message immediately follow.
- Click on the Log Navigator
Executing AppRTCDemo via Xcode
With WebRTC binary+headers already built and resolved, Xcode can now resolve the missing AppRTCDemo Objective-C code.
- Open the Schemes List:
- Hover over the AppRTCDemo Scheme:
- Select any iPhone or iPad (real or simulator)
- Build and run the AppRTCDemo scheme
- Wait for build to finish (Should be quick, WebRTC is already precompiled)
- AppRTCDemo should launch on either simulator or real ios device -- Success!
Developing like an iOS Developer
Including the RTCPeerconnection API in your own *.xcodeproj
Option 1 - Cocoapods (maintainable)
Note: There is a known bug because I hit the filesize limit on the bitbucket repo. I am working with the cocoapods team to move this to an HTTP source. Will update again soon.
libjingle_peerconnection is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod "libjingle_peerconnection"
# Add this to the bottom so it won't have issues with active architecture
post_install do |installer_representation|
installer_representation.project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
config.build_settings['VALID_ARCHS'] = ['armv7', 'i386']
end
end
end
That's it!
I started the builds at r6798, so make sure you set the revision you want.
Also, the Cocoapods based AppRTCDemo can be found here.
Option 2 - Integrate into your own project (not as maintainable)
Take a look at the AppRTCDemo for extra tips
-
Copy all the files from the ~/webrtc/headers into your Xcode project. It is up to you if you want to copy into the project itself (Probably yes).
-
Copy the static library from webrtc/libWebRTC-LATEST-Universal-Debug.a into your xcode project. It is up to you if you want to copy into the project itself (again, probably yes).
-
Go to the target settings in Xcode, Build Phases
-
Under Link Binary With Libraries, make sure you have these on the list, Otherwise add them:
- Foundation.framework
- AVFoundation.framework
- CoreGraphics.framework
- CoreMedia.framework
- GLKit.framework
- libc.dylib
- libsqlite3.dylib
- libstdc++.6.0.9.dylib
- libWebRTC-LATEST-Universal-Debug.a
- UIKit.framework
-
At this point you should be able to make any WebRTC calls using the peer connection library. Simply
#import
any files you need from the WebRTC Objective-C public headers.
Happy Building!
P.S. We're pleased to announce our new Pristine baby, Bot the Builder! He's so cute, he builds, tests and merges in our code!