Setup SDK

Flutter_iOS PacketSDK Integration Guide

Overview

This guide is intended for application developers who want to monetize their iOS apps using the PacketSDK. PacketSDK supports iOS apps written in flutter.

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 iOS 12.0 or higher

Development Environment

Develop with Visual Studio Code Or Android Studio

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 iOS SDK package:packet_sdk_flutterForIOS1-\*.zip

Unzip the SDK package to find the following files:

├──packetsdk_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_flutterforios_document-\*.md(Integration Documentation)

SDK Project Configuration

Step1: Import SDK Library

Add packet_ios_sdk: ^1.0.9 to pubspec.yaml, perform flutter pub get on the terminal

  • dependencies:

 packet_ios_sdk: ^1.0.9

Step2: Quick Integration

   import 'package:packet_ios_sdk/packet_ios_sdk.dart';
    // set user app_key
    if (defaultTargetPlatform == TargetPlatform.iOS) {
        PacketIosSdk().SetAppKey("yourappkey");//your appkey
        PacketIosSdk().optIn();
        PacketIosSdk().Start();
   }

Step3: Verify if integration is successful.

  • After call PacketIosSdk().SetAppKey("yourappkey") 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 PacketSDK Dashboard in 24 hours.

Default consent window

We have provided a default consent window.

 import 'package:packet_ios_sdk/packet_ios_sdk.dart';
    // set user app_key
    if (defaultTargetPlatform == TargetPlatform.iOS) {
     PacketIosSdk().SetAppKey("yourappkey");//your appkey
     final bool? isOptIn = await PacketIosSdk().isOptIn();
     if (isOptIn == true) {//You have already agreed to the agreement
        PacketIosSdk().Start();
     } else {
        PacketIosSdk().requestConsent();
     }
   }

Custom consent window

If default SDK consent window doesn't suit your needs, you can create a custom consent window. Make sure to call PacketIosSdk().optIn() whenever user gives a consent and PacketIosSdk().optOut() whenever user declines it.

import 'package:packet_ios_sdk/packet_ios_sdk.dart';
    // set user app_key
    if (defaultTargetPlatform == TargetPlatform.iOS) {
     PacketIosSdk().SetAppKey("yourappkey");//your appkey
    //If you click "Agree" in the consent window,call PacketIosSdk().optIn()
    //If you click "Reject" in the consent window call PacketIosSdk().optOut()
     final bool? isOptIn = await PacketIosSdk().isOptIn();
     if (isOptIn == true) {//You have already agreed to the agreement
        PacketIosSdk().Start();
     } else {
        //Your custom pop-up window
     }
   }

SDK APIs

  /**
 * Checks whether user has given the consent to start SDK.
 */
public static func isOptIn() -> Bool

/**
 * 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, [PacketIosSdk().Start()] still needs to be called.
 */
public static func optIn()

/**
 * Opens up a view displaying consent request with default settings.
 */
public static func requestConsent()

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