Setup SDK
iOS and tvOS PacketSDK Integration Guide
Overview
This guide is intended for application developers who want to monetize their iOS and tvOS apps using the PacketSDK. PacketSDK supports native iOS and tvOS apps written in Objective-C and Swift.
Integrating the Packet SDK into your app is the first step to earning revenue. Once integrated, you'll start seeing revenue in the PacketSDK Dashboard within 24 hours.
This document will walk you through the steps required for proper integration. Most apps can be integrated with the Packet SDK in about 15 to 20 minutes.
Compatibility Information
System
Supports iOS 13.0 or higher and tvOS 13.0 or higher
Development Environment
Develop with Xcode15.3 or higher
Preparation
Apply for appkey
Register and log in to the PacketSDK, go to Dashboard>APP to add your app and get your appkey
SDK Integration Package Directory Structure
After completing the previous step, download the SDK package: packet_sdk_ios-\*.zip
Unzip the SDK package to find the following files:
├──PacketSDK.xcframework (Obfuscated SDK package)
├──PacketSDKDemo (The SDK usage demo comes with the SDK already integrated. You can refer to this demo for guidance on integrating the SDK. Before integrating, please test the demo to understand the implementation principles.)
├──PacketSDK_tvOS_Demo (The SDK usage demo comes with the SDK already integrated. You can refer to this demo for guidance on integrating the SDK. Before integrating, please test the demo to understand the implementation principles.)
├──PacketSDK_swiftUI_Demo (The SDK usage demo comes with the SDK already integrated. You can refer to this demo for guidance on integrating the SDK. Before integrating, please test the demo to understand the implementation principles.)
└───packet_sdk_ios_tvos_document-\*.md (Integration Documentation)
SDK Project Configuration
Step1: Import SDK Library
Copy PacketSDK.xcframework to your project directory, Add the following configuration:
import PacketSDK#import "PacketSDK/PacketSDK-Swift.h"Step2: Quick Integration
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
PacketSdk.SetCallBack { [weak self]msg in
guard let self = self else { return }
print("msg--\(msg)")
}
PacketSdk.SetAppKey(appkey: "yourappkey")
PacketSdk.optIn()
PacketSdk.Start()
// Do any additional setup after loading the view.
}
}@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[PacketSdk SetCallBackWithBlock:^(NSString * _Nonnull msg) {
NSLog(@"msg %@",msg);
}];
[PacketSdk SetAppKeyWithAppkey:@"yourappkey"];//your appkey
[PacketSdk optIn];
[PacketSdk Start];
}
@end
Step3: Verify if integration is successful.
After call PacketSdk.Start() API, if receive Start preparation Get Server Success and Connect success in the callback function you set, it indicates that you have successfully integrated Packet SDK into your application.
Once you’ve received Connect success in the callback function, you will start seeing devices data and revenue in Packet SDK Dashboard in 24 hours.
Default consent window
We have provided a default consent window.
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
PacketSdk.SetCallBack { [weak self]msg in
guard let self = self else { return }
print("msg--\(msg)")
}
PacketSdk.SetAppKey(appkey: "yourappkey")
if PacketSdk.isOptIn() {//You have already agreed to the agreement
PacketSdk.Start()
} else {
//default consent window
PacketSdk.requestConsent(icon: "icon", close: "close", bussiness: "business", url: "url", device: "device", web: "web", row: "line",code: "code", vc: self)
}
}
}
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[PacketSdk SetCallBackWithBlock:^(NSString * _Nonnull msg) {
NSLog(@"msg %@",msg);
}];
[PacketSdk SetAppKeyWithAppkey:@"yourappkey"];//your appkey
if (PacketSdk.isOptIn) {//You have already agreed to the agreement
[PacketSdk Start];
} else {
//default consent window
[PacketSdk requestConsentWithIcon:@"icon" close:@"close" bussiness:@"business" url:@"url" device:@"device" web:@"web" row:@"line" code:@"code" vc:self];
}
}
@end
Custom consent window
If default SDK consent window doesn't suit your needs, you can create a custom consent window. Make sure to call PacketSdk.optIn() whenever user gives a consent and PacketSdk.optOut() whenever user declines it.
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
PacketSdk.SetCallBack { [weak self]msg in
guard let self = self else { return }
print("msg--\(msg)")
}
PacketSdk.SetAppKey(appkey: "yourappkey")
//If you click "Agree" in the consent window,call PacketSdk.optIn()
//If you click "Reject" in the consent window call PacketSdk.optOut()
if PacketSdk.isOptIn() {//You have already agreed to the agreement
PacketSdk.Start()
} else {
//Your custom pop-up window
}
}
}
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[PacketSdk SetCallBackWithBlock:^(NSString * _Nonnull msg) {
NSLog(@"msg %@",msg);
}];
[PacketSdk SetAppKeyWithAppkey:@"yourappkey"];//your appkey
//If you click "Agree" in the consent window,call PacketSdk.optIn()
//If you click "Reject" in the consent window call PacketSdk.optOut()
if (PacketSdk.isOptIn) {//You have already agreed to the agreement
[PacketSdk Start];
} else {
//Your custom pop-up window
}
}
@end
Return Value Description
Start preparation.
Start the SDK
Get Server Success.
Server successfully acquired
Connect success.
Connection successful
SDK APIs
/**
* Checks whether user has given the consent to start SDK.
*/
public static func isOptIn() -> Bool
/**
* Set your appkey.
*/
public static func PacketSdk.SetAppKey(appkey: String)
/**
* Stops SDK if it's running.
*/
public static func Stop()
/**
* Withdraws user's consent and stops SDK if it was running.
*/
public static func optOut()
/**
* Informs SDK that user gave consent. Used with custom consent requests when
* provided consent UI is insufficient.
* This does not start SDK, [PacketSdk.start()] still needs to be called.
*/
public static func optIn()
/**
* Opens up a view displaying consent request with default settings.
*/
public static func requestConsent(icon:String,close:String,bussiness:String,url:String,device:String,web:String,row:String,code:String,vc: UIViewController)Demo Project Reference
We have provided a SDKDemo in the zip file for you to debug. You can use the demo to configure your app_key and then click start.
If the following message is returned, it means that your current device has successfully connected to our service,you will start seeing devices data and revenue in PacketSDK Dashboard in 24 hours.
Start preparation.Get Server Success.Connect success.
Last updated