#firebase #react-native #push-notification #firebase-cloud-messaging #apple-push-notifications
# #firebase #реагировать-встроенное #push-уведомление #firebase-облако-обмен сообщениями #apple-push-уведомления
Вопрос:
я пытаюсь использовать push-уведомление firebase на Android и IOS, оно работает на Android, но IOS не работает, я пытаюсь протестировать сообщение в облаке на IOS, оно сработало. но когда я пытаюсь использовать облачные сообщения для приложения appstore, это не работает, что мне делать?
это моя версия RN и lib
Версия Xcode Версия 12.1 (12A7403) «react-native»: «^ 0.63.2», «react-native-push-уведомление»: «^ 6.1.2», «@react-native-сообщество / push-уведомление-ios»: «^ 1.7.1»,
Сертификаты добавляют службу apple push
Идентификаторы push-уведомления — добавление службы push
Службы с поддержкой ключей добавляют профили, возможности с поддержкой — добавление push-уведомлений
это мой исходный код Xcode AppDelegate.m
#import "AppDelegate.h"
#import <Firebase.h>
#import <CodePush/CodePush.h>
#import <AppCenterReactNative.h>
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <GoogleMaps/GoogleMaps.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#ifdef FB_SONARKIT_ENABLED
#import <UserNotifications/UserNotifications.h>
#import <RNCPushNotificationIOS.h>
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
#import <KakaoOpenSDK/KakaoOpenSDK.h>
#import <FirebaseCore/FirebaseCore.h>.
static void InitializeFlipper(UIApplication *application) {
FlipperClient *client = [FlipperClient sharedClient];
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
[client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
[client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
[client addPlugin:[FlipperKitReactPlugin new]];
[client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
[client start];
}
#endif
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
// [AppCenterReactNative register];
// [AppCenterReactNativeAnalytics registerWithInitiallyEnabled:true];
// [AppCenterReactNativeCrashes registerWithAutomaticProcessing];
//codePush-IOS
{
if ([FIRApp defaultApp] == nil) {
[FIRApp configure];
}
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
// if ([FIRApp defaultApp] == nil) {
// [FIRApp configure];
//// [RNFirebaseNotifications configure];
// }
if ([UNUserNotificationCenter class] != nil) {
// iOS 10 or later
// For iOS 10 display notification (sent via APNS)
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert |
UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
[[UNUserNotificationCenter currentNotificationCenter]
requestAuthorizationWithOptions:authOptions
completionHandler:^(BOOL granted, NSError * _Nullable error) {
// ...
}];
} else {
// iOS 10 notifications aren't available; fall back to iOS 8-9 notifications.
UIUserNotificationType allNotificationTypes =
(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings =
[UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
[application registerUserNotificationSettings:settings];
}
[application registerForRemoteNotifications];
[FIRMessaging messaging].delegate = self;
[[FIRMessaging messaging] tokenWithCompletion:^(NSString *token, NSError *error) {
if (error != nil) {
NSLog(@"Error getting FCM registration token: %@", error);
} else {
NSLog(@"FCM registration token: %@", token);
self.fcmRegTokenMessage.text = token;
}
}];
#if DEBUG
#endif
[GMSServices provideAPIKey:@"AIzaSyBJao2sARSCYwF74BCqwRf3hexsP8Pkzj0"]; // add this line using the api key obtained from Google Console
#ifdef FB_SONARKIT_ENABLED
InitializeFlipper(application);
#endif
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"sikju_remaster"
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];
//notification
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
return YES;
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:
(void (^)(UNNotificationPresentationOptions options))
completionHandler {
completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionAlert);
}
#if DEBUG
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
[RNCPushNotificationIOS didRegisterUserNotificationSettings:notificationSettings];
}
// Required for the register event.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[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
{
[RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
// Required for the registrationError event.
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
[RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error];
}
// Required for the localNotification event.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
[RNCPushNotificationIOS didReceiveLocalNotification:notification];
}
// Required for localNotification event
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler
{
[RNCPushNotificationIOS didReceiveNotificationResponse:response];
}
// [START refresh_token]
- (void)messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken {
NSLog(@"FCM registration token: %@", fcmToken);
// Notify about received token.
NSDictionary *dataDict = [NSDictionary dictionaryWithObject:fcmToken forKey:@"token"];
[[NSNotificationCenter defaultCenter] postNotificationName:
@"FCMToken" object:nil userInfo:dataDict];
// TODO: If necessary send token to application server.
// Note: This callback is fired at each app startup and whenever a new token is generated.
}
// [END refresh_token]
//- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
// if ([KOSession isKakaoAccountLoginCallback:url]) {
// return [KOSession handleOpenURL:url];
// }
// [KOSession sharedSession].automaticPeriodicRefresh = YES;
// return false;
//}
//- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
// if ([KOSession isKakaoAccountLoginCallback:url]) {
// return [KOSession handleOpenURL:url];
// }
// [KOSession handleDidEnterBackground];
// return false;
//}
//
//- (void)applicationDidBecomeActive:(UIApplication *)application {
// [KOSession handleDidBecomeActive];
//}
#endif
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
// return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; //
return [CodePush bundleURL];
#endif
}
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
return [[FBSDKApplicationDelegate sharedInstance]application:app
openURL:url
options:options];
}
//facebook login
@end
Комментарии:
1. Включены ли Push-уведомления в профиле рассылки, с помощью которого вы отправили приложение в appstore. если нет, то это может быть проблемой
2. @Saikiran я проверяю это и пытаюсь автоматически управлять отключенной подписью
3. как попробовать Push-уведомление? если попробовать это с вашей панели firebase, в некоторых случаях вы, возможно, устанавливаете udid целевого устройства для получения уведомлений.
4. @MeisamSaba Тестовое сообщение на firebase, в котором говорилось, что используется токен FCM