簡體   English   中英

Flutter 本地通知,自定義聲音不適用於 iOS

[英]Flutter local notifications, custom sound not working for iOS

我在我的項目中使用flutter_local_notifications: 4.0.1+2 出現通知我正在嘗試在 iOS 上播放自定義聲音。 我嘗試以下為 iOS 實現自定義聲音,但它不起作用:

  flutterLocalNotificationsPlugin
  .resolvePlatformSpecificImplementation<
      IOSFlutterLocalNotificationsPlugin>()
  ?.requestPermissions(
    alert: true,
    badge: true,
    sound: true,
  );

  var initializationSettings = InitializationSettings(
  android: initializationSettingsAndroid, iOS: initializationSettingsIOS);
  flutterLocalNotificationsPlugin.initialize(initializationSettings);

  const AndroidNotificationDetails androidPlatformChannelSpecifics =
      AndroidNotificationDetails(
          'Adhan Times Notification', 'Islamic App', 'Allah O Akbar',
          priority: Priority.high,
          sound: RawResourceAndroidNotificationSound('azan'));
  const IOSNotificationDetails iOSPlatformChannelSpecifics =
      IOSNotificationDetails(sound: 'azan.aiff');

azaan.aiff文件位於app/ios/Runner中。

任何幫助,將不勝感激。 謝謝

除了IOSNotificationDetails構造函數的sound屬性外, playsound屬性必須設置為 true。

您可以在主屏幕的 init 方法中調用以下方法

 void _requestPermissions() {
flutterLocalNotificationsPlugin
    .resolvePlatformSpecificImplementation<
        IOSFlutterLocalNotificationsPlugin>()
    ?.requestPermissions(
      alert: true,
      badge: true,
      sound: true,
    );
flutterLocalNotificationsPlugin
    .resolvePlatformSpecificImplementation<
        MacOSFlutterLocalNotificationsPlugin>()
    ?.requestPermissions(
      alert: true,
      badge: true,
      sound: true,
    );
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM