【发布时间】:2021-03-11 01:22:58
【问题描述】:
应用在android上运行正常(推送通知,设备开始响铃),但在IOS上,应用收到通知但再次打开应用后铃声响起...
我也设置了功能、后台模式(音频后台获取、远程通知和后台处理)和推送通知
我正在尝试在 onMessage 方法中播放自定义声音...
Firebase 监听器
void firebaseCloudMessagingListeners(BuildContext context) {
final deliveryCubit = BlocProvider.of<DeliveryCubit>(context);
final playerService = PlayerService();
if (Platform.isIOS) getIOSPermission();
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
debugPrint('FMC -> $message');
if(appInBackground){
playerService.playRingtone();
}
},
onResume: (Map<String, dynamic> message) async {
debugPrint('on resume $message');
},
onLaunch: (Map<String, dynamic> message) async {
debugPrint('on launch $message');
},
);
}
播放器服务
import 'package:assets_audio_player/assets_audio_player.dart';
import 'package:path_provider/path_provider.dart' as path_provider;
class PlayerService {
static PlayerService _instance;
final assetsAudioPlayer = AssetsAudioPlayer();
factory PlayerService() => _instance ?? PlayerService._internal();
PlayerService._internal(){
_instance = this;
}
void playRingtone(){
assetsAudioPlayer.open(
Audio("assets/audios/iosRingtone.mp3"),
showNotification: false,
);
assetsAudioPlayer.play();
}
void pauseRingtone(){
assetsAudioPlayer.pause();
}
}
我尝试在 lifeCycleStateChange 上停止播放器...
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
switch(state){
case AppLifecycleState.resumed:
socketService.appInBackground = false;
firebaseService.appInBackground = false;
playerService.pauseRingtone();
setState(() {
appLifecycleState = AppLifecycleState.resumed;
});
print("LifecycleState resumed");
break;
case AppLifecycleState.inactive:
print("LifecycleState inactive");
socketService.appInBackground = true;
firebaseService.appInBackground = true;
setState(() {
appLifecycleState = AppLifecycleState.inactive;
});
break;
case AppLifecycleState.paused:
socketService.appInBackground = true;
firebaseService.appInBackground = true;
print("LifecycleState paused");
break;
case AppLifecycleState.detached:
print("LifecycleState detached");
break;
}
}
【问题讨论】:
-
应用推送通知负载是否包含自定义警报声音设置?
-
不,没有为推送通知负载配置警报声音设置...
标签: android ios firebase flutter dart