this is my flutter code:
Future<void> permi() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
var username = prefs.getString("username");
_fcm.getToken().then((value) => prefs.setString("fireToken", "$value!"));
print(_fcm.getToken());
var fireToken = prefs.getString("fireToken");
var token = prefs.getString("token");
await http
.post(Uri.parse("http://192.168.0.111:3000/notiftoken"),
headers:{"Content-Type": "application/json",
"authorization": "$token"},
body: jsonEncode({"username": username,"token": fireToken}),
)
.then((value) => value)
.catchError((e) => print(e));
}
Future checkprm()async{
NotificationSettings settings =
await _fcm.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
NotificationSettings set = await _fcm.getNotificationSettings();
if (settings.authorizationStatus == AuthorizationStatus.authorized) {
print('User granted permission');
} else if (settings.authorizationStatus == AuthorizationStatus.provisional) {
print('User granted provisional permission');
} else {
print('User declined or has not accepted permission');
}
}
@override
void initState(){
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
_fcm.getToken().then((value) => print("$value"));
checkprm();
permi();
connect();
super.initState();
WidgetsBinding.instance.addObserver(this);
}
this my node server :
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
async function sendNotif( title, body0,token){
return await admin.messaging().sendMulticast({
tokens: [token],
notification: {
title: title,
body: body0
},
data: {
title: "This is a firebase message",
message: "expo-notifications should be triggered",
"hello": "world",
click_action: "FLUTTER_NOTIFICATION_CLICK"
},
// Set Android priority to "high"
android: {
priority: "high",
},
// Add APNS (Apple) config
apns: {
payload: {
aps: {
"contentAvailable": true,
},
},
headers: {
"apns-push-type": "background",
"apns-priority": "5", // Must be `5` when `contentAvailable` is set to true.
"apns-topic": "io.flutter.plugins.firebase.messaging", // bundle identifier
},
}
});
}
i've been searching for a solution for about two weeks but it's all for nothing.
the issue is that i don't receive notifications coming from firebase.
if anyone found a solution please tell us. .
.
.