Not able to Receive Message on IOS App #7199
Unanswered
freelancer-top
asked this question in
Q&A
Replies: 1 comment 5 replies
-
Hi there. Without the notification JSON that you send via the firebase-admin SDK using the FCM APIs as a test, I cannot say why the FCM is not coming through. There are many related issues in the repository that you may search for that have related issues. My hunch is that you are trying to send a data-only / background notification, which are both difficult to do correctly at all (they require specific entitlements etc) and are specifically not guaranteed to deliver reliably. iOS will frequently just drop them, even if you do everything right. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have followed documentation. I am able to get device token. Using that device token able to send message via Firebase . API Response says success but message on IOS device is not there . I suspect something wrong with my appdeleage.mm . Can you please suggest what is missing ?
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <Firebase.h>
#import <FirebaseMessaging/FirebaseMessaging.h>
@interface AppDelegate () <UIApplicationDelegate, FIRMessagingDelegate, UNUserNotificationCenterDelegate>
@EnD
@implementation AppDelegate
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Configure Firebase
[FIRApp configure];
// Add Firebase messaging delegate
[FIRMessaging messaging].delegate = self;
// Register for push notifications
[RCTPushNotificationManager.sharedInstance registerForRemoteNotifications];
self.moduleName = @"SchoolconnectForParent";
self.initialProps = @{};
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
(void)messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken {
// TODO: Handle the received FCM token
NSLog(@"Received FCM token: %@", fcmToken);
// You can send this token to your server or use it for sending push notifications
}
(NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[NSURL alloc] initWithString:@"http://localhost:8081/index.bundle?platform=ios"];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}
(BOOL)concurrentRootEnabled
{
return true;
}
// UserNotifications delegate methods
(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
{
// Handle the notification response here
completionHandler();
}
(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
// Handle the remote notification here
completionHandler(UIBackgroundFetchResultNewData);
}
(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
// Forward the device token to Firebase Messaging
[[FIRMessaging messaging] setAPNSToken:deviceToken type:FIRMessagingAPNSTokenTypeProd];
}
(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"Failed to register for remote notifications: %@", error);
}
@EnD
My React native version :0.71.7
"@react-native-firebase/app": "^18.0.0",
"@react-native-firebase/messaging": "^18.0.0",
Here is my code to ensure Permission and token is there : ""Permisssion Granted" is shown on screen
export const requestUserPermission = async () => {
const authStatus = await messaging().requestPermission();
if (authStatus === messaging.AuthorizationStatus.AUTHORIZED) {
Alert.alert("Permisssion Granted");
console.log('**** Permission granted **** ');
} else if (authStatus === messaging.AuthorizationStatus.DENIED) {
Alert.alert("Permisssion Denied");
}
};
if (messaging().isDeviceRegisteredForRemoteMessages == false )
{
// Register the device with FCM
await messaging().registerDeviceForRemoteMessages();
}
// Get the token
const token = await messaging().getToken();
async function onMessageReceived(message: any) {
Alert.alert("Yes Message Received");
setUserMessage("Yes Received ");
Alert.alert(message);
}
Beta Was this translation helpful? Give feedback.
All reactions