From d58f1031fb84a2128b8c7cb3e103fe259c6f68a6 Mon Sep 17 00:00:00 2001 From: Gautier de Lataillade <32983806+gdelataillade@users.noreply.github.com> Date: Wed, 22 Nov 2023 17:47:58 +0100 Subject: [PATCH] Increment plugin version to 3.0.0-dev.4 with some improvements --- CHANGELOG.md | 5 +++++ README.md | 17 ++++++++++++----- example/lib/screens/home.dart | 2 +- example/pubspec.lock | 2 +- ios/Classes/SwiftAlarmPlugin.swift | 2 +- lib/alarm.dart | 25 ++++++++++++++++++++----- pubspec.yaml | 2 +- 7 files changed, 41 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfe3144c..838152cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 3.0.0-dev.4 +* [iOS] Remove notification sound. +* Throw exception if alarm settings are invalid. +* Improve README. + ## 3.0.0-dev.3 * Update README. * Add minor improvements. diff --git a/README.md b/README.md index 4f900826..61e385cf 100644 --- a/README.md +++ b/README.md @@ -59,13 +59,14 @@ assetAudio | `String` | The path to you audio asset you want to use as rin loopAudio | `bool` | If true, audio will repeat indefinitely until alarm is stopped. vibrate | `bool` | If true, device will vibrate indefinitely until alarm is stopped. If [loopAudio] is set to false, vibrations will stop when audio ends. volume | `double` | Sets system volume level (0.0 to 1.0) at [dateTime]; reverts on alarm stop. Defaults to current volume if null. -when alarm is stopped. fadeDuration | `double` | Duration, in seconds, over which to fade the alarm volume. Set to 0.0 by default, which means no fade. -notificationTitle | `String` | The title of the notification triggered when alarm rings if app is on background. +notificationTitle | `String` | The title of the notification triggered when alarm rings. notificationBody | `String` | The body of the notification. enableNotificationOnKill | `bool` | Whether to show a notification when application is killed to warn the user that the alarm he set may not ring. Enabled by default. androidFullScreenIntent | `bool` | Whether to turn screen on when android alarm notification is triggered. Enabled by default. +Note that if `notificationTitle` and `notificationBody` are both empty, iOS will not show the notification and Android will show an empty notification. + If you enabled `enableNotificationOnKill`, you can chose your own notification title and body by using this method before setting your alarms: ```Dart await Alarm.setNotificationOnAppKillContent(title, body) @@ -85,7 +86,7 @@ To avoid unexpected behaviors, if you set an alarm for the same time as an exist ## 📱 Example app -Don't hesitate to check out the example's code, and take a look at the app: +Don't hesitate to check out the [example's code](https://github.com/gdelataillade/alarm/tree/main/example), and take a look at the app: ![home](https://github.com/gdelataillade/alarm/assets/32983806/695736aa-b55f-4050-8b0d-274b0d46714a) ![edit](https://github.com/gdelataillade/alarm/assets/32983806/05329836-9fbe-462c-aa1e-dce0fa70f455) @@ -101,8 +102,8 @@ Don't hesitate to check out the example's code, and take a look at the app: | While playing other media| ✅ | ✅ | ✅ | ✅ | App killed | 🤖 | 🤖 | 🤖 | ✅ -✅ : iOS and Android -🤖 : Android only. +✅ : iOS and Android.\ +🤖 : Android only.\ Silenced: Means that the notification is not shown directly on the top of the screen. You have to go in your notification center to see it. ## ❓ FAQ @@ -134,6 +135,12 @@ While periodic alarms can be implemented on Android, this is not feasible for iO Related issue [here](https://github.com/gdelataillade/alarm/issues/47#issuecomment-1820896276). +### Why was my app rejected by the App Store for guideline issues? + +The rejection may relate to plugin's background audio functionality, essential for alarm apps. Clarify in your submission that background activity is crucial for your alarm app to notify users effectively. Ensure compliance with Apple's guidelines on background processes. + +For more guidance, see: [App Store Rejection Issues](https://github.com/gdelataillade/alarm/discussions/87). + ## ⚙️ Under the hood ### Android diff --git a/example/lib/screens/home.dart b/example/lib/screens/home.dart index 7533a742..50b2a1f6 100644 --- a/example/lib/screens/home.dart +++ b/example/lib/screens/home.dart @@ -71,7 +71,7 @@ class _ExampleAlarmHomeScreenState extends State { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar(title: const Text('alarm 3.0.0-dev.3')), + appBar: AppBar(title: const Text('alarm 3.0.0-dev.4')), body: SafeArea( child: alarms.isNotEmpty ? ListView.separated( diff --git a/example/pubspec.lock b/example/pubspec.lock index 524950af..bdd8ac78 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: path: ".." relative: true source: path - version: "3.0.0-dev.3" + version: "3.0.0-dev.4" async: dependency: transitive description: diff --git a/ios/Classes/SwiftAlarmPlugin.swift b/ios/Classes/SwiftAlarmPlugin.swift index 076b3950..6b300614 100644 --- a/ios/Classes/SwiftAlarmPlugin.swift +++ b/ios/Classes/SwiftAlarmPlugin.swift @@ -436,7 +436,7 @@ public class SwiftAlarmPlugin: NSObject, FlutterPlugin { let content = UNMutableNotificationContent() content.title = title content.body = body - content.sound = UNNotificationSound.default + content.sound = nil let trigger = UNTimeIntervalNotificationTrigger(timeInterval: TimeInterval(delayInSeconds), repeats: false) let request = UNNotificationRequest(identifier: "alarm-\(id)", content: content, trigger: trigger) diff --git a/lib/alarm.dart b/lib/alarm.dart index d4b54550..0181886b 100644 --- a/lib/alarm.dart +++ b/lib/alarm.dart @@ -63,11 +63,7 @@ class Alarm { /// If you set an alarm for the same [dateTime] as an existing one, /// the new alarm will replace the existing one. static Future set({required AlarmSettings alarmSettings}) async { - if (!alarmSettings.assetAudioPath.contains('.')) { - throw AlarmException( - 'Provided asset audio file does not have extension: ${alarmSettings.assetAudioPath}', - ); - } + alarmSettingsValidation(alarmSettings); for (final alarm in Alarm.getAlarms()) { if (alarm.id == alarmSettings.id || @@ -95,6 +91,25 @@ class Alarm { return false; } + static void alarmSettingsValidation(AlarmSettings alarmSettings) { + if (!alarmSettings.assetAudioPath.contains('.')) { + throw AlarmException( + 'Provided audio path is not valid: ${alarmSettings.assetAudioPath}', + ); + } + if (alarmSettings.volume != null && + (alarmSettings.volume! < 0 || alarmSettings.volume! > 1)) { + throw AlarmException( + 'Volume must be between 0 and 1. Provided: ${alarmSettings.volume}', + ); + } + if (alarmSettings.fadeDuration < 0) { + throw AlarmException( + 'Fade duration must be positive. Provided: ${alarmSettings.fadeDuration}', + ); + } + } + /// When the app is killed, all the processes are terminated /// so the alarm may never ring. By default, to warn the user, a notification /// is shown at the moment he kills the app. diff --git a/pubspec.yaml b/pubspec.yaml index cf9701cb..84906cfc 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: 3.0.0-dev.3 +version: 3.0.0-dev.4 homepage: https://github.com/gdelataillade/alarm environment: