Contextual (iOS 15+) Setup¶
You can find an example of integration here
Prerequisites¶
- Deployment target iOS 15.0 and above.
- Xcode 13.4.1 or above.
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.
CocoaPods¶
Step 1 - Pod File¶
In pod file of your Application, add the following line:
1 2 3 |
|
Step 2 - Install¶
On the first time, run:
1 |
|
For updates and ensuring to get the latest version of the Contextual SDK, run:
1 |
|
Note
If you have used cocoapods previously, please run either "pod update" or "pod update Contextual --no-repo-update", this will ensure that the most recent version of the Contextual SDK is integrated.
Swift Package Manager¶
Step 1 - Add Package Dependency¶
Add Contextual SDK as a Swift Package Manager dependency
1 |
|
For Version Rules, you can use:
1 |
|
1 |
|
Integration Steps¶
Step 1 - Register an install during app launch¶
In your Application launch function, add Contextual registration.
Import the Contextual SDK:
Swift
1 |
|
Objective-C
1 |
|
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 14 15 16 |
|
Note
React Native users - make sure the #import "ContextualSDK/ContextualSDK.h"
is above the #if DEBUG or #ifdef FB_SONARKIT_ENABLED
declaration (if present)
Objective-C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
Step 2 - Replace Base Classes¶
iOS Native¶
UIKit¶
Replace the base ViewController classes and inherit from Contextual SDK classes as shown below.
From | To |
---|---|
UITableViewController | ContextualBaseTableViewController |
UIViewController | ContextualBaseViewController |
UICollectionViewController | ContextualBaseCollectionViewController |
Swift UI¶
If you are using primarily Swift UI for your screens and views, then you will need to implement the UIViewControllerRepresentable
protocol on your Swift UI View that is being used as a screen.
Example:
If you have a Swift UI View named "TicketListViewVC" that is acting as a screen for your app, then you should implement the UIViewControllerRepresentable
protocol as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
!!! note For a sample project to see how the Contextual SDK was implemented into a Swift UI project, see: https://github.com/contextu-al/FlightTicketBrowser
React Native¶
In your AppDelegate.m where the rootViewController
is created, replace UIViewController with ContextualBaseViewController
React Native < v0.71.0:
1 2 3 4 5 |
|
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 |
|
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 3 - 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 |
|
Objective-C
1 2 3 4 |
|
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 |
|
Objective-C
1 2 |
|