Skip to content

Contextual (iOS 13+) Setup

You can find an example of integration here

Prerequisites

  • Deployment target iOS 13.0 and above.
  • Latest Xcode.


Note

If using an Apple Silicon Mac, you will likely need to use a Rosetta terminal when installing dependencies or at least prefix your terminal commands with "arch -x86_64".

e.g. arch -x86_64 pod update


This setup assumes you have already setup your App Key on the Dashboard.

See prerequisites.

CocoaPod Integration Steps

Step 1 - Pod File

In pod file of your Application, add the following line:

1
2
platform :ios,'13.0' # or above
pod "pointzi"

Step 2 - Install

On the first time, run:

1
pod install

For updates and ensuring to get the latest version of the Contextual SDK, run:

1
pod update
This installs Contextual binary and dependencies.

Note

If you have used cocoapods previously, please run either "pod update" or "pod update pointzi --no-repo-update", this will ensure that the most recent version of the Contextual SDK is integrated.

If you are using Swift, add :

1
#import "StreetHawkCore_Pointzi.h"
in your Swift bridge header file <Your_Project_Name>-Bridging-Header.h.

Step 3 - Initialization

In your Application launch function, add Contextual registration.

If you are using Swift, Add the following code in AppDelegate

Swift 
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
{
    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
    {
        // Replace 'MyApp' with your app_key, registered in the Contextual Dashboard.
        Pointzi.sharedInstance().registerInstall(forApp: "MyApp", withDebugMode: false)
        // Set 'withDebugMode' to 'true' to enable debug logging.
        return true
    }
}

If you are using ObjectiveC - React Native, Add the following code in AppDelegate, make sure the #import "StreetHawkCore_Pointzi.h" above the #if DEBUG or #ifdef FB_SONARKIT_ENABLED declaration (if present):

Objc 
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#import "StreetHawkCore_Pointzi.h"

#ifdef FB_SONARKIT_ENABLED // IMPORTS MUST GO ABOVE THIS DECLARATION
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Replace 'MyApp' with your app_key, registered in the Contextual Dashboard.
    [POINTZI registerInstallForApp:@"MyApp" withDebugMode:NO];
    // Set 'withDebugMode' to 'YES' to enable debug logging.
    return YES;
}

Step 4 - Replace Base Classes

iOS Native

Replace the base ViewController classes and inherit from Contextual SDK classes as shown below.

From To
UITableViewController StreetHawkBaseTableViewController
UIViewController StreetHawkBaseViewController
UICollectionViewController StreetHawkBaseCollectionViewController

React Native

In your AppDelegate.m where the rootViewController is created, replace UIViewController with StreetHawkBaseViewController

React Native < v0.71.0:

1
2
3
4
5
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  //Replace UIViewController with StreetHawkBaseViewController
  UIViewController *rootViewController = [StreetHawkBaseViewController new];
}

React Native >= v0.71.0:

There is a new delegate method for customising the root view, so implementat that and specify the base class for the View Controller:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
- (UIView *)createRootViewWithBridge:(RCTBridge *)bridge
                          moduleName:(NSString *)moduleName
                           initProps:(NSDictionary *)initProps
{
  UIView * rootView = [super createRootViewWithBridge:bridge moduleName:moduleName initProps:initProps];

  UIViewController *rootViewController = [StreetHawkBaseViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;

  return rootView;
}

Info

If your view controller overrides system functions, make sure you call super.

Note

Replacing your view controller with the Contextual controller is essential for Contextual to function correctly. Please ensure that if you have multiple view controllers showing on the same screen to replace the base ViewController in each of the UIViewController subclasses (child ViewControllers)

Step 5 - Set sh_cuid [Optional]

We recommend you also send a unique ID for the user so you can "tag" users from your backend system. This is called the sh_cuid.

If you would like to tag the user during registration just place the following snippet.

Swift 
1
2
3
4
//unique id in your system, for example customer's login id
Pointzi.sharedInstance().registerInstall(forApp: "MyApp", withDebugMode: false) {
    Pointzi.sharedInstance().tagUserId("user@example.com")
}
Objc 
1
2
3
4
//unique id in your system, for example customer's login id
[POINTZI registerInstallForApp:@"MyApp" withDebugMode:NO completion:^{
    [POINTZI tagUserId:@"user@example.com"];
}];

If you would like to tag the user at any other place in your application eg after login call, just place the following snippet.

Swift 
1
2
//unique id in your system, for example customer's login id
   Pointzi.sharedInstance().tagCuid("user@example.com")
Objc 
1
2
//unique id in your system, for example customer's login id
    [POINTZI tagCuid:@"user@example.com"];

Without Cocoapod

Dependencies

Before you can integrate the Contextual Framework you need to include the following libraries and frameworks in your project.

  • libxml2.dylib
  • UIKit
  • libsqlite3
  • CoreTelephony
  • Foundation
  • CoreGraphics
  • CoreSpotlight

Tip

Click "+" button of section Linked Frameworks and Libraries on general tab of your target to add the libraries.

Note

If your app is a swift project, please make sure you add -ObjC into your app target's Other Linker Flags under Build Settings.

Dynamic Framework

  • Download and extract [pointzi-framework-2.2.0.zip] (https://repo.pointzi.com/sdk/pointzi/ios/2.2.0/2.2.0/pointzi-framework-2.2.0.zip).
  • Drag & drop StreetHawkCore_Pointzi.framework into your app project.
  • Go to the target general tab.
  • Add the Contextual framework to the Embedded Binaries
  • Download the resources corresponding to the resource bundle Pointzi.bundle to the same path as the framework.
  • Add this resource using Copy Bundle Resources option under Build Phases of your app target.
  • Now you should be able to call Contextual api by importing headers like
1
#import <StreetHawkCore_Pointzi/StreetHawkCore_Pointzi.h>

Static Library

  • Download and extract [pointzi-2.2.0.zip] (https://repo.pointzi.com/sdk/pointzi/ios/2.2.0/2.2.0/pointzi-2.2.0.zip).
  • Drag & drop the Pointzi folder into your app project.
  • Ensure you added libPointzi.a in the folder into your app target Link Binary With Libraries under tab Build Phases.
  • Download the resource corresponding to the resource bundle Pointzi.bundle to the same path of framework (or just add resources from folder assets into Build Phases).
  • Add this resource using Copy Bundle Resources option under Build Phases of your app target.
  • Now you should be able to call Contextual api by importing headers like.
1
#import "StreetHawkCore_Pointzi.h"

Last update: 2024-01-15