Push token
static void addPushToken(String pushToken, PushTokenService service); // lib/affise.dart:35enum PushTokenService (lib/settings/push_token_service.dart:1-4):
enum PushTokenService { FIREBASE, APPLE}Native keys (lib/settings/push_token_service.dart:8-14):
| Enum | Native key | Platform |
|---|---|---|
| FIREBASE | "fms" | Android + iOS (FCM) |
| APPLE | "apns" | iOS only |
Firebase token (Android + iOS FCM)
Section titled “Firebase token (Android + iOS FCM)”import 'package:affise_attribution_lib/affise.dart';import 'package:firebase_messaging/firebase_messaging.dart';
class _Application extends State<Application> {
@override void initState() { super.initState();
// Any time the token refreshes, pass this to Affise. FirebaseMessaging.instance.onTokenRefresh.listen((pushToken) { Affise.addPushToken(pushToken, PushTokenService.FIREBASE); }) .onError((err) { // Error getting token. }); }
...}APNs token (iOS)
Section titled “APNs token (iOS)”Using firebase_messaging
Section titled “Using firebase_messaging”import 'dart:io';import 'package:affise_attribution_lib/affise.dart';import 'package:firebase_messaging/firebase_messaging.dart';
class _Application extends State<Application> {
@override void initState() { super.initState();
// Works only on iOS if (Platform.isIOS) { // Get Apple Push Notification Service token FirebaseMessaging.instance.getAPNSToken().then((pushToken) { if (pushToken != null) { Affise.addPushToken(pushToken, PushTokenService.APPLE); } }); } }
...}Using the native AppDelegate
Section titled “Using the native AppDelegate”If you use APNs directly (without Firebase), register for remote notifications and forward the token from AppDelegate.swift:
import AffiseAttributionLib
@UIApplicationMain@objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { GeneratedPluginRegistrant.register(with: self) let result = super.application(application, didFinishLaunchingWithOptions: launchOptions)
application.registerForRemoteNotifications()
return result }
override func application( _ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data ) { let pushToken = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
// Pass APNs token to Affise Affise.addPushToken(pushToken, .APPLE) }}Uninstall tracking
Section titled “Uninstall tracking”“Affise automatically track reinstall events by using silent-push technology, to make this feature work, pass push token when it is recreated by user and on you application starts up”
README 1255-1260
Affise.addPushToken("token", PushTokenService.FIREBASE);