diff --git a/.gitignore b/.gitignore index 96486fd9..150724ac 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,7 @@ migrate_working_dir/ .dart_tool/ .packages build/ + +# Debug assets +assets/blank.mp3 +assets/not_blank.mp3 \ No newline at end of file diff --git a/README.md b/README.md index 63a7607b..abdfad00 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ This Flutter plugin provides a simple and easy-to-use interface for setting and ## 🔧 Installation steps +Please carefully follow these installation steps. They have been updated for plugin version `2.0.0`. + ### [iOS Setup](https://github.com/gdelataillade/alarm/blob/feat/ios-background-fetch/help/INSTALL-IOS.md) ### [Android Setup](https://github.com/gdelataillade/alarm/blob/feat/ios-background-fetch/help/INSTALL-ANDROID.md) @@ -113,8 +115,8 @@ Several factors could prevent your alarm from ringing: ### My alarm is not firing on a specific Android device Some Android manufacturers prefer battery life over proper functionality of your apps. Check out [dontkillmyapp.com](https://dontkillmyapp.com) to find out about more about optimizations done by different vendors, and potential workarounds. -Most common workaround is to ask the user to disable battery optimization settings. -*Source: [https://pub.dev/packages/android_alarm_manager_plus#faq](https://pub.dev/packages/android_alarm_manager_plus#faq)* +Most common solution is to educate users to disable **battery optimization** settings. +*Source: [android_alarm_manager_plus FAQ](https://pub.dev/packages/android_alarm_manager_plus#faq)* ### How can I increase the reliability of the alarm ringing? diff --git a/example/pubspec.lock b/example/pubspec.lock index e7dadc11..44034bc6 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: path: ".." relative: true source: path - version: "2.0.0-dev.4" + version: "2.0.0-dev.5" android_alarm_manager_plus: dependency: transitive description: @@ -195,10 +195,10 @@ packages: dependency: transitive description: name: just_audio - sha256: "890cd0fc41a1a4530c171e375a2a3fb6a09d84e9d508c5195f40bcff54330327" + sha256: "5ed0cd723e17dfd8cd4b0253726221e67f6546841ea4553635cf895061fc335b" url: "https://pub.dev" source: hosted - version: "0.9.34" + version: "0.9.35" just_audio_platform_interface: dependency: transitive description: @@ -404,6 +404,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.10.0" + sprintf: + dependency: transitive + description: + name: sprintf + sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23" + url: "https://pub.dev" + source: hosted + version: "7.0.0" stack_trace: dependency: transitive description: @@ -464,10 +472,10 @@ packages: dependency: transitive description: name: uuid - sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313" + sha256: e03928880bdbcbf496fb415573f5ab7b1ea99b9b04f669c01104d085893c3134 url: "https://pub.dev" source: hosted - version: "3.0.7" + version: "4.0.0" vector_math: dependency: transitive description: @@ -504,18 +512,18 @@ packages: dependency: transitive description: name: win32 - sha256: "9e82a402b7f3d518fb9c02d0e9ae45952df31b9bf34d77baf19da2de03fc2aaa" + sha256: c97defd418eef4ec88c0d1652cdce84b9f7b63dd7198e266d06ac1710d527067 url: "https://pub.dev" source: hosted - version: "5.0.7" + version: "5.0.8" win32_registry: dependency: transitive description: name: win32_registry - sha256: e4506d60b7244251bc59df15656a3093501c37fb5af02105a944d73eb95be4c9 + sha256: "41fd8a189940d8696b1b810efb9abcf60827b6cbfab90b0c43e8439e3a39d85a" url: "https://pub.dev" source: hosted - version: "1.1.1" + version: "1.1.2" xdg_directories: dependency: transitive description: @@ -533,5 +541,5 @@ packages: source: hosted version: "6.3.0" sdks: - dart: ">=3.1.0-185.0.dev <4.0.0" + dart: ">=3.1.0 <4.0.0" flutter: ">=3.7.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 1d689d6e..6779e96c 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -2,19 +2,11 @@ name: alarm_example description: Demonstrates how to use the alarm plugin. version: 0.1.2 -# The following line prevents the package from being accidentally published to -# pub.dev using `flutter pub publish`. This is preferred for private packages. -publish_to: 'none' # Remove this line if you wish to publish to pub.dev +publish_to: 'none' environment: - sdk: '>=2.19.0 <3.0.0' + sdk: '>=3.0.0 <4.0.0' -# Dependencies specify other packages that your package needs in order to work. -# To automatically upgrade your package dependencies to the latest versions -# consider running `flutter pub upgrade --major-versions`. Alternatively, -# dependencies can be manually updated by changing the version numbers below to -# the latest version available on pub.dev. To see which dependencies have newer -# versions available, run `flutter pub outdated`. dependencies: flutter: sdk: flutter @@ -27,62 +19,21 @@ dependencies: # the parent directory to use the current plugin's version. path: ../ - # The following adds the Cupertino Icons font to your application. - # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 dev_dependencies: flutter_test: sdk: flutter - # The "flutter_lints" package below contains a set of recommended lints to - # encourage good coding practices. The lint set provided by the package is - # activated in the `analysis_options.yaml` file located at the root of your - # package. See that file for information about deactivating specific lint - # rules and activating additional ones. flutter_lints: ^2.0.0 -# For information on the generic Dart part of this file, see the -# following page: https://dart.dev/tools/pub/pubspec - -# The following section is specific to Flutter packages. flutter: - # The following line ensures that the Material Icons font is - # included with your application, so that you can use the icons in - # the material Icons class. uses-material-design: true - # To add assets to your application, add an assets section, like this: assets: - assets/mozart.mp3 - assets/nokia.mp3 - assets/one_piece.mp3 - assets/star_wars.mp3 - - assets/marimba.mp3 - - # An image asset can refer to one or more resolution-specific "variants", see - # https://flutter.dev/assets-and-images/#resolution-aware - - # For details regarding adding assets from package dependencies, see - # https://flutter.dev/assets-and-images/#from-packages - - # To add custom fonts to your application, add a fonts section here, - # in this "flutter" section. Each entry in this list should have a - # "family" key with the font family name, and a "fonts" key with a - # list giving the asset and other descriptors for the font. For - # example: - # fonts: - # - family: Schyler - # fonts: - # - asset: fonts/Schyler-Regular.ttf - # - asset: fonts/Schyler-Italic.ttf - # style: italic - # - family: Trajan Pro - # fonts: - # - asset: fonts/TrajanPro.ttf - # - asset: fonts/TrajanPro_Bold.ttf - # weight: 700 - # - # For details regarding fonts from package dependencies, - # see https://flutter.dev/custom-fonts/#from-packages + - assets/marimba.mp3 \ No newline at end of file diff --git a/ios/Classes/SwiftAlarmPlugin.swift b/ios/Classes/SwiftAlarmPlugin.swift index 9a157ca1..985e5a4d 100644 --- a/ios/Classes/SwiftAlarmPlugin.swift +++ b/ios/Classes/SwiftAlarmPlugin.swift @@ -171,7 +171,6 @@ public class SwiftAlarmPlugin: NSObject, FlutterPlugin { self.playSilent = true self.silentAudioPlayer?.play() NotificationCenter.default.addObserver(self, selector: #selector(handleInterruption), name: AVAudioSession.interruptionNotification, object: nil) - // self.loopSilentSound() } catch { NSLog("SwiftAlarmPlugin: Error: Could not create and play audio player: \(error)") } @@ -199,21 +198,17 @@ public class SwiftAlarmPlugin: NSObject, FlutterPlugin { } } - // private func loopSilentSound() { - // self.silentAudioPlayer?.play() - // NSLog("SwiftAlarmPlugin: Playing silent audio...") - - // DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { - // self.silentAudioPlayer?.pause() - // NSLog("SwiftAlarmPlugin: Paused silent audio...") - - // DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) { - // if self.playSilent { - // self.loopSilentSound() - // } - // } - // } - // } + private func loopSilentSound() { + self.silentAudioPlayer?.play() + DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { + self.silentAudioPlayer?.pause() + DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) { + if self.playSilent { + self.loopSilentSound() + } + } + } + } private func handleAlarmAfterDelay(id: Int, triggerTime: Date, fadeDuration: Double, vibrationsEnabled: Bool, audioLoop: Bool, volumeMax: Bool) { guard let audioPlayer = self.audioPlayers[id], let storedTriggerTime = triggerTimes[id], triggerTime == storedTriggerTime else { @@ -317,10 +312,7 @@ public class SwiftAlarmPlugin: NSObject, FlutterPlugin { } } - // Runs when a background fetch event is triggered private func backgroundFetch() { - NSLog("SwiftAlarmPlugin: -> Background fetch !") - self.mixOtherAudios() self.silentAudioPlayer?.pause() @@ -334,7 +326,6 @@ public class SwiftAlarmPlugin: NSObject, FlutterPlugin { let dateTime = self.triggerTimes[id]! let currentTime = audioPlayer.deviceCurrentTime let time = currentTime + dateTime.timeIntervalSinceNow - // self.audioPlayers[id]!.stop() self.audioPlayers[id]!.play(atTime: time) } @@ -363,7 +354,7 @@ public class SwiftAlarmPlugin: NSObject, FlutterPlugin { if let error = error { NSLog("SwiftAlarmPlugin: Failed to show notification on kill service => error: \(error.localizedDescription)") } else { - NSLog("SwiftAlarmPlugin: Show notification on kill now") + NSLog("SwiftAlarmPlugin: Trigger notification on app kill") } } } @@ -386,10 +377,8 @@ public class SwiftAlarmPlugin: NSObject, FlutterPlugin { } } - // Runs from AppDelegate when the app is launched + /// Runs from AppDelegate when the app is launched static public func registerBackgroundTasks() { - NSLog("SwiftAlarmPlugin: -> registerBackgroundTasks !") - if #available(iOS 13.0, *) { BGTaskScheduler.shared.register(forTaskWithIdentifier: backgroundTaskIdentifier, using: nil) { task in self.scheduleAppRefresh() @@ -401,10 +390,8 @@ public class SwiftAlarmPlugin: NSObject, FlutterPlugin { } } - // Enables background fetch + /// Enables background fetch static func scheduleAppRefresh() { - NSLog("SwiftAlarmPlugin: -> scheduleAppRefresh !") - if #available(iOS 13.0, *) { let request = BGAppRefreshTaskRequest(identifier: backgroundTaskIdentifier) @@ -419,10 +406,8 @@ public class SwiftAlarmPlugin: NSObject, FlutterPlugin { } } - // Disable background fetch + /// Disables background fetch static func cancelBackgroundTasks() { - NSLog("SwiftAlarmPlugin: -> cancelBackgroundTasks !") - if #available(iOS 13.0, *) { BGTaskScheduler.shared.cancel(taskRequestWithIdentifier: backgroundTaskIdentifier) } else { diff --git a/pubspec.yaml b/pubspec.yaml index 6fbee0d8..1cd3ecb2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ version: 2.0.0-dev.5 homepage: https://github.com/gdelataillade/alarm environment: - sdk: '>=2.18.5 <4.0.0' + sdk: '>=3.0.0 <4.0.0' flutter: ">=2.5.0" dependencies: