Skip to content

Instantly share code, notes, and snippets.

@scalabl3
Last active April 15, 2017 02:34
Show Gist options
  • Save scalabl3/8da810423f868b8fd81a to your computer and use it in GitHub Desktop.
Save scalabl3/8da810423f868b8fd81a to your computer and use it in GitHub Desktop.
Manual Setup of PubNub SDK in Xcode

Getting Setup with PubNub Manually for iOS

Additional Reference: PubNub Github Repo README Instructions

Important Notes

Make sure that your iOS project (.xcodeproj) is within a Xcode Workspace (.xcworkspace). Being in a workspace rather than a project changes Xcode behavior when drag-dropping files.

If you are only in an .xcodeproj, then it doesn't prompt you with options to "copy items if needed" and automatically creates symlink rather than copy files into project (hence being susceptible to the changes in the original PubNub project).

Copy Items Option

Step 1 - Setup XCode Workspace and iOS Project

  1. File ... New > ... Workspace ( ^⌘N )
  2. You can right click and click on New Project...
  3. If you already have an iOS Project, you can create a workspace in same folder and add the project by clicking on left side and Add files to Project
  4. Destination: Check Copy items into destination group's folder (if needed)
  5. Folders: Select Create folder references for any added folders

New Workspace New Workspace

New Project New Project

Add Project to Workspace Add Files

Add Project to Workspace Add Project

Step 2 - Clone PubNub Objective-C SDK

  1. Download/Clone PubNub iOS SDK in a separate folder from your workspace/project Github Repo

Step 3 - Compile PubNub SDK

  1. You can either add the PubNub project to your workspace, OR, just open the PubNub .xcodeproj and build it
  2. In either case, you will generate files in the Products subfolder:
  3. libPubNub.a
  4. PubNub.bundle

Step 4 - Copy to iOS Project

  1. From built PubNub SDK Products subfolder, Right click on libPubNub.a and click "Show in Finder"
  2. Create folder in Frameworks
  3. In Finder, Highlight PubNub.Framework and PubNub.bundle
  4. Copy the files over into your iOS Project in the Frameworks folder

Copy Files

Files Copied

Step 5 - Create Swift/Objective-C Header Bridge File

  1. Add a new .h (header) file to iOS project, I named it BridgeHeader.h
  2. Add import statement
#ifndef manual_test_BridgeHeader_h
#define manual_test_BridgeHeader_h
#import <Pubnub/PNImports.h>
#endif

BridgeHeader.h

Step 6 - Add Swift/Objective-C Header Bridge File to Build Settings

  1. Click on Project Name, select Build Settings, Search for "Bridging"
  2. Click on blank space to right of Objective-C Bridging Header
  3. Type full path to BridgeHeader.h

BridgeHeader Setting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment