I’m trying to send notifications with custom sounds based on the type of notification in my Flutter app. While the implementation works fine on Android, I’m having trouble with the iOS part.
Here’s the relevant portion of my code:
await initRealm();
_initAuth();
_initPublication();
_initResetPassword();
_initNotificationConfig();
await dotenv.load(fileName: ".env");
serviceLocator.registerLazySingleton<MenuCubit>(() => MenuCubit());
serviceLocator.registerLazySingleton<AppUserCubit>(() => AppUserCubit());
AwesomeNotifications().createNotification(
content: NotificationContent(
id: 20,
channelKey: 'owod_res_custom6',
title: 'Custom Notification',
body: 'This is a custom notification with custom sound.',
notificationLayout: NotificationLayout.Default,
),
);
}
Future<void> _initNotificationConfig() async {
// Initialize local notifications
AwesomeNotifications().initialize(
null,
[
NotificationChannel(
channelKey: 'owod_res_custom',
channelName: 'Custom Notifications',
channelDescription: 'Notification channel for custom sounds',
defaultColor: Color(0xFF9D50DD),
ledColor: AppTheme.tertiaryColor,
importance: NotificationImportance.High,
soundSource: 'resource://raw/tunnel',
playSound: true
// Android
),
NotificationChannel(
channelKey: 'owod_res_custom6',
channelName: 'Custom Notifications 2',
channelDescription: 'Notification channel for custom sounds',
defaultColor: Color(0xFF9D50DD),
ledColor: AppTheme.tertiaryColor,
importance: NotificationImportance.High,
soundSource: 'custom_sound.caf',
playSound: true
// iOS
),
],
debug: true,
);
AwesomeNotifications()
.setListeners(onActionReceivedMethod: onActionReceivedMethod);
}
And here’s my project Runner structure:
├── Resources
│ ├── custom_sound.mp3
│ └── tunnel.caf
├── Runner-Bridging-Header.h
└── custom_sound.caf
I’ve tried the following for the soundSource:
resource://raw/tunnel
custom_sound.caf
However, the custom sound isn’t playing on iOS. I made sure to include the sound files in the Xcode project under the Resources directory.
What I’ve tried:
Ensuring the sound files are in the correct format and accessible in the project.
Setting debug: true in AwesomeNotifications().initialize() for debugging, but I can’t find any helpful logs.
Testing on a real device, since the simulator doesn’t support push notifications.
Questions:
How should I correctly reference the custom sound file for iOS in the soundSource field?
Are there any specific configurations or steps that I might be missing for custom sounds on iOS?
Any advice on how to troubleshoot this issue effectively?
Any help would be greatly appreciated!