Add Kettle
Preqrequisites
The following criterias must be fulfilled to implement the SDK:
- Minimum iOS target: 11.0
- Minimum Android minSdk: 15
- Minimum Android compileSdk: 31
- Minimum Kotlin version: 1.8.10
Add dependency
The plugin is available at pub.dev. Add the following package to your pubspec:
dependencies:
kettle: ^x.x.x
Install flutter package
Install the package.
$ flutter pub get
Android
A runtime exception will be thrown on launch if API key is missing.
In AndroidManifest.xml, add the following element as a child of the application element:
<meta-data
android:name="com.kogenta.kettle.sdk.API_KEY"
android:value="<API-KEY>"
/>
If your project utilizees ProGuard for obfuscation and code minification, add the following exception to your definition:
-keepclassmembers class com.kogenta.kettle.core.model.** { *; }
iOS
After running flutter pub get, navigate to your projects ios directory and install hte pods imported by the kettle plugin. Open the runner workspace afterwards.
$ cd ios
$ pod install
$ open Runner.xcworkspace
In your AppDelegate didFinishLaunchingWithOptions, add the following to initialize Kettle:
import KettleKit
...
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
...
let kettleConfig = KettleConfig.default()
kettleConfig.developmentApiKey = "<DEV-API-KEY">
kettleConfig.productionApiKey = "<PROD-API-KEY">
// optionally, override Kettle's default log verbosity
kettleConfig.productionLogLevel = .none
kettleConfig.developmentLogLevel = .debug
// Initialize Kettle
Kettle.prepare(config, launchOptions: launchOptions)
...
}
Add bluetooth-central to your applications background modes. This is required to scan for eddystone data. Add the required permissions to your Info.plist.
Push Notifications
Assign push token
Forwards the users push token to Kettle, allowing it to send push notifications.
Kettle.shared.pushToken = "<PUSH-TOKEN>"
Handle notification events
To enable Kettle to track push notification interactions, you need to forward specific notification events to the SDK.
// When app receives a remote notification
func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
Kettle.shared.didReceiveRemoteNotification(userInfo: userInfo)
...
}
// When user opens a notification (requires UNUserNotificationCenterDelegate)
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
Kettle.shared.didOpenNotification(userInfo: userInfo)
...
}
User opened notification
When a user taps on a notification to open the app, inform Kettle about this interaction:
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
Kettle.shared.didOpenNotification(userInfo: userInfo)
...
}
Deep Links
If your app is opened via a custom URL scheme or universal link, notify Kettle in case any project-specific deep link logic needs to be handled by the SDK.
func application(_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
Kettle.shared.didOpenApplicationWithUrl(url: url.absoluteString)
return true
}
Import Kettle in Dart
You can import Kettle in Dart as:
import 'package:kettle/kettle.dart';