MaikuB / flutter_local_notifications

A Flutter plugin for displaying local notifications on Android, iOS, macOS and Linux
2.47k stars 1.4k forks source link

Notification sound too slow with default and customs sounds #2311

Closed iSaqibShafique closed 3 days ago

iSaqibShafique commented 6 months ago

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 commented 6 months ago

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

bedirhanayydin commented 5 months ago

Could you solve the problem? I have the same problem.

MaikuB commented 5 months ago

For all the issues you're reporting, I don't see how any of them are to do with the plugin especially when you already say the default sound is slow. Furthermore, you mention sounds playing on earpiece not on the speaker. All of these device related and the native APIs don't provide any capability on where the audio should play let alone the plugin.

As for custom sound not working, this would be an issue in your app to resolve in making you set things up properly. This would be for you to resolve and the example app shows that this is working.

iSaqibShafique commented 5 months ago

Could you solve the problem? I have the same problem.

Yes I did by changing the getting permission method to this.

if (Platform.isAndroid) { await Permission.notification.isDenied.then((value) { if (value) { Permission.notification.request(); } }); } else { await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< IOSFlutterLocalNotificationsPlugin>() ?.requestPermissions( alert: true, badge: true, sound: true, critical: true, provisional: true, ); }

MaikuB commented 3 days ago

Sounds like you identified the cause so closing this