Reputation: 711
I have only been working on Android push notification, Now I want to work on IOS , I have all the required fields like developer account etc covered. I can in fact receive a push notification but as I click on it i want a dialogue box to open retrieveRideRequestInfo
.The code below works fine with Android. However with IOS nothing happens as I am unsure what else is needed because the documentation is too complicated for me.
class PushNotificationService {
FirebaseMessaging firebasemessaging = FirebaseMessaging.instance;
Future initialize(context) async {
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
RemoteNotification? notification = message
.notification;
AndroidNotification? android = message.notification?.android;
if (notification != null && android != null) {
retrieveRideRequestInfo(getRideRequestId(message.data)!, context);
flutterLocalNotificationsPlugin.show(
notification.hashCode,
notification.title,
notification.body,
NotificationDetails(
iOS: IOSNotificationDetails(),
android:
AndroidNotificationDetails(channel.id, channel.name,
channelDescription: channel.description,
color: Colors.blue,
playSound: false,
icon: '@mipmap/ic_launcher'),
),
);
print('AndroidNotification after clicking ' + notification.title!);
print('AndroidNotification after clicking ' + notification.body!);
print("This is message map");
}
});
//on message open
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
// same as above
RemoteNotification? notification = message
.notification; //assign two variables for remotenotification and android notification
AndroidNotification? android = message.notification?.android;
if (notification != null && android != null) {
// if (doublenotification.isOdd)
retrieveRideRequestInfo(getRideRequestId(message.data)!, context);
print('AndroidNotification after clicking ' + notification.title!);
print('AndroidNotification after clicking ' + notification.body!);
//getRideRequestId();
}
//}
});
}
The docs specify if (notification != null && android != null) {}
which is only taking care of android, How can I handle Ios notifications then ?
Upvotes: 0
Views: 453
Reputation: 1557
You only added condition for android
platform. you need also add for iOS platform. also make sure both
// onMessage: When the app is open and it receives a push notification
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
RemoteNotification? notification = message.notification;
if (notification != null) {
if (notification.android != null) {
//---- Android notification open app handle here ----
print("${notification.data}");
} else {
//---- iOS notification open app handle here ----
print("${notification.data}");
}
}
});
Also check
notification.data
before map into your widget because its slightly different. from from Android.
Checkout this link for firebase config.
Upvotes: 1