I have been debugging this for a long time. I'm on the verge of abandoning FCM all together. If anyone has insight on this, please help.
Cannot get remote notification to show up on phone, no matter whether app is in background or foreground. Tried sending notification both from firebase console and using firebase admin. Same result. Nada.
Push notification capacities are enabled, including background mode.
Tried using both APNS auth key and APNS certificates in app configuration for firebase. Didn't work. When sending notification from firebase console, status is always 'completed'. When sending using firebase admin from my server, always getting 200 success in return. So I'm fairly certain this is not an authentication issue.
Tried making a curl call directly through APNS using my phone's device token
curl --http2 --cert ./push-cert.pem -H "apns-topic: [bundle id]" -d '{"aps":{"alert":"Hello from APNs!","sound":"default"}}' https://api.development.push.apple.com/3/device/[device token].
I'm getting the notification with no problem. So this is not an issue with device's connection to APNs.
Here's my js code:
class SomeComponent extends Component {
constructor (props) {
super(props);
this.state = {
token: '',
};
... ...
}
componentDidMount() {
FCM.requestPermissions();
FCM.getFCMToken().then(token => {
console.log('FCM device registration token: ', token);
this.setState({
token,
});
// store fcm token in database
this.props.user.soundcasts && storeDeviceToken(token, this.props.user.soundcasts);
});
this.notificationListener = FCM.on(FCMEvent.Notification, notif => {
console.log('notification received==> ', notif);
if(notif.local_notification){
return;
}
if(notif.opened_from_tray){
return;
}
if(Platform.OS ==='ios'){
switch(notif._notificationType){
case NotificationType.Remote:
notif.finish(RemoteNotificationResult.NewData) //other types available: RemoteNotificationResult.NewData, RemoteNotificationResult.ResultFailed
break;
case NotificationType.NotificationResponse:
notif.finish();
break;
case NotificationType.WillPresent:
notif.finish(WillPresentNotificationResult.All) //other types available: WillPresentNotificationResult.None
break;
}
}
});
this.refreshTokenListener = FCM.on(FCMEvent.RefreshToken, (token) => {
console.log('fcm token refreshed to: ', token);
this.props.user.soundcasts && storeDeviceToken(token, this.props.user.soundcasts);
});
}
... ...
}
FCM.requestPermissions() and FCM.getFCMToken() are working. But the notification event listener does not show any signs of life.
Here's my AppDelegate.m:
#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import "RNFIRMessaging.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"SoundwiseCMS_mobile"
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];
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
[FIRApp configure];
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
return YES;
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]
];
return handled;
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
[RNFIRMessaging willPresentNotification:notification withCompletionHandler:completionHandler];
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler
{
[RNFIRMessaging didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[RNFIRMessaging didReceiveLocalNotification:notification];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
[RNFIRMessaging didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
// print device token for Push Notification
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings // NS_AVAILABLE_IOS(8_0);
{
[application registerForRemoteNotifications];
}
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken{
NSLog(@"deviceToken: %@", deviceToken);
NSString * token = [NSString stringWithFormat:@"%@", deviceToken];
//Format token:
token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
token = [token stringByReplacingOccurrencesOfString:@">" withString:@""];
token = [token stringByReplacingOccurrencesOfString:@"<" withString:@""];
}
@end
"react": "16.0.0-alpha.12"
"react-native": "0.46.4"
"react-native-fcm": "^9.1.0"
testing on iOS 10.3.3
Added
<key>FirebaseAppDelegateProxyEnabled</key>
<true/>
to info.plist. Now it's working.
Hello, i have same problem like you, i had try add
to
Most helpful comment
Added
to
info.plist. Now it's working.