From 777ca46ff901e7f454e7ba0184e9a1cda18a8dbe Mon Sep 17 00:00:00 2001 From: Hien Ho Date: Fri, 1 Nov 2024 11:32:53 +0700 Subject: [PATCH] update onesignal lib (#2279) --- lib/main.dart | 6 +++--- lib/screen/home/home_navigation_page.dart | 6 ++---- lib/util/notification_util.dart | 9 ++++----- pubspec.lock | 4 ++-- pubspec.yaml | 2 +- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 54eaabaf3..1b86963cc 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -106,9 +106,9 @@ Future runFeralFileApp() async { log.info('Error in AuFileService setup: $e'); } - OneSignal.shared.setLogLevel(OSLogLevel.error, OSLogLevel.none); - OneSignal.shared.setAppId(Environment.onesignalAppID); - + OneSignal.initialize(Environment.onesignalAppID); + OneSignal.Debug.setLogLevel(OSLogLevel.error); + SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle( statusBarColor: AppColor.white, statusBarIconBrightness: Brightness.dark, diff --git a/lib/screen/home/home_navigation_page.dart b/lib/screen/home/home_navigation_page.dart index 7f6ed53bc..b13293242 100644 --- a/lib/screen/home/home_navigation_page.dart +++ b/lib/screen/home/home_navigation_page.dart @@ -278,10 +278,9 @@ class HomeNavigationPageState extends State _triggerShowAnnouncement(); - OneSignal.shared.setNotificationWillShowInForegroundHandler((event) { + OneSignal.Notifications.addForegroundWillDisplayListener((event) { log.info('Receive notification: ${event.notification.additionalData}'); if (event.notification.additionalData == null) { - event.complete(null); return; } final additionalData = @@ -292,7 +291,6 @@ class HomeNavigationPageState extends State /// should complete event after getting all data needed /// and before calling async function - event.complete(null); Future.delayed(const Duration(milliseconds: 500), () async { await injector().fetchAnnouncements(); if (!mounted) { @@ -307,7 +305,7 @@ class HomeNavigationPageState extends State ); }); }); - OneSignal.shared.setNotificationOpenedHandler((openedResult) async { + OneSignal.Notifications.addClickListener((openedResult) async { log.info('Tapped push notification: ' '${openedResult.notification.additionalData}'); final additionalData = diff --git a/lib/util/notification_util.dart b/lib/util/notification_util.dart index 2d6c073bd..ec2efb728 100644 --- a/lib/util/notification_util.dart +++ b/lib/util/notification_util.dart @@ -22,7 +22,7 @@ Future registerPushNotifications({bool askPermission = false}) async { if (askPermission) { final permission = Platform.isAndroid ? true - : await OneSignal.shared.promptUserForPushNotificationPermission(); + : await OneSignal.Notifications.requestPermission(true); if (!permission) { return false; @@ -30,9 +30,8 @@ Future registerPushNotifications({bool askPermission = false}) async { } try { - final identityHash = await OneSignalHelper.getIdentityHash(); final primaryAddress = await injector().getPrimaryAddress(); - await OneSignal.shared.setExternalUserId(primaryAddress!, identityHash); + await OneSignal.login(primaryAddress!); await injector().setNotificationEnabled(true); return true; } catch (error) { @@ -45,13 +44,13 @@ Future registerPushNotifications({bool askPermission = false}) async { Future deregisterPushNotification() async { log.info('unregister notification'); - await OneSignal.shared.removeExternalUserId(); + await OneSignal.logout(); } class OneSignalHelper { static Future setExternalUserId( {required String userId, String? authHashToken}) async { - await OneSignal.shared.setExternalUserId(userId, authHashToken); + await OneSignal.login(userId); } static Future getIdentityHash() async { diff --git a/pubspec.lock b/pubspec.lock index fe1146ccb..1a82e4cac 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1925,10 +1925,10 @@ packages: dependency: "direct main" description: name: onesignal_flutter - sha256: f4e54ad09bbfc2401b5d3e9cda6b31577facf0dd119d282d008df5710f5665d0 + sha256: "28e8295c1e79b029d010c6af6459683b1e1485246d95d42f13bba15ca35a94ae" url: "https://pub.dev" source: hosted - version: "3.5.1" + version: "5.2.6" open_settings: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 5859a41fd..c7d38b78c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -75,7 +75,7 @@ dependencies: measured_size: ^1.0.0 mime: ^1.0.1 mixpanel_flutter: ^2.0.0 - onesignal_flutter: ^3.3.0 + onesignal_flutter: ^5.2.6 open_settings: ^2.0.2 overlay_support: ^2.0.0 package_info_plus: ^8.0.3