Skip to content

Commit

Permalink
Merge pull request #359 from qonversion/tech/sc-35135/deprecatePushToken
Browse files Browse the repository at this point in the history
The `setNotificationToken`, `handleNotification`, and `getNotificationCustomPayload` methods were marked as deprecated.
  • Loading branch information
SpertsyanKM authored Oct 1, 2024
2 parents cd1d1ba + 4a6e980 commit d9df2e2
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 293 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "io.qonversion.sandwich:sandwich:5.1.4"
implementation "io.qonversion.sandwich:sandwich:5.1.5"
implementation 'com.google.code.gson:gson:2.9.0'
}
5 changes: 0 additions & 5 deletions example/lib/constants.dart

This file was deleted.

41 changes: 0 additions & 41 deletions example/lib/handling_notification.dart

This file was deleted.

46 changes: 0 additions & 46 deletions example/lib/home.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import 'dart:async';
import 'dart:io';

import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:qonversion_flutter/qonversion_flutter.dart';
import 'handling_notification.dart';

class HomeView extends StatefulWidget {
@override
Expand All @@ -27,24 +25,6 @@ class _HomeViewState extends State<HomeView> {
super.initState();
_initPlatformState();

FirebaseMessaging.onMessage.listen((RemoteMessage message) {
showNotification(message);
});

FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage? message) {
if (message != null) {
onNotificationClick(message.data);
}
});

FirebaseMessaging.instance
.getInitialMessage()
.then((RemoteMessage? message) {
if (message != null) {
onNotificationClick(message.data);
}
});

_shownScreensStream =
Automations.getSharedInstance().shownScreensStream.listen((event) {
// do any logic you need
Expand Down Expand Up @@ -177,7 +157,6 @@ class _HomeViewState extends State<HomeView> {
.build();
Qonversion.initialize(config);
Qonversion.getSharedInstance().collectAppleSearchAdsAttribution();
_sendNotificationsToken();
_loadQonversionObjects();
}

Expand All @@ -194,31 +173,6 @@ class _HomeViewState extends State<HomeView> {
setState(() {});
}

Future<void> _sendNotificationsToken() async {
String? deviceToken;
switch (defaultTargetPlatform) {
case TargetPlatform.android:
{
deviceToken = await FirebaseMessaging.instance.getToken();
}
break;

case TargetPlatform.iOS:
{
deviceToken = await FirebaseMessaging.instance.getAPNSToken();
}
break;
default:
deviceToken = null;
break;
}

if (deviceToken != null) {
Automations.getSharedInstance().setNotificationsToken(deviceToken);
print('Device token: $deviceToken');
}
}

List<Widget> _entitlementsFromMap(Map<String, QEntitlement> entitlements) {
return entitlements.entries.map<Widget>((e) {
var title = e.value.productId +
Expand Down
84 changes: 0 additions & 84 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,96 +1,12 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:qonversion_example/constants.dart';

import 'handling_notification.dart';
import 'home.dart';
import 'params_view.dart';
import 'products_view.dart';
import 'dart:async';

import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'dart:convert';

/// Define a top-level named handler which background/terminated messages will
/// call.
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
print('Handling a background message ${message.messageId}');
showNotification(message);
}

/// Initialize the [FlutterLocalNotificationsPlugin] package.
late FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;

/// Create a [AndroidNotificationChannel] for heads up notifications
late AndroidNotificationChannel channel;

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();

// Set the background messaging handler early on, as a named top-level function
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

if (!kIsWeb) {
channel = const AndroidNotificationChannel(
Constants.channelId, // id
Constants.channelName, // name
importance: Importance.high,
);

/// Configure FlutterLocalNotificationsPlugin
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
var initializationSettingsAndroid =
AndroidInitializationSettings('launch_background');
var initializationSettingsIOS = DarwinInitializationSettings(
requestAlertPermission: true,
requestBadgePermission: true,
requestSoundPermission: false);
var initializationSettings = InitializationSettings(
android: initializationSettingsAndroid, iOS: initializationSettingsIOS);

await flutterLocalNotificationsPlugin.initialize(initializationSettings,
onDidReceiveNotificationResponse: (NotificationResponse details) async {
var notificationData = jsonDecode(details.payload ?? "{}");
onNotificationClick(notificationData);
});

/// Create an Android Notification Channel.
await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(channel);

/// Update the iOS foreground notification presentation options to allow heads up notifications.
await FirebaseMessaging.instance
.setForegroundNotificationPresentationOptions(
alert: true,
badge: true,
sound: true,
);
}
/// Grant entitlements for iOS
if (Platform.isIOS) {
NotificationSettings settings =
await FirebaseMessaging.instance.requestPermission(
announcement: true,
carPlay: true,
criticalAlert: true,
);

if (settings.authorizationStatus == AuthorizationStatus.authorized) {
print('User granted permission');
} else if (settings.authorizationStatus ==
AuthorizationStatus.provisional) {
print('User granted provisional permission');
} else {
print('User declined or has not accepted permission');
}
}

runApp(SampleApp());
}
Expand Down
3 changes: 0 additions & 3 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ dependencies:
flutter:
sdk: flutter

firebase_messaging: ^11.0.0
flutter_local_notifications: ^17.2.2

dependency_overrides:
firebase_core_platform_interface: 4.5.1

Expand Down
2 changes: 1 addition & 1 deletion ios/qonversion_flutter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
s.platform = :ios, '9.0'
s.dependency "QonversionSandwich", "5.1.4"
s.dependency "QonversionSandwich", "5.1.5"

# Flutter.framework does not contain a i386 slice. Only x86_64 simulators are supported.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' }
Expand Down
3 changes: 3 additions & 0 deletions lib/src/automations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,22 @@ abstract class Automations {

/// Set push token to Qonversion to enable Qonversion push notifications
/// [token] Firebase device token for Android. APNs device token for iOS
@Deprecated("Consider removing this method calls. Qonversion is not working with push notifications anymore")
Future<void> setNotificationsToken(String token);

/// [notificationData] notification payload data
/// See [Firebase RemoteMessage data](https://pub.dev/documentation/firebase_messaging_platform_interface/latest/firebase_messaging_platform_interface/RemoteMessage/data.html)
/// See [APNs notification data](https://developer.apple.com/documentation/usernotifications/unnotificationcontent/1649869-userinfo)
/// Returns true when a push notification was received from Qonversion. Otherwise returns false, so you need to handle the notification yourself
@Deprecated("Consider removing this method calls as they aren't needed anymore")
Future<bool> handleNotification(Map<String, dynamic> notificationData);

/// Get parsed custom payload, which you added to the notification in the dashboard
/// [notificationData] notification payload data
/// See [Firebase RemoteMessage data](https://pub.dev/documentation/firebase_messaging_platform_interface/latest/firebase_messaging_platform_interface/RemoteMessage/data.html)
/// See [APNs notification data](https://developer.apple.com/documentation/usernotifications/unnotificationcontent/1649869-userinfo)
/// Returns a map with custom payload from the notification or null if it's not provided.
@Deprecated("Consider removing this method calls. Qonversion is not working with push notifications anymore")
Future<Map<String, dynamic>?> getNotificationCustomPayload(Map<String, dynamic> notificationData);

/// Show the screen using its ID.
Expand Down
2 changes: 1 addition & 1 deletion macos/qonversion_flutter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
s.source_files = 'Classes/**/*'
s.dependency 'FlutterMacOS'
s.platform = :osx, '10.12'
s.dependency "QonversionSandwich", "5.1.4"
s.dependency "QonversionSandwich", "5.1.5"

s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
s.swift_version = '5.0'
Expand Down
Loading

0 comments on commit d9df2e2

Please sign in to comment.