Open mertbuldur opened 4 years ago
hey did you find a solution?
I am unable to get token with getAPNSToken()
but with react-native-push-notification
I am able to get token and work for background and foreground. But I need to get the token without the need of react-native-push-notification
.
In android it works fine.
try {
let tries = 0;
let apnsToken = null;
while (tries < 5) {
const apnsToken = await messaging().getAPNSToken();
if (apnsToken !== null) return apnsToken;
await new Promise((resolve) => setTimeout(resolve, 1000));
tries++;
}
// await syncStorage.set('firebaseToken', apnsToken);
// report({firebaseToken: syncStorage.get('firebaseToken')}, 'firebaseToken IOS');
report(apnsToken, 'getAPNSToken()');
return apnsToken;
} catch (e) {
reportErrorInstabug(e, 'registerAppWithAPN()', 'ERROR');
return null;
}
}
hello I am trying to catch notifications when the application is closed or at the bottom. Notifications on the front work, but notifications on the back. I am trying to capture with setBackgroundMessageHandler, but I cannot receive a message in the log or console. I run it once but I don't remember the codes Please help me I have been dealing with it for 2 days.
AppDelegate.m `#import "AppDelegate.h"
import
import <UserNotifications/UserNotifications.h>
import <React/RCTBridge.h>
import <React/RCTBundleURLProvider.h>
import <React/RCTRootView.h>
// Firebase @import Firebase;
@implementation AppDelegate
(BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions {
ifdef FB_SONARKIT_ENABLED
InitializeFlipper(application);
endif
RCTBridge bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; RCTRootView rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"Psikolog" initialProperties:nil];
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];
// Push notification UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; [application registerForRemoteNotifications]; center.delegate = self;
[FIRApp configure];
return YES; }
// Push Nofitication // Required to register for notifications
(void)application:(UIApplication )application didRegisterUserNotificationSettings:(UIUserNotificationSettings )notificationSettings { [RNCPushNotificationIOS didRegisterUserNotificationSettings:notificationSettings]; } // Required for the register event.
(void)application:(UIApplication )application didRegisterForRemoteNotificationsWithDeviceToken:(NSData )deviceToken { NSLog(@"APP_PUSH from Device Token "); [RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } // Required for the notification event. You must call the completion handler after handling the remote notification.
(void)application:(UIApplication )application didReceiveRemoteNotification:(NSDictionary )userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { NSLog(@"APP_PUSH from Background "); [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; }
// Required for the registrationError event.
-(void)userNotificationCenter:(UNUserNotificationCenter )center willPresentNotification:(UNNotification )notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
NSLog(@"APP_PUSH from foreground %@ ",completionHandler); NSLog(@"APP_PUSH from foreground2 %@ ",completionHandler);
completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}
// Sistem
if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
endif
}
@end `
Package.json:
"@react-native-firebase/app": "6.7.1", "@react-native-firebase/messaging": "6.7.1", @react-native-community/push-notification-ios": "^1.2.0", "react-native-push-notification": "^3.1.9",
App.js ` messaging().setBackgroundMessageHandler( remoteMessage => { PushNotification.localNotification({ title: "xxxx", message: "testxxxting", // (required),PushNotification.configure({ // (optional) Called when Token is generated (iOS and Android)
});
`