Initialize the iOS SDK
Before you begin
This guide assumes that you are familiar with CocoaPods or Swift Package Manager and know how to install dependencies for iOS development. For more information, check out CocoaPods' or Swift Package Manager's user guides.
CocoaPods guide
Set up a workspace using this CocoaPods tutorial.
- Add the
Rokt-Widget
pod to the pod file:
pod 'Rokt-Widget'
- Install the pod:
pod install
If you receive the DT_TOOLCHAIN_DIR cannot be used to evaluate LIBRARY_SEARCH_PATHS use TOOLCHAIN_DIR instead
error, add the following post install hook to your Podfile
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
xcconfig_path = config.base_configuration_reference.real_path
xcconfig = File.read(xcconfig_path)
xcconfig_mod = xcconfig.gsub(/DT_TOOLCHAIN_DIR/, "TOOLCHAIN_DIR")
File.open(xcconfig_path, "w") { |file| file << xcconfig_mod }
end
end
end
Swift Package Manager guide
In Xcode:
- Go to File > Add Package Dependencies
- Add
https://github.com/ROKT/rokt-sdk-ios.git
- Select Up to Next Major with 4.7.0
or add below code to the dependencies
part of Package.swift
.
dependencies: [
.package(url: "https://github.com/ROKT/rokt-sdk-ios.git", .upToNextMajor(from: "4.7.0"))
]
Note on Objective-C integration: The Rokt SDK for iOS is implemented using Swift. If you are using Objective-C, you need to import the bridging header file from the framework into the
.h/.m
file.
#import <Rokt_Widget/Rokt_Widget-Swift.h>
If you are having trouble installing and are receiving an error saying that the SWIFT_VERSION is not defined, please add a user-defined variable SWIFT_VERSION
. This variable should be set to "5" for iOS SDK versions 2.0 and above. This variable should be set to "4.2" for iOS SDK version 1.2.1.
Initialize the Rokt SDK for iOS
Initialize the Rokt SDK for iOS prior to using it in any ViewController
. We recommend calling the init
method from the applicationDidFinishLaunching
handler.
Contact Rokt for the Rokt Account ID associated with your account. In order to test your integration, you can use the Rokt Account ID below, but this needs to be replaced by your unique Rokt Account ID before you launch in production.
Initialize the SDK
The Rokt SDK for iOS applications can be used by Rokt partners to display overlay or embedded placements, or by Rokt advertisers to record conversions for campaigns. The Rokt SDK for iOS is deployed using CocoaPods.
All use cases of the SDK will follow the same initial steps to integrate and initialize the SDK in your application. At a high level, these steps are:
- Set up a workspace using CocoaPod/Swift Package Manager
- Add the
Rokt-Widget
- Install the pod/package
- Initialize the Rokt SDK
Following these steps, the execute
method of the SDK can then be used in various ways to suit the required use case.
Test Rokt Account ID: 222
- Swift
- Objective-C
//file => AppDelegate.swift
import Rokt_Widget
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// The following will reveal a demo integration. To view your integration, replace the integration test tag ID (222) with your unique Rokt Tag ID
Rokt.initWith(roktTagId: "222")
return true
}
//file => AppDelegate.m
#import <Rokt_Widget/Rokt_Widget-Swift.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[Rokt initWithRoktTagId:@"222"];
return YES;
}
Receiving initialization status
From version 4.6.0
, the Rokt SDK provides 2 ways to receive the status of initialization:
Optional callback on initialize
There is a callback in the Rokt.initWith
method to notify when the initialization is completed and return the status.
Rokt.initWith(roktTagId: "222") { status in
print("Rokt init completed with status: \(status)")
}
Global events API
The SDK also provides the status through the Rokt.globalEvents
API.
Rokt.globalEvents() { roktEvent in
if let initEvent = roktEvent as? RoktEvent.InitComplete {
print("Rokt init completed with status: \(initEvent.success)")
}
}
Debugging
Use the Rokt.setLoggingEnabled(enable: true)
API to enable debug logs from the Rokt SDK.
Next steps
Your next steps depend on the use case of your integration. Check out these resources for more information: