Installing Twilio Client for iOS using CocoaPods

When I first started digging into writing apps for the iPhone, one of the first things I looked for in Xcode was some kind of package manager.  It being the 21st century, I thought that obvious that nearly every IDE would have some kind of package manager built in, but to my surprise I found nothing in Xcode.  But my search did not end there.  I could not believe that iOS developers lived without a package manager of some kind.  Thankfully a search on Google told me about CocoaPods, a great package manager for iOS developers that makes it pretty quick and painless to install and manage project dependencies.

After discovering CocoaPods, my next thought was “OK, why doesn’t Twilio have a CocoaPods package for our Twilio Client for iOS library?”.  So I set out to make one and in this post I’ll show you how you can use it to make installing Twilio Client for iOS into your Xcode project a snap.

Getting Going with CocoaPods

Installing CocoaPods is pretty straight forward.  It’s a ruby gem and the CocoaPods website has great instructions on installing and using it from the command line.
Once you have CocoaPods installed, all you need to do to add dependencies to your project is to create a podfile in your Xcode project directory and include the packages you want to install.  For example, if you wanted to add Twilio Client to your project, your podfile would look like this:

The platform value tells CocoaPods to use libraries built for iOS 5 or greater and the pod value tells CocoaPods to install the TwilioSDK pod, which contains Twilio Client for iOS. If you had other libraries that you wanted to use in your project you can add those by adding multiple pod values in your podfile.

Once you’ve created the podfile, make sure Xcode and any simulators are closed and then back head over to the command line and navigate to your Xcode projects directory. Once there, install the pods using the command:

That’s all there is to it. Once CocoaPods finishes installing the pods, you can open your project by using the new workspace that was created by CocoaPods and check out what each library added.

Let’s take a quick look at what the Twilio Client for iOS pod adds to a project.

When you open your project in Xcode you’ll see a new Pods project is included in the workspace. This is where CocoaPods installs library files. If you expand the folders in the Pods project you can see that CocoaPods added a number of Frameworks, the header files for the Twilio Client library, and a bunch of WAV files that the library uses for sounds. The static libraries are also there, just not directly referenced in the project.

One Last Step

While CocoaPods does a great job at simplifying the install of the Twilio Client for iOS SDK, there is unfortunately one thing that CocoaPods cannot do. In order to let iOS know that this app is a VoIP application and will need Audio even when the application is running in the background, you need to add two values to your applications plist file. Without these, if a user places your app into the background while its connected to Twilio, the calls audio will stop, but the call continues. The user would have to reactive the app in order to continue the call.

The image below shows using the Property List editor to add the Audio and Voip values to the Required background modes key in a project’s plist file:
And now with the Twilio Client library now fully installed in the Pods project, and the plist values added, you can use the library’s APIs to write code that can make and receive VoIP calls without ever leaving your app.

  • Hi, I’m having issues installing Twilio in one of my iOS projects.

    The compile error is the following:

    Undefined symbols for architecture i386:
    “_OBJC_CLASS_$_TCDevice”, referenced from:
    objc-class-ref in TwilioPhone.o
    ld: symbol(s) not found for architecture i386
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    Do you know what could be wrong?

    • Troy

      I have the same issue. Did you resolve it?

      • fahad

        You just need to add these files to your project; you can find them in the sdkfolder


        good luck

    • My fix is to manually add the libraries to the list of Frameworks. Here’s the procedure:

      * Open the workspace in Xcode
      * Click on Pods project
      * Click on “Build Phases”
      * Expand “Link Binary with Libraries”
      * Click on “+” icon
      * Click “Add Other” button in the resulting dialog
      * Browse for the following files to add: libcrypto.a, libssl.a, libTwilioClient.a (they can be found in Pods/TwilioSDK/Libraries after you ran pod install)