Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The presentSound parameter also affects background behaviour #2097

Closed
kazume opened this issue Sep 18, 2023 · 4 comments · Fixed by #2112
Closed

The presentSound parameter also affects background behaviour #2097

kazume opened this issue Sep 18, 2023 · 4 comments · Fixed by #2112

Comments

@kazume
Copy link

kazume commented Sep 18, 2023

Bug description

From the documentation

Indicates if a sound should be played when the notification is triggered while app is in the foreground.

the presentSound parameter should only affect the foreground behaviour of the notification sound (like it does for presentBanner), but setting it to false will also prevent the notification sound to be played when showing the notification while the app is in the background (tested on iOS).

EDIT: interestingly enough, it does work with a custom sound, so that'll be my workaround

To Reproduce

  1. In the example of this repository, change the presentSound parameter to false in the _zonedScheduleNotification method:
  Future<void> _zonedScheduleNotification() async {
    await flutterLocalNotificationsPlugin.zonedSchedule(
      0,
      'scheduled title',
      'scheduled body',
      tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)),
      const NotificationDetails(
        android: AndroidNotificationDetails(
          'your channel id',
          'your channel name',
          channelDescription: 'your channel description',
        ),
        iOS: DarwinNotificationDetails(
          presentSound: false,
        ),
      ),
      androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
      uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime,
    );
  }
  1. Launch the app (in my case: iPad Air (4th generation) with iOS 16.6)
  2. Select "Schedule notification to appear in 5 seconds based on local time zone"
  3. Send the app to the background before the notification appears
  4. Observe no sound when the notification appears

Expected behavior
I'd expect a sound on notification.

Flutter doctor -v output [✓] Flutter (Channel stable, 3.13.2, on macOS 13.5.1 22G90 darwin-x64, locale en-AT) • Flutter version 3.13.2 on channel stable at /Users/egon/Development/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision ff5b5b5fa6 (4 weeks ago), 2023-08-24 08:12:28 -0500 • Engine revision b20183e040 • Dart version 3.1.0 • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/egon/Library/Android/sdk
• Platform android-33, build-tools 34.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14E300c
• CocoaPods version 1.12.1

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• android-studio-dir = /Applications/Android Studio.app/Contents
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] VS Code (version 1.82.0)
• VS Code at /Users/egon/Development/Visual Studio Code.app/Contents
• Flutter extension version 3.72.0

[✓] Connected device (4 available)
• Egon’s (mobile) • 00008101-000A71A80A06001E • ios • iOS 16.6 20G75
• EFB (mobile) • CFFD813F-9D82-4D41-8D1B-68EC6DA2A3BD • ios • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
• macOS (desktop) • macos • darwin-x64 • macOS 13.5.1 22G90 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 116.0.5845.187

[✓] Network resources
• All expected network resources are available.

@MaikuB
Copy link
Owner

MaikuB commented Oct 3, 2023

Thanks for catching this. This a mistake in the documentation but potentially may need to consider how to fix this for the plugin. This is happening where a default sound is specified only if the code requests the sound to play via presentSound and no custom sound is specified. Normally apps would want consistency with foreground and background where possible so this likely why no one has caught this before. In saying that, I believe fixing it by amending the condition will align more to the native platform's behaviour. This may be a breaking change in behaviour to some so I'll add this to the 16.0 prerelease that will land on stable once Android 14 is out

@MaikuB
Copy link
Owner

MaikuB commented Oct 3, 2023

Actually on further thought, this is not as straightforward as some will want no sound to be played at all and developers are use to a null sound representing the default notification. I might have to consider a different approach. If you have an idea than feel free to share and/or submit a PR

@MaikuB
Copy link
Owner

MaikuB commented Oct 3, 2023

Just tried it and looks like passing any value to https://pub.dev/documentation/flutter_local_notifications/latest/flutter_local_notifications/DarwinNotificationDetails/sound.html whilst presentSound is false will allow the default sound to play so believe this will be the solution. Not sure if this is what you meant as well. I'd have to update the documentation for this scenario

@kazume
Copy link
Author

kazume commented Oct 6, 2023

Thx for the quick fix @MaikuB I'll test in the next week (althought it looks like I'll need a custom sound anyway with the default sound being too low for the application we're making).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants