Hi all!
I do need help fixing the push notification issue.
Currently, I've a home page that comes after the Signup/login page, and on page load I have a function as below to generate a fcm token. first, it doesn't generate FCM token, it says permission is denied when I'm in test mode in the browser, only generates FCM token when I'm have installed the app in a test flight for a phone (right now dealing only with IOS).
now the issue is: when a user creates a message, then another user gets a notification, but if the other user sends a message, the main person who initiated the chat doesn't get a notification.
below is the function I made to generate fcm token.
anyone has deal with such a thing or know how to fix it? I appreciate any help
// Automatic FlutterFlow imports import '/backend/backend.dart'; import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_util.dart'; import '/custom_code/actions/index.dart'; // Imports other custom actions import '/flutter_flow/custom_functions.dart'; // Imports custom functions import 'package:flutter/material.dart'; // Begin custom action code // DO NOT REMOVE OR MODIFY THE CODE ABOVE! import 'package:firebase_messaging/firebase_messaging.dart'; // Import Firebase Messaging import 'dart:io' show Platform; // Import platform detection // Custom Action: Fetch FCM Token Future<String?> getFCMToken() async { try { // Check if the platform is iOS or Android if (Platform.isIOS || Platform.isAndroid) { // Request notification permission (iOS/Android) NotificationSettings settings = await FirebaseMessaging.instance.requestPermission( alert: true, badge: true, sound: true, ); // If permission is granted, fetch the FCM Token if (settings.authorizationStatus == AuthorizationStatus.authorized) { String? token = await FirebaseMessaging.instance.getToken(); return token ?? 'no-token'; // Return token or fallback if null } else { return 'permission-denied'; // Handle permission denial } } // Handle FCM token generation for Web (macOS Browser or other platforms) else { // Web platforms require a VAPID key to retrieve FCM token String? token = await FirebaseMessaging.instance.getToken( vapidKey: 'BKNg81iS1Bp4Os193RlYo-Ei83MFjforf0_AGMimnk-ENYg2J0OthXZPFEZOI6KcwWj33L2Qr7AwnyVpQAntIU4', // Replace with your VAPID key ); return token ?? 'no-token'; // Return token or fallback } } catch (e) { return 'error-fetching-token'; // Return error if something goes wrong } } // End custom action code // DO NOT REMOVE OR MODIFY THE CODE BELOW!