Build

Setup Pubnub on iOS in 7 Minutes Using CocoaPods

2 min read PubNub Staff on Jan 6, 2016
Try PubNub Today

Free up to 1MM monthly messages. No credit card required.

Subscribe to our newsletter

By submitting this form, you are agreeing to our Terms and Conditions and Privacy Policy.

This week, Jordan Zucker, iOS maestro at PubNub, shows us just how simple it is to get PubNub up and running in a brand-new iOS project using CocoaPods.  Here's the rundown: Download the iOS Getting S...

This week, Jordan Zucker, iOS maestro at PubNub, shows us just how simple it is to get PubNub up and running in a brand-new iOS project using CocoaPods.  Here’s the rundown:

Download the iOS Getting Started Git Repository from the video

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects that makes it super easy to add and update 3rd party libraries in iOS projects. This is by far the best way to load PubNub’s iOS SDK.

Without CocoaPods, adding a 3rd party library to an iOS project can take up to 40 minutes, assuming you know what you’re doing. CocoaPods cuts this down to only 2-3 minutes, so you can spend that time doing something more productive, like building your cool app.

There’s not a whole lot to it, really. Just a few simple steps:

  1. Create project in Xcode
  2. Close project (project must be closed for the following steps)
  3. Create Podfile
  4. Run pod install from command line within project repository
  5. Open up a newly created workspace (in this case Example.xcworkspace)
  6. Navigate to ViewController.m
  7. Add #import <PubNub/PubNub.h>
  8. Add @property (nonatomic, strong) PubNub *client;
  9. Add PNObjectEventListener protocol to ViewController.m
  10. Initialize PubNub client instance using your pub and sub keys. Assign it to self.client instance variable
  11. Register ViewController as a listener for PubNub subscribe callbacks
  12. Subscribe to test channel
  13. Add label and button properties to ViewController class (declare them as IBOutlets)
  14. Update label with message from - (void)client:(PubNub *)client didReceiveMessage:(PNMessageResult *)message callback
  15. Add IBAction for button. Implementation should publish “Hello, world!” string on same test channel
  16. Connect button, label, and action in Main.storyboard
  17. Run on sim and click button to see the result!

This is only a simple walkthrough that shows you how to get PubNub up and running with a simple publish-subscribe function. For more in-depth information, visit our docs page for the PubNub iOS SDK. Happy coding!

More from PubNub

Top Trends to Engage Your App Users
InsightsSep 27, 20224 min read

Top Trends to Engage Your App Users

Take a look at the top trends that are the most effective in attracting customers and reducing churn, and how you can incorporate...

PubNub Staff

PubNub Staff

Comparing Game Engines: Unity vs Unreal vs the Rest
Real-Time Gaming BlogSep 21, 20225 min read

Comparing Game Engines: Unity vs Unreal vs the Rest

Comparing the major game engines: Unity vs Unreal Engine vs Corona SDK vs GameMaker Studio, including the benefits and cons of...

PubNub Staff

PubNub Staff

Python Socket Programming: Client, Server and Peer Libraries
BuildSep 21, 20226 min read

Python Socket Programming: Client, Server and Peer Libraries

Sockets (aka socket programming) enable programs to send and receive data, bi-directionally, at any given moment. This tutorial...

PubNub Staff

PubNub Staff