Skip to content

Commit d9df2e2

Browse files
authored
Merge pull request #359 from qonversion/tech/sc-35135/deprecatePushToken
The `setNotificationToken`, `handleNotification`, and `getNotificationCustomPayload` methods were marked as deprecated.
2 parents cd1d1ba + 4a6e980 commit d9df2e2

File tree

11 files changed

+218
-293
lines changed

11 files changed

+218
-293
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ android {
5151

5252
dependencies {
5353
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
54-
implementation "io.qonversion.sandwich:sandwich:5.1.4"
54+
implementation "io.qonversion.sandwich:sandwich:5.1.5"
5555
implementation 'com.google.code.gson:gson:2.9.0'
5656
}

example/lib/constants.dart

Lines changed: 0 additions & 5 deletions
This file was deleted.

example/lib/handling_notification.dart

Lines changed: 0 additions & 41 deletions
This file was deleted.

example/lib/home.dart

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import 'dart:async';
22
import 'dart:io';
33

4-
import 'package:firebase_messaging/firebase_messaging.dart';
54
import 'package:flutter/foundation.dart';
65
import 'package:flutter/material.dart';
76
import 'package:qonversion_flutter/qonversion_flutter.dart';
8-
import 'handling_notification.dart';
97

108
class HomeView extends StatefulWidget {
119
@override
@@ -27,24 +25,6 @@ class _HomeViewState extends State<HomeView> {
2725
super.initState();
2826
_initPlatformState();
2927

30-
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
31-
showNotification(message);
32-
});
33-
34-
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage? message) {
35-
if (message != null) {
36-
onNotificationClick(message.data);
37-
}
38-
});
39-
40-
FirebaseMessaging.instance
41-
.getInitialMessage()
42-
.then((RemoteMessage? message) {
43-
if (message != null) {
44-
onNotificationClick(message.data);
45-
}
46-
});
47-
4828
_shownScreensStream =
4929
Automations.getSharedInstance().shownScreensStream.listen((event) {
5030
// do any logic you need
@@ -177,7 +157,6 @@ class _HomeViewState extends State<HomeView> {
177157
.build();
178158
Qonversion.initialize(config);
179159
Qonversion.getSharedInstance().collectAppleSearchAdsAttribution();
180-
_sendNotificationsToken();
181160
_loadQonversionObjects();
182161
}
183162

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

197-
Future<void> _sendNotificationsToken() async {
198-
String? deviceToken;
199-
switch (defaultTargetPlatform) {
200-
case TargetPlatform.android:
201-
{
202-
deviceToken = await FirebaseMessaging.instance.getToken();
203-
}
204-
break;
205-
206-
case TargetPlatform.iOS:
207-
{
208-
deviceToken = await FirebaseMessaging.instance.getAPNSToken();
209-
}
210-
break;
211-
default:
212-
deviceToken = null;
213-
break;
214-
}
215-
216-
if (deviceToken != null) {
217-
Automations.getSharedInstance().setNotificationsToken(deviceToken);
218-
print('Device token: $deviceToken');
219-
}
220-
}
221-
222176
List<Widget> _entitlementsFromMap(Map<String, QEntitlement> entitlements) {
223177
return entitlements.entries.map<Widget>((e) {
224178
var title = e.value.productId +

example/lib/main.dart

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,12 @@
1-
import 'dart:io';
2-
31
import 'package:flutter/material.dart';
4-
import 'package:qonversion_example/constants.dart';
52

6-
import 'handling_notification.dart';
73
import 'home.dart';
84
import 'params_view.dart';
95
import 'products_view.dart';
106
import 'dart:async';
117

12-
import 'package:firebase_core/firebase_core.dart';
13-
import 'package:firebase_messaging/firebase_messaging.dart';
14-
import 'package:flutter/foundation.dart';
15-
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
16-
import 'dart:convert';
17-
18-
/// Define a top-level named handler which background/terminated messages will
19-
/// call.
20-
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
21-
print('Handling a background message ${message.messageId}');
22-
showNotification(message);
23-
}
24-
25-
/// Initialize the [FlutterLocalNotificationsPlugin] package.
26-
late FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
27-
28-
/// Create a [AndroidNotificationChannel] for heads up notifications
29-
late AndroidNotificationChannel channel;
30-
318
Future<void> main() async {
329
WidgetsFlutterBinding.ensureInitialized();
33-
await Firebase.initializeApp();
34-
35-
// Set the background messaging handler early on, as a named top-level function
36-
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
37-
38-
if (!kIsWeb) {
39-
channel = const AndroidNotificationChannel(
40-
Constants.channelId, // id
41-
Constants.channelName, // name
42-
importance: Importance.high,
43-
);
44-
45-
/// Configure FlutterLocalNotificationsPlugin
46-
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
47-
var initializationSettingsAndroid =
48-
AndroidInitializationSettings('launch_background');
49-
var initializationSettingsIOS = DarwinInitializationSettings(
50-
requestAlertPermission: true,
51-
requestBadgePermission: true,
52-
requestSoundPermission: false);
53-
var initializationSettings = InitializationSettings(
54-
android: initializationSettingsAndroid, iOS: initializationSettingsIOS);
55-
56-
await flutterLocalNotificationsPlugin.initialize(initializationSettings,
57-
onDidReceiveNotificationResponse: (NotificationResponse details) async {
58-
var notificationData = jsonDecode(details.payload ?? "{}");
59-
onNotificationClick(notificationData);
60-
});
61-
62-
/// Create an Android Notification Channel.
63-
await flutterLocalNotificationsPlugin
64-
.resolvePlatformSpecificImplementation<
65-
AndroidFlutterLocalNotificationsPlugin>()
66-
?.createNotificationChannel(channel);
67-
68-
/// Update the iOS foreground notification presentation options to allow heads up notifications.
69-
await FirebaseMessaging.instance
70-
.setForegroundNotificationPresentationOptions(
71-
alert: true,
72-
badge: true,
73-
sound: true,
74-
);
75-
}
76-
/// Grant entitlements for iOS
77-
if (Platform.isIOS) {
78-
NotificationSettings settings =
79-
await FirebaseMessaging.instance.requestPermission(
80-
announcement: true,
81-
carPlay: true,
82-
criticalAlert: true,
83-
);
84-
85-
if (settings.authorizationStatus == AuthorizationStatus.authorized) {
86-
print('User granted permission');
87-
} else if (settings.authorizationStatus ==
88-
AuthorizationStatus.provisional) {
89-
print('User granted provisional permission');
90-
} else {
91-
print('User declined or has not accepted permission');
92-
}
93-
}
9410

9511
runApp(SampleApp());
9612
}

example/pubspec.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ dependencies:
1313
flutter:
1414
sdk: flutter
1515

16-
firebase_messaging: ^11.0.0
17-
flutter_local_notifications: ^17.2.2
18-
1916
dependency_overrides:
2017
firebase_core_platform_interface: 4.5.1
2118

ios/qonversion_flutter.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616
s.source_files = 'Classes/**/*'
1717
s.dependency 'Flutter'
1818
s.platform = :ios, '9.0'
19-
s.dependency "QonversionSandwich", "5.1.4"
19+
s.dependency "QonversionSandwich", "5.1.5"
2020

2121
# Flutter.framework does not contain a i386 slice. Only x86_64 simulators are supported.
2222
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' }

lib/src/automations.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,22 @@ abstract class Automations {
5151

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

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

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

6972
/// Show the screen using its ID.

macos/qonversion_flutter.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616
s.source_files = 'Classes/**/*'
1717
s.dependency 'FlutterMacOS'
1818
s.platform = :osx, '10.12'
19-
s.dependency "QonversionSandwich", "5.1.4"
19+
s.dependency "QonversionSandwich", "5.1.5"
2020

2121
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
2222
s.swift_version = '5.0'

0 commit comments

Comments
 (0)