From cf9274a514424dc73d1042e21cb59a590f737b7f Mon Sep 17 00:00:00 2001 From: Codel1417 Date: Fri, 29 Nov 2024 20:24:24 -0500 Subject: [PATCH] add firebase notification base code --- android/app/build.gradle | 6 +- android/app/src/main/AndroidManifest.xml | 24 +++++++ android/settings.gradle | 2 + ios/Runner/AppDelegate.swift | 3 + lib/main.dart | 31 +++++++++ pubspec.lock | 80 +++++++++++++++++++++--- pubspec.yaml | 5 +- 7 files changed, 141 insertions(+), 10 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index a156548c0..2f0ad0431 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -3,6 +3,8 @@ plugins { id "kotlin-android" id "dev.flutter.flutter-gradle-plugin" id "io.sentry.android.gradle" + id 'com.google.gms.google-services' + } def localProperties = new Properties() @@ -102,6 +104,8 @@ dependencies { testImplementation "junit:junit:4.13.2" // https://developer.android.com/jetpack/androidx/releases/test/#1.2.0 coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:2.1.3" + implementation(platform("com.google.firebase:firebase-bom:33.6.0")) + } configurations.configureEach { exclude group: "io.sentry", module: "sentry-android-ndk" @@ -111,7 +115,7 @@ sentry { // Disables or enables debug log output, e.g. for for sentry-cli. // Default is disabled. debug = false - + // The slug of the Sentry organization to use for uploading proguard mappings/source contexts. org = System.getenv("SENTRY_ORG") diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 9c96c794e..91e459d79 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -100,6 +100,30 @@ android:exported="false" android:foregroundServiceType="connectedDevice" android:stopWithTask="true" /> + + + + + + + + + + + + + diff --git a/android/settings.gradle b/android/settings.gradle index 00b32f3bc..7507cda62 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -22,6 +22,8 @@ plugins { id "io.sentry.android.gradle" version "4.13.0" apply false id "org.jetbrains.kotlin.android" version "2.0.21" apply false id "com.android.application" version '8.7.2' apply false + id 'com.google.gms.google-services' version '4.4.2' apply false + } include ":app" diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index 70693e4a8..eac5ccc66 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -8,6 +8,9 @@ import Flutter didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { GeneratedPluginRegistrant.register(with: self) + if #available(iOS 10.0, *) { + UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate + } return super.application(application, didFinishLaunchingWithOptions: launchOptions) } } diff --git a/lib/main.dart b/lib/main.dart index 776833453..7ef1b349e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,6 +4,8 @@ import 'dart:ui'; import 'package:device_info_plus/device_info_plus.dart'; import 'package:feedback_sentry/feedback_sentry.dart'; +import 'package:firebase_core/firebase_core.dart'; +import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:firebase_testlab_detector/firebase_testlab_detector.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -15,6 +17,7 @@ import 'package:hive_flutter/adapters.dart'; import 'package:install_referrer/install_referrer.dart'; import 'package:intl/intl.dart'; import 'package:is_wear/is_wear.dart'; +import 'package:klaviyo_flutter/klaviyo_flutter.dart'; import 'package:logging/logging.dart'; import 'package:path_provider/path_provider.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; @@ -439,3 +442,31 @@ class _EagerInitialization extends ConsumerWidget { return child; } } + +//TODO: get APNs cert from apple +// Eat snacks +// Get google-services.json +// Configure Github Actions to store and place the files +Future initMarketingNotifications() async { + await Klaviyo.instance.initialize(const String.fromEnvironment('KLAVIYO_KEY', defaultValue: "")); + final firebaseMessaging = FirebaseMessaging.instance; + final token = Platform.isIOS ? await firebaseMessaging.getAPNSToken() : await firebaseMessaging.getToken(); + + if (token != null && token.isNotEmpty) { + Klaviyo.instance.sendTokenToKlaviyo(token); + FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler); + } +} + +Future firebaseMessagingBackgroundHandler(RemoteMessage message) async { + await Firebase.initializeApp(); + final data = message.data; + final klaviyo = Klaviyo.instance; + + if (klaviyo.isKlaviyoPush(data)) { + if (!klaviyo.isInitialized) { + await klaviyo.initialize(const String.fromEnvironment('KLAVIYO_KEY', defaultValue: "")); + } + final result = await klaviyo.handlePush(data); + } +} diff --git a/pubspec.lock b/pubspec.lock index ce68c9a45..1ec3d0b0d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -9,6 +9,14 @@ packages: url: "https://pub.dev" source: hosted version: "72.0.0" + _flutterfire_internals: + dependency: transitive + description: + name: _flutterfire_internals + sha256: "71c01c1998c40b3af1944ad0a5f374b4e6fef7f3d2df487f3970dbeadaeb25a1" + url: "https://pub.dev" + source: hosted + version: "1.3.46" _macros: dependency: transitive description: dart @@ -543,6 +551,54 @@ packages: url: "https://pub.dev" source: hosted version: "8.1.4" + firebase_core: + dependency: "direct main" + description: + name: firebase_core + sha256: "2438a75ad803e818ad3bd5df49137ee619c46b6fc7101f4dbc23da07305ce553" + url: "https://pub.dev" + source: hosted + version: "3.8.0" + firebase_core_platform_interface: + dependency: transitive + description: + name: firebase_core_platform_interface + sha256: e30da58198a6d4b49d5bce4e852f985c32cb10db329ebef9473db2b9f09ce810 + url: "https://pub.dev" + source: hosted + version: "5.3.0" + firebase_core_web: + dependency: transitive + description: + name: firebase_core_web + sha256: f967a7138f5d2ffb1ce15950e2a382924239eaa521150a8f144af34e68b3b3e5 + url: "https://pub.dev" + source: hosted + version: "2.18.1" + firebase_messaging: + dependency: "direct main" + description: + name: firebase_messaging + sha256: "4d0968ecb860d7baa15a6e2af3469ec5b0d959e51c59ce84a52b0f7632a4aa5a" + url: "https://pub.dev" + source: hosted + version: "15.1.5" + firebase_messaging_platform_interface: + dependency: transitive + description: + name: firebase_messaging_platform_interface + sha256: a2cb3e7d71d40b6612e2d4e0daa0ae759f6a9d07f693f904d14d22aadf70be10 + url: "https://pub.dev" + source: hosted + version: "4.5.48" + firebase_messaging_web: + dependency: transitive + description: + name: firebase_messaging_web + sha256: "1554e190f0cd9d6fe59f61ae0275ac12006fdb78b07669f1a260d1a9e6de3a1f" + url: "https://pub.dev" + source: hosted + version: "3.9.4" firebase_testlab_detector: dependency: "direct main" description: @@ -718,10 +774,10 @@ packages: dependency: "direct main" description: name: flutter_markdown - sha256: "999a4e3cb3e1532a971c86d6c73a480264f6a687959d4887cb4e2990821827e4" + sha256: "255b00afa1a7bad19727da6a7780cf3db6c3c12e68d302d85e0ff1fdf173db9e" url: "https://pub.dev" source: hosted - version: "0.7.4+2" + version: "0.7.4+3" flutter_native_splash: dependency: "direct main" description: @@ -758,10 +814,10 @@ packages: dependency: transitive description: name: flutter_svg - sha256: "936d9c1c010d3e234d1672574636f3352b4941ca3decaddd3cafaeb9ad49c471" + sha256: "54900a1a1243f3c4a5506d853a2b5c2dbc38d5f27e52a52618a8054401431123" url: "https://pub.dev" source: hosted - version: "2.0.15" + version: "2.0.16" flutter_test: dependency: "direct dev" description: flutter @@ -1053,6 +1109,14 @@ packages: url: "https://pub.dev" source: hosted version: "6.9.0" + klaviyo_flutter: + dependency: "direct main" + description: + name: klaviyo_flutter + sha256: "0ebeadf99f22b6a9456bc8b87f82663e82ee2862360709a0c284057f286b9b61" + url: "https://pub.dev" + source: hosted + version: "0.1.1" leak_tracker: dependency: transitive description: @@ -1258,10 +1322,10 @@ packages: dependency: transitive description: name: path_provider_android - sha256: c464428172cb986b758c6d1724c603097febb8fb855aa265aeecc9280c294d4a + sha256: "8c4967f8b7cb46dc914e178daa29813d83ae502e0529d7b0478330616a691ef7" url: "https://pub.dev" source: hosted - version: "2.2.12" + version: "2.2.14" path_provider_foundation: dependency: transitive description: @@ -1937,10 +2001,10 @@ packages: dependency: transitive description: name: vector_graphics_compiler - sha256: ab9ff38fc771e9ee1139320adbe3d18a60327370c218c60752068ebee4b49ab1 + sha256: "1b4b9e706a10294258727674a340ae0d6e64a7231980f9f9a3d12e4b42407aad" url: "https://pub.dev" source: hosted - version: "1.1.15" + version: "1.1.16" vector_math: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 48a4f5e0a..d9d3f58f1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -81,11 +81,11 @@ dependencies: flutter_widget_from_html_core: ^0.15.2 visibility_detector: ^0.4.0+2 # used on the tail blog widgets lottie: ^3.1.3 - #pdfrx: ^1.0.91 pdfx: git: url: https://github.com/Codel1417/packages.flutter path: packages/pdfx + # Dio HTTP dio: ^5.7.0 dio_smart_retry: ^7.0.1 @@ -111,9 +111,12 @@ dependencies: in_app_review: ^2.0.10 upgrader: ^11.3.0 google_api_availability: ^5.0.0 + firebase_messaging: ^15.1.5 + firebase_core: ^3.8.0 # Spicy plausible_analytics: ^0.3.0 # Privacy Preserving analytics + klaviyo_flutter: ^0.1.1 # Marketing Notifications # Sentry sentry_flutter: ^8.10.1 # Base sentry + Flutter integration