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

Notification sound too slow with default and customs sounds #2311

Open
iSaqibShafique opened this issue Apr 23, 2024 · 1 comment
Open

Notification sound too slow with default and customs sounds #2311

iSaqibShafique opened this issue Apr 23, 2024 · 1 comment

Comments

@iSaqibShafique
Copy link

Describe the bug
I was using custom audios in Android and for iOS, Android is working good, but in iOS these are the problems.
1 - Notification sound too slow when notify.
2 - When using custom sound Notifications not working in iOS.

To Reproduce

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

Sample code to reproduce the problem
static Future init() async {
const AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('logo');
final DarwinInitializationSettings initializationSettingsDarwin =
DarwinInitializationSettings(
onDidReceiveLocalNotification: (id, title, body, payload) =>
Get.toNamed(AppRoutes.home, arguments: 3),
requestSoundPermission: true,
requestAlertPermission: true,
);
const LinuxInitializationSettings initializationSettingsLinux =
LinuxInitializationSettings(defaultActionName: 'Open notification');
final InitializationSettings initializationSettings =
InitializationSettings(
android: initializationSettingsAndroid,
iOS: initializationSettingsDarwin,
linux: initializationSettingsLinux,
);

await flutterLocalNotificationsPlugin.initialize(initializationSettings);

}

static Future showScheduleNotifications({
required DateTime notificationTime,
required String bodyText,
String? audio,
}) async {
try {
int notificationId = notificationTime.millisecondsSinceEpoch ~/ 1000;
AndroidNotificationDetails androidNotificationDetails =
AndroidNotificationDetails(
notificationId.toString(),
notificationId.toString(),
channelDescription: notificationId.toString(),
importance: Importance.max,
priority: Priority.high,
ticker: 'ticker',
sound: RawResourceAndroidNotificationSound(audio),
enableVibration: true,
);
NotificationDetails notificationDetails = NotificationDetails(
android: androidNotificationDetails,
iOS: const DarwinNotificationDetails(),
);

  if (notificationTime.isAfter(DateTime.now())) {
    await flutterLocalNotificationsPlugin.zonedSchedule(
      notificationId, // Use a distinct notification ID
      "Pink Elephants Coaching Company",
      bodyText,
      tz.TZDateTime.from(notificationTime, tz.local),
      notificationDetails,
      uiLocalNotificationDateInterpretation:
          UILocalNotificationDateInterpretation.absoluteTime,
      // ignore: deprecated_member_use
      androidAllowWhileIdle: true,
      payload: "home",
    );
  }
} catch (e) {
  print(
      "Error scheduling notification: $e");
}

}

@iSaqibShafique
Copy link
Author

Attention, also when I give custom sounds, it plays on earpiece not on speaker in iOS.

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

1 participant