ios notification not received but sent from api successfully.
See original GitHub issueHi,
Following are the versions:
react: 16.0.0-alpha.6, react-native: 0.44.0, react-native-fcm: ^7.2.0,
I have tested on iphone 6 ios 10.3.2
Following is the code in appdelegate.m:
#import "RNFIRMessaging.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FIRApp configure];
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
NSURL *jsCodeLocation;
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"high_furtados_appv2"
initialProperties:nil
launchOptions:launchOptions];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
NSLog(@"willPresentNotification %@",notification);
[RNFIRMessaging willPresentNotification:notification withCompletionHandler:completionHandler];
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler
{
NSLog(@"didReceiveNotificationResponse %@",response);
[RNFIRMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
NSLog(@"didReceiveRemoteNotification %@",userInfo);
[RNFIRMessaging didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
//You can skip this method if you don't want to use local notification
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[RNFIRMessaging didReceiveLocalNotification:notification];
}
Following is the code in react-native project:
FCM.requestPermissions();
FCM.subscribeToTopic('all');
FCM.getFCMToken().then(token => {
console.log('getFCMToken :::: ', token);
// store fcm token in your server
if (token) {
global.pushToken = token
}
console.log('getFCMToken global.pushToken ::: ', global.pushToken);
});
this.notificationListener = FCM.on(FCMEvent.Notification, async (notif) => {
console.log('notificationListener notif ::: ', notif);
let notificationIos = typeof notif == 'string' ? JSON.parse(notif) : notif;
let notificationIosBody = {};
try {
notificationIosBody = notificationIos.notification.body;
} catch (e) {
try {
notificationIosBody = notificationIos.aps.alert.body;
} catch (e) {
console.log("Format Error!");
}
}
// there are two parts of notif. notif.notification contains the notification payload, notif.data contains data payload
if (notif.local_notification) {
//this is a local notification
}
if (notif.opened_from_tray) {
//app is open/resumed because user clicked banner
console.log('notificationListener notif.opened_from_tray ::: ', notif);
if (Platform.OS === 'ios') {
if (notificationIosBody) {
Alert.alert('Notification', notificationIosBody,
[
{ text: 'OK', onPress: () => { } },
]);
}
}
}
if (Platform.OS === 'ios') {
if (notificationIosBody) {
Alert.alert('Notification', notificationIosBody,
[
{ text: 'OK', onPress: () => { } },
]);
}
}
else if (Platform.OS === 'android') {
if (notif.fcm.body) {
Alert.alert('Notification', notif.fcm.body,
[
{ text: 'OK', onPress: () => { } },
]);
}
}
});
this.refreshTokenListener = FCM.on(FCMEvent.RefreshToken, (token) => {
console.log('refreshTokenListener ::: ', token);
// fcm token may not be available on first load, catch it here
if (token) {
global.pushToken = token
}
console.log('refreshTokenListener global.pushToken ::: ', global.pushToken);
});
I have added all the packages as mentioned in readme file for nonpod configuration.
I am not getting any logs which are added in appdelegate.m file.
The notifications are not getting received in ios only when app is open and also when app is closed or in background.
I have also added following in info.plist:
<key>FirebaseAppDelegateProxyEnabled</key>
<false/>
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:86 (27 by maintainers)
Top Results From Across the Web
Push notification is not arriving … | Apple Developer Forums
The APNS server responds with 200/OK, but no notification will ever arrive at my device. I definitely assume my request is correct; if...
Read more >iOS Notifications are not receiving that are sent from the server
First check all the validations or verifications like certificate, pem file and other things are updated on iOS and backend side.
Read more >Notifications Not Shown - Mobile Push
The following are reasons why notifications may show as "Delivered" on the OneSignal dashboard or API, but are not visible on your device....
Read more >Push notifications are not sending - Leanplum Documentation
If the token/id is missing, the push notification cannot be sent. To ensure that the token is added, check if the app has...
Read more >Send a test message to a backgrounded app | Firebase Cloud ...
To get started with FCM, build out the simplest use case: sending a test notification message from the Notifications composer to a development...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
+1 Having same issue
Relevant discussions: Apple Developer Forums thread:
Stackoverflow questions in the last 24hrs: