【发布时间】:2021-01-21 03:59:35
【问题描述】:
我在尝试在 iOS 上显示 onMessage 通知时遇到问题,Android 工作正常。我发送通知并且 onMessage 被触发但没有在 Android 设备上显示 Flushbar。奇怪的是,它在控制台中打印了 onMessage,但没有在 App 上显示 Flushbar。
@override
void initState() {
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print("onMessage: $message");
int idEvent = int.parse(message['data']['idevent']);
String image = message['data']['image'];
Flushbar(
title: message['notification']['title'],
message: message['notification']['body'],
duration: Duration(seconds: 5),
flushbarPosition: FlushbarPosition.TOP,
flushbarStyle: FlushbarStyle.GROUNDED,
onTap: (Flushbar fb) async {
fb.dismiss();
ServiceEvent.fetchEvent(idEvent).then((event) {
if (event != null) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => EventDetailsPage(
event,
fromNotification: true,
),
),
);
} else {
DialogUtility.dialogInfo(
context, "There was an error didn't find event");
}
}).catchError((error) {
DialogUtility.dialogInfo(context, error.toString());
});
},
icon: image != null
? Padding(
padding: const EdgeInsets.symmetric(horizontal: 5.0),
child: Image.network('$image', height: 40, width: 40,),
)
: Padding(
padding: const EdgeInsets.symmetric(horizontal: 5),
child: SvgPicture.asset(
'assets/icons/tarjeta-rocket-entries.svg',
semanticsLabel: 'Acme Logo',
width: 40,
height: 40,
),
),
)..show(buildContext);
},
onLaunch: (Map<String, dynamic> message) async {
print("onLaunch: $message");
},
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
},
);
_firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(
sound: true, badge: true, alert: true, provisional: true));
_firebaseMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings) {
print("Settings registered: $settings");
});
_firebaseMessaging.getToken().then((String token) {
assert(token != null);
setState(() {
//_homeScreenText = "Push Messaging token: $token";
});
//print('token: '+token);
});
super.initState();
}
【问题讨论】:
标签: firebase flutter firebase-cloud-messaging