This demo is to show how to integrate platform specific libraries of kantar sifo in flutter
In android/build.gradle add:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
In android/app/build.gradle add:
dependencies {
implementation 'com.github.kantarsifo:SifoInternetAndroidSDK:4.x.x’
}
In MainActivity change from:
class MainActivity: FlutterActivity()
to:
class MainActivity: FlutterFragmentActivity()
this is so that createInstance accepts the activity as a parameter
For more details: https://github.com/kantarsifo/SifoInternetAndroidSDK
Add library to project
Swift Package Manager:
source 'https://github.com/kantarsifo/SifoInternet_IOS_SDK.git'
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>
For more details: https://github.com/kantarsifo/SifoInternet_IOS_SDK
Override this function:
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
}
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
add channel:
let channel = FlutterMethodChannel(name: "com.example.app/native", binaryMessenger: controller.binaryMessenger)
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
Create a channel:
static const platform = MethodChannel('com.example.app/native');
Call methods and send data
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}'.");
}
}
void _sendTag() async {
try {
await platform.invokeMethod('sendTag', {
'category': string,
'contentID': string,
});
} on PlatformException catch (e) {
print("Failed to send tag: '${e.message}'.");
}
}
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}'.");
}
}
}