From 20fa0882c79da13ed5ed93d19ad5e0e3de87c343 Mon Sep 17 00:00:00 2001 From: Gautier de Lataillade Date: Fri, 20 Sep 2024 12:37:22 +0200 Subject: [PATCH] Remove iOS notification permission request & increment to 4.0.0-dev.5 --- CHANGELOG.md | 4 ++ example/ios/Podfile | 7 ++ example/ios/Podfile.lock | 8 ++- example/lib/screens/home.dart | 20 +++++- example/lib/services/permission.dart | 2 +- example/pubspec.lock | 70 ++++++++++++++++++- example/pubspec.yaml | 2 +- .../services/NotificationManager.swift | 20 +++--- pubspec.yaml | 2 +- 9 files changed, 115 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c99a504f..711ac6cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.0.0-dev.5 +**💥 Breaking Changes** +* [iOS] Removed notification permission request. Must be handled in-app to match Android behaviour. + ## 4.0.0-dev.4 * [Android] Reschedule alarms after device reboot. diff --git a/example/ios/Podfile b/example/ios/Podfile index 279576f3..190e4ad9 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -37,5 +37,12 @@ end post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) + + target.build_configurations.each do |config| + config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [ + '$(inherited)', + 'PERMISSION_NOTIFICATIONS=1', + ] + end end end diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index ee190cad..86af024e 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -9,6 +9,8 @@ PODS: - shared_preferences_foundation (0.0.1): - Flutter - FlutterMacOS + - url_launcher_ios (0.0.1): + - Flutter DEPENDENCIES: - alarm (from `.symlinks/plugins/alarm/ios`) @@ -16,6 +18,7 @@ DEPENDENCIES: - flutter_fgbg (from `.symlinks/plugins/flutter_fgbg/ios`) - permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`) - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) + - url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`) EXTERNAL SOURCES: alarm: @@ -28,6 +31,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/permission_handler_apple/ios" shared_preferences_foundation: :path: ".symlinks/plugins/shared_preferences_foundation/darwin" + url_launcher_ios: + :path: ".symlinks/plugins/url_launcher_ios/ios" SPEC CHECKSUMS: alarm: 6c1f6a9688f94cd6bf8f104c67cc26e78c9d8d13 @@ -35,7 +40,8 @@ SPEC CHECKSUMS: flutter_fgbg: 31c0d1140a131daea2d342121808f6aa0dcd879d permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2 shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78 + url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe -PODFILE CHECKSUM: c4c93c5f6502fe2754f48404d3594bf779584011 +PODFILE CHECKSUM: 8af8e7ee73303366e8affe0fe6e44bcbddffaa5b COCOAPODS: 1.15.2 diff --git a/example/lib/screens/home.dart b/example/lib/screens/home.dart index 8a20d54f..3edd6af5 100644 --- a/example/lib/screens/home.dart +++ b/example/lib/screens/home.dart @@ -7,6 +7,9 @@ import 'package:alarm_example/screens/shortcut_button.dart'; import 'package:alarm_example/services/permission.dart'; import 'package:alarm_example/widgets/tile.dart'; import 'package:flutter/material.dart'; +import 'package:url_launcher/url_launcher.dart'; + +const version = '4.0.0-dev.4'; class ExampleAlarmHomeScreen extends StatefulWidget { const ExampleAlarmHomeScreen({super.key}); @@ -24,8 +27,8 @@ class _ExampleAlarmHomeScreenState extends State { @override void initState() { super.initState(); + AlarmPermissions.checkNotificationPermission(); if (Alarm.android) { - AlarmPermissions.checkAndroidNotificationPermission(); AlarmPermissions.checkAndroidScheduleExactAlarmPermission(); } loadAlarms(); @@ -71,6 +74,11 @@ class _ExampleAlarmHomeScreenState extends State { if (res != null && res == true) loadAlarms(); } + Future launchReadmeUrl() async { + final url = Uri.parse('https://pub.dev/packages/alarm/versions/$version'); + await launchUrl(url); + } + @override void dispose() { ringSubscription?.cancel(); @@ -81,7 +89,15 @@ class _ExampleAlarmHomeScreenState extends State { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar(title: const Text('alarm 4.0.0-dev.4')), + appBar: AppBar( + title: const Text('alarm $version'), + actions: [ + IconButton( + icon: const Icon(Icons.menu_book_rounded), + onPressed: launchReadmeUrl, + ), + ], + ), body: SafeArea( child: alarms.isNotEmpty ? ListView.separated( diff --git a/example/lib/services/permission.dart b/example/lib/services/permission.dart index 0627ba8d..64b39f11 100644 --- a/example/lib/services/permission.dart +++ b/example/lib/services/permission.dart @@ -2,7 +2,7 @@ import 'package:alarm/alarm.dart'; import 'package:permission_handler/permission_handler.dart'; class AlarmPermissions { - static Future checkAndroidNotificationPermission() async { + static Future checkNotificationPermission() async { final status = await Permission.notification.status; if (status.isDenied) { alarmPrint('Requesting notification permission...'); diff --git a/example/pubspec.lock b/example/pubspec.lock index ce2ab0de..89073bff 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: path: ".." relative: true source: path - version: "4.0.0-dev.4" + version: "4.0.0-dev.5" async: dependency: transitive description: @@ -356,6 +356,70 @@ packages: url: "https://pub.dev" source: hosted version: "0.7.2" + url_launcher: + dependency: "direct main" + description: + name: url_launcher + sha256: "21b704ce5fa560ea9f3b525b43601c678728ba46725bab9b01187b4831377ed3" + url: "https://pub.dev" + source: hosted + version: "6.3.0" + url_launcher_android: + dependency: transitive + description: + name: url_launcher_android + sha256: e35a698ac302dd68e41f73250bd9517fe3ab5fa4f18fe4647a0872db61bacbab + url: "https://pub.dev" + source: hosted + version: "6.3.10" + url_launcher_ios: + dependency: transitive + description: + name: url_launcher_ios + sha256: e43b677296fadce447e987a2f519dcf5f6d1e527dc35d01ffab4fff5b8a7063e + url: "https://pub.dev" + source: hosted + version: "6.3.1" + url_launcher_linux: + dependency: transitive + description: + name: url_launcher_linux + sha256: e2b9622b4007f97f504cd64c0128309dfb978ae66adbe944125ed9e1750f06af + url: "https://pub.dev" + source: hosted + version: "3.2.0" + url_launcher_macos: + dependency: transitive + description: + name: url_launcher_macos + sha256: "9a1a42d5d2d95400c795b2914c36fdcb525870c752569438e4ebb09a2b5d90de" + url: "https://pub.dev" + source: hosted + version: "3.2.0" + url_launcher_platform_interface: + dependency: transitive + description: + name: url_launcher_platform_interface + sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029" + url: "https://pub.dev" + source: hosted + version: "2.3.2" + url_launcher_web: + dependency: transitive + description: + name: url_launcher_web + sha256: "772638d3b34c779ede05ba3d38af34657a05ac55b06279ea6edd409e323dca8e" + url: "https://pub.dev" + source: hosted + version: "2.3.3" + url_launcher_windows: + dependency: transitive + description: + name: url_launcher_windows + sha256: "49c10f879746271804767cb45551ec5592cdab00ee105c06dddde1a98f73b185" + url: "https://pub.dev" + source: hosted + version: "3.1.2" vector_math: dependency: transitive description: @@ -397,5 +461,5 @@ packages: source: hosted version: "1.0.4" sdks: - dart: ">=3.4.0 <4.0.0" - flutter: ">=3.22.0" + dart: ">=3.5.0 <4.0.0" + flutter: ">=3.24.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 757dec9b..e4bd5d72 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -14,7 +14,7 @@ dependencies: flutter: sdk: flutter permission_handler: ^11.1.0 - + url_launcher: ^6.3.0 dev_dependencies: flutter_test: diff --git a/ios/Classes/services/NotificationManager.swift b/ios/Classes/services/NotificationManager.swift index ca363213..e1a69204 100644 --- a/ios/Classes/services/NotificationManager.swift +++ b/ios/Classes/services/NotificationManager.swift @@ -20,31 +20,29 @@ class NotificationManager: NSObject, UNUserNotificationCenterDelegate { UNUserNotificationCenter.current().delegate = self } - func requestAuthorization(completion: @escaping (Bool, Error?) -> Void) { - UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge], completionHandler: completion) - } - func scheduleNotification(id: Int, delayInSeconds: Int, notificationSettings: NotificationSettings, completion: @escaping (Error?) -> Void) { - requestAuthorization { granted, error in - guard granted, error == nil else { + UNUserNotificationCenter.current().getNotificationSettings { settings in + guard settings.authorizationStatus == .authorized else { + NSLog("[NotificationManager] Notification permission not granted. Cannot schedule alarm notification. Please request permission first.") + let error = NSError(domain: "NotificationManager", code: 1, userInfo: [NSLocalizedDescriptionKey: "Notification permission not granted"]) completion(error) return } - + if let stopButton = notificationSettings.stopButton { self.setupNotificationActions(stopButton: stopButton) } - + let content = UNMutableNotificationContent() content.title = notificationSettings.title content.body = notificationSettings.body content.sound = nil content.categoryIdentifier = "ALARM_CATEGORY" content.userInfo = ["id": id] - + let trigger = UNTimeIntervalNotificationTrigger(timeInterval: TimeInterval(delayInSeconds), repeats: false) let request = UNNotificationRequest(identifier: "alarm-\(id)", content: content, trigger: trigger) - + UNUserNotificationCenter.current().add(request, withCompletionHandler: completion) } } @@ -74,4 +72,4 @@ class NotificationManager: NSObject, UNUserNotificationCenterDelegate { func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { completionHandler([.alert, .sound]) } -} +} \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 315d53ae..e298b874 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: alarm description: A simple Flutter alarm manager plugin for both iOS and Android. -version: 4.0.0-dev.4 +version: 4.0.0-dev.5 homepage: https://github.com/gdelataillade/alarm environment: