I just got a request: Can you download sound file from remote server and make it a notification sound?
Here is my code (for ios)
//package i used
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:dio/dio.dart';
import 'package:path/path.dart' as pathService;
import 'package:path_provider/path_provider.dart';
//Download file we needed
final iosLibraryDir = await getApplicationLibrary();
final soundFilename = 'notification1.wav';
final downloadPath = pathService.join(iosLibraryDir.path, 'Sounds', soundFilename);
Dio dio = Dio();
await dio.download(remoteURL, downloadPath);
//set up notification
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
await flutterLocalNotificationsPlugin.initialize(
InitializationSettings(
iOS: IOSInitializationSettings(requestSoundPermission: true)
);
await flutterLocalNotificationsPlugin.show(
1,
'Test Title',
'Test Body',
NotificationDetails(
iOS: IOSNotificationDetails(
presentSound: true,
sound: soundFilename
)
)
);
Notification shown but no sound played I also try path like '/Library/Sounds/notification1.wav' and full path report from getApplicationLibrary(), but none of them worked.
Is this caused by ios cannot found the path or Apple's security policy not allowed it?