Skip to content

shortcut/flutter-sifo-implementation-demo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kantar Sifo Flutter Demo

This demo is to show how to integrate platform specific libraries of kantar sifo in flutter

SETUP

Android

Step 1:

In android/build.gradle add:

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

Step 2:

In android/app/build.gradle add:

dependencies {
    implementation 'com.github.kantarsifo:SifoInternetAndroidSDK:4.x.x’
}

Step 3:

In MainActivity change from:

    class MainActivity: FlutterActivity()

to:

class MainActivity: FlutterFragmentActivity()

this is so that createInstance accepts the activity as a parameter

IOS

Step 1:

Add library to project

Swift Package Manager:

source 'https:/kantarsifo/SifoInternet_IOS_SDK.git'

Step 2:

Add url scheme, query scheme and user tracking usage

Update your info.plist to include. Add query scheme:

<key>LSApplicationQueriesSchemes</key>
<array>
	<string>se.tns-sifo.internetpanelen</string>
</array>

Add url scheme with <your_bundle_id>.tsmobileanalytics:

<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleTypeRole</key>
    <string>None</string>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>my.example.id.tsmobileanalytics</string>
    </array>
  </dict>
</array>

Connecting Everything

Android

Step 1:

Override this function:

override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
}

Step 2:

Add needed method channels: ["initializeFramework", "sendTag", "destroyFramework"]

Method channel example:

MethodChannel(
            flutterEngine.dartExecutor.binaryMessenger,
            CHANNEL
        ).setMethodCallHandler { call, result ->
            if (call.method == "initializeFramework") {}
        }

When "initializeFramework" will be called it will invoke whatever is inside the function of that method call

Everything from here is calling the functions just like in native android

IOS

Step 1:

add channel:

let channel = FlutterMethodChannel(name: "com.example.app/native", binaryMessenger: controller.binaryMessenger)

Step 2:

Add needed method channels: ["initializeFramework", "sendTag"] (ios package of kantar sifo does not have destroy framework)

Method channel example:

channel.setMethodCallHandler { [self] (call, result) in
        if call.method == "initializeFramework" {}
}

When "initializeFramework" will be called it will invoke whatever is inside the function of that method call

Everything from here is calling the functions just like in native ios

Flutter

Step 1

Create a channel:

  static const platform = MethodChannel('com.example.app/native');

Step 2

Call methods and send data

initializeFramework:

void _initializeFramework() async {
    try {
      final bool result = await platform.invokeMethod('initializeFramework', {
        'cpId': string,
        'appName': string,
        'isPanelistOnly': bool,
        'isLogEnabled': bool,
        'isWebViewBased': bool,
      });
    } on PlatformException catch (e) {
      print("Failed to initialize framework: '${e.message}'.");
    }
  }

sendTag:

void _sendTag() async {
  try {
    await platform.invokeMethod('sendTag', {
      'category': string,
      'contentID': string,
    });
  } on PlatformException catch (e) {
    print("Failed to send tag: '${e.message}'.");
  }
}

destroyFramework (Android only)

void _destroyFramework() async {
  if (Platform.isAndroid) {
    try {
      final bool result = await platform.invokeMethod('destroyFramework');
    } on PlatformException catch (e) {
      print("Failed to destroy framework: '${e.message}'.");
    }
  }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 39.1%
  • CMake 30.1%
  • Dart 13.4%
  • Swift 7.7%
  • Kotlin 6.1%
  • HTML 2.1%
  • Other 1.5%