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

iOS Background Custom Sound Not Working #2333

Open
bedirhanayydin opened this issue Jun 3, 2024 · 7 comments
Open

iOS Background Custom Sound Not Working #2333

bedirhanayydin opened this issue Jun 3, 2024 · 7 comments

Comments

@bedirhanayydin
Copy link

bedirhanayydin commented Jun 3, 2024

Hello, the code I wrote works on both iOS and Android. On iOS, the custom notification sound plays when the app is in the foreground. However, when the app is in the background, notifications are received but the notification sound doesn't play. How can I solve this issue on iOS?

import 'package:flutter_local_notifications/flutter_local_notifications.dart';

void sendNotification({String? title, String? body}) async {
  FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();

  // iOS (Darwin) settings
  const DarwinInitializationSettings initializationSettingsIOS = DarwinInitializationSettings(
    requestSoundPermission: true,
    requestBadgePermission: true,
    requestAlertPermission: true,
  );
  const InitializationSettings initializationSettings = InitializationSettings(
    iOS: initializationSettingsIOS,
  );
  await flutterLocalNotificationsPlugin.initialize(
    initializationSettings,
  );

 

  DarwinNotificationDetails iosNotificationDetails = DarwinNotificationDetails(
    sound: "slow_spring_board.mp3",
    presentSound: true,
    presentAlert: true,
    presentBadge: true,
  );

  flutterLocalNotificationsPlugin.show(
    0,
    title,
    body,
    NotificationDetails(
      iOS: iosNotificationDetails,
    ),
  );
}

@Blacktaler
Copy link

having the same problem

@bedirhanayydin
Copy link
Author

@MaikuB can you help us

@MaikuB
Copy link
Owner

MaikuB commented Jun 12, 2024

Are you using FCM?

@MaikuB
Copy link
Owner

MaikuB commented Jun 12, 2024

yes

There's your answer then. Please make sure you're distinguishing between FCM and this plugin that when you raise an issue and include code that it actually reproduces the issue specific to this plugin. The native APIs that the plugin don't behave differently based on if the app is in the foreground or not. A relatively easy way to reproduce this is schedule a notification using the plugin and kill the app so that the scheduled notification appears whilst the app is killed

@bedirhanayydin
Copy link
Author

My codes are above, where do you think I'm making a mistake?

@MaikuB
Copy link
Owner

MaikuB commented Jun 12, 2024

This isn't about a coding mistake and I don't specifically help with debugging an individual's code. As mentioned in my previous post you'll need to make sure you understand how FCM works

@bedirhanayydin
Copy link
Author

Thank you, I actually understood the fcm, but I just didn't understand why the custom sound I get when the application is open does not play the same sound when the application is closed.

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

No branches or pull requests

3 participants