Setup SDK

MacOS PacketSDK Integration Guide

Overview

This guide is intended for application developers who want to monetize their macOS apps using the PacketSDK.

PacketSDK supports integration of native macOS apps written in Objective-C and Swift through framework libraries and pre-compiled binary executables.

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

Category
Compatibility

System

Supports macOS 10.13 or higher

Development Environment

Develop with Xcode 15.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 macos SDK package:packet_sdk_macos-*.zip

Unzip the SDK package to find the following files:

├──PacketSDK.framework (Obfuscated SDK package)

├──PacketSDK_MacDemo (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_macos_document-*.md (Integration Documentation)

└───bin(This is binary integration)

Choose an integration method that suits you.

Binary executable program integration

framework library integration

Binary Executable Program Integration

Step1: Find the binary executable program in the MacOS integration package.

Open the terminal and go to the package directory.

Step2: Enter ./PacketSDK_Mac -appkey=yourappkey on the terminal.

If you are prompted with no permissions, type sudo spctl --master-disable on the terminal, and then enter your computer login password.

Granting execution authority.chmod +x PacketSDK_Mac

After obtaining permissions, enter ./PacketSDK_Mac -appkey=yourappkey on the terminal.

Step3: Verify if integration is successful.

After hitting Enter on the terminal,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.

Framework Library Integration

Step1: Import SDK Library

Copy PacketSDK.framework to your project directory,Add the following configuration:

  • Swift:

    import PacketSDK
  • Object-C:

    #import "PacketSDK/PacketSDK-Swift.h"

Step2: Quick Integration

  • Swift

     class ViewController: NSViewController {
    
        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.
        }
    
    }
  • Object-C

    @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.

We have provided a default consent window.

  • Swift

class ViewController: NSViewController {

    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)
        }
    
    }

}
  • Object-C

@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

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.

  • Swift

class ViewController: NSViewController {

    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
       }
    
    }

}
  • Object-C

@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

SDK APIs

/**

Checks whether user has given the consent to start SDK.

* /

  • public static func isOptIn() -> Bool

/*

Monitor the status of the SDK.

*/

  • public static func SetCallBack(block:@escaping(String) -> Void)

/**

Set your appkey.

*/

  • public static func SetAppKey(appkey: String)

/**

Starts SDK if user has given the consent, otherwise does nothing.

*/

  • public static func Start();

/**

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)

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.

Return Value Description

Return Value
Description

Start preparation.

Start the SDK

Get Server Success.

Server successfully acquired

Connect success.

Connection successful

Last updated