IOS-how-to-connect-Quickblox-framework

Ask tech team
From QuickBlox Developers (API docs, code samples, SDK)
Jump to: navigation, search

Contents

Connecting QuickBlox Framework with Your Project

There are 2 ways of adding Quickblox framework:

CocoaPods

Make sure that you have CocoaPods installed.

Open your Podfile and add following line for dynamic framework (iOS 8+):

pod 'QuickBlox'

Add the following script for dynamic framework.

Or add following line for static framework (iOS 7+):

pod 'QuickBlox-static'

Than open Terminal go to your project folder with Podfile and run:

pod install

That's all! Now you have connected Quickblox Framework to Your Project.

Manual installation

  1. Download iOS SDK
  2. Unzip the file. Open Framework folder - inside it you will see Quickblox.framework file.
  3. Open existing or create a new project in Xcode
  4. Drag & drop Quickblox.framework folder to Frameworks folder in your Xcode project:
  5. IOS QB framework connect.jpg

  6. Add #import <Quickblox/Quickblox.h> to *-Prefix.pch file:
  7. IOS QB framework connect2.jpg

  8. Link with CFNetwork, SystemConfiguration, MobileCoreServices, CoreGraphics, CoreLocation, CoreData, AudioToolbox, CoreMedia, Accelerate, CoreVideo, AVFoundation, Security, libz, libresolv, libxml frameworks:
    1. Open the settings for your target by clicking on the blue bar at the top of the Xcode sidebar:
    2. Main file SuperSample.jpg

    3. Open the Build Phases tab, expand the box Link Binary With Libraries, then click the + button:
    4. Add linked library.jpg

    5. Choose CFNetwork.framework from the list and click Add:
    6. Cf network.jpg

    7. Repeat the last two steps to add the following: SystemConfiguration.framework, MobileCoreServices.framework, CoreGraphics.framework, CoreLocation.framework, CoreData.framework, AudioToolbox.framework, CoreMedia.framework, Accelerate.framework, CoreVideo.framework, AVFoundation.framework,QuartzCore.framework, Security.framework, libz.tbd (libz.dylib in Xcode6), libresolv.tbd (libresolv.dylib in Xcode6), libxml.tbd (libxml.dylib in Xcode6)

  9. Add -lxml2, -ObjC, -lstdc++ flags to Other Linker Flags section in project settings
  10. IOS SDK objCflag.png

  11. Add /usr/include/libxml2 to Xcode Header search path
  12. Enjoy it!

Dynamic framework

For dynamic framework add Quickblox as Embedded binary:

EmbeddedBinary.png

And add a Run Script Phase.

Run Script Phase for Dynamic framework

For dynamic framework add a "Run Script Phase" in build phases of your project. Past the following snippet in the script:

bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Quickblox.framework/strip-framework.sh"

This fixes a known Apple bug, that does not allowing to publish archives to the App store with dynamic frameworks that contains simulator platforms. Script will only work for archiving.


Enable the cloud backend for your iOS app

Your app needs to have the unique ID and authentication keys to access its own cloud backend, authenticate API calls, store and retrieve data. Simply follow the steps below to get it sorted.

  1. Register an account at admin.quickblox.com
  2. Log in and create an application (admin.quickblox.com). Click on your newly created app's title and you will see:
    1. Application id
    2. Authorization key
    3. Authorization secret
  3. Follow the instructions above add QuickBlox iOS SDK framework to your empty Xcode or an existing project
  4. Add the following lines to AppDelegate:
    1. [QBSettings setApplicationID:your_app_id;
    2. [QBSettings setAuthKey:@"your_app_service_key"];
    3. [QBSettings setAuthSecret:@"your_app_authorization_secret"];
  5. Go to admin.quickblox.com/account and copy Account Key: [QBSettings setAccountKey:accountKey];
  6. That's all - your app has its own cloud backend enabled!
  7. Note2: in case you want to use Messages module (integrate push notifications, for example) you will then need to:
    1. Create APNS certificates and upload them to admin panel - please check this tutorial
    2. Use valid Provisioning Profiles for your project


Additional steps for Swift using CocoaPods

After completing the steps above you should create a Bridging header.

Assuming you have created empty swift project and executed pod install QuickBlox.

1. Create a header file which will be used as a bridging header.

Step1swift.png

Replace content of created Bridging-Header.h with

#ifndef Bridging_Header_h
#define Bridging_Header_h
 
#import <Quickblox/Quickblox.h>
 
#endif /* Bridging_Header_h */

2. In the target in Build Settings set Objective-C Bridging Header

Step2swift.png

3. The project structure should look like on the screenshot below

Step3swift.png

4. That's all! Now you have connected your swift project with QuickBlox framework

AppDelegate.swift

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {	
    QBSettings.setApplicationID(92)
 
    return true
}

Additional steps for Swift using Manual Installation

Assuming you have created empty swift project and downloaded Quickblox.framework

1. Drag-n-drop Quickblox.framework and select "Copy items if needed"

CopyItemsIfNeeded swift.png

Xcode automatically links the framework.

2. Change AppDelegate.swift


import Quickblox
 
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {	
    QBSettings.setApplicationID(92)
 
    return true
}

3. Add the following items in Build Phases

CFNetwork.framework

libxml2.tbd

libresolv.tbd

MobileCoreServices.framework

SystemConfiguration.framework

IOSQBframeworkconnect swift.png

4. That's all!

Good luck with your app!