Skip to content

Adding libPusher to your project

lukeredpath edited this page Feb 1, 2012 · 18 revisions

There are a number of ways in which you can add libPusher to your project. This page documents how to get up and running with libPusher as quickly as possible.

Downloading libPusher

First of all, you need to decide whether or not you want to use the latest version from source or download a pre-compiled static library. Downloading a pre-compiled static library is the quickest way to get up and running, however depending on how you manage your project (e.g. if you use CocoaPods or git submodules) you may want to use one of the alternative methods below.

Using a pre-compiled static library

On the project Downloads page, you'll find a couple of different packages to download. Most people will want to grab the latest stable release, however there is also an automated nightly build if you want to run a bleeding-edge version.

Contained within each download package are a number of static libraries and a collection of header files. For more information, read the README file contained within the download.

Most people will want to use the combined fat static library. Simply copy libPusher-combined.a and the contents of the headers directory into your Xcode project and then:

  • Under the Build Phases tab for your target, expand "Link Binary With Libraries" and if libPusher-combined.a isn't there already, click the + symbol and add it.

  • Locate the "Other Linker Flags" build setting for your target and add -all_load.

You should now be able to build your project.

Important note: if you are using the pre-compiled static library and you are using the libraries JSONKit or CocoaAsyncSocket in your project already, you will need to remove the implementation files for these libraries from your project as they are already compiled into the libPusher binaries. Leaving these files in your project will result in duplicate symbol errors from the linker. You should however leave the header files in your project in order to use them in your own source files.

Adding libPusher to your project using CocoaPods

CocoaPods is an Objective-C package manager; if you are familiar with the Rubygems eco-system, it is somewhere between Rubygems and Bundler - it allows you to manage all of your project dependencies using a simple manifest file. For more information on getting up and running with CocoaPods, you should read the documentation.

Assuming you do not have a Podfile in your project root already, go ahead and create one:

platform :ios
dependency 'libPusher', '1.0'

You can now use pod to install libPusher:

$ pod install

If this is the first time you've used CocoaPods for your project, an Xcode workspace containing your project and the Pods project will have been created. If you open this workspace file in Xcode, you should now be able to build your project - the Pods dependencies (including libPusher) will be compiled into a static library and linked to your own app/target.

Compiling libPusher from source

If you require a recent version of libPusher, you are advised to use the nightly build, available on the Downloads tab. If you would like to compile libPusher from source yourself, there are a few things you need to know.

First of all, libPusher itself uses CocoaPods to manage it's dependencies. You can view a list of it's dependencies by viewing the contents of the project's Podfile.

In order to install the project dependencies, you will need a working installation of MacRuby (I recommend one of the nightly builds, as I have experienced problems with the last stable release, 0.10).

The project also contains a Rakefile and some Ruby scripts in Scripts for running various automated tasks and booting up a dummy authorisation server for testing presence and private channels with the bundled sample app. The Rakefile and these scripts rely on various Ruby gems to run and these gems are managed using Bundler. It is recommended that you switch back to Ruby 1.9.x (MRI) to use these scripts. Run bundle install to install the necessary gems.

Because you will need to use MacRuby to use CocoaPods, and standard Ruby (1.9.x) to build from the command-line and run the other bundled scripts, it is recommended that you install MacRuby nightly using RVM so you can switch between the two. The bundled build scripts depend on rvm to switch between Ruby interpreters.

Building from Xcode

To build from Xcode, all you need to do is set up the CocoaPods dependencies as explained above, then open libPusher.xcworkspace. Make sure the libPusher scheme is selected and hit Build.

Building from the command-line

Having set up CocoaPods, you should be able to run build.sh. The script will do the following things:

  • Switch to MacRuby using rvm, update it's gem dependencies using Bundler and update the project pods using pod install
  • Switch back to the default Ruby using rvm, update it's gem dependencies using Bundler and run the release:combined Rake task.

The release:combined Rake task will build libraries for the simulator and device and combine them into a single fat library using lipo. This is the same process that is used to build and deploy the nightly automated release.