ios无法在react native firebase中接收通知

stszievb  于 2021-09-23  发布在  Java
关注(0)|答案(0)|浏览(197)

我正在使用 react-native-firebase 与其他一些库一起显示来自firebase的通知。下面是我的 package.json 看起来像。

"dependencies": {
    ...
    "react-native-push-notification": "^7.2.3",
    "@react-native-community/push-notification-ios": "^1.8.0",
    "@react-native-firebase/app": "^11.4.1",
    "@react-native-firebase/messaging": "^11.4.1",
    ...
}

出于某些原因,我的应用程序在ios设备上根本不会收到通知。即使是通过设备令牌发送的firebase控制台的测试通知也不起作用。所以我建议我的问题不在 react-native 代码。顺便说一下,通知在安卓系统上也应该如此。
在我的xcode“签名和功能”选项卡中,推送通知被启用,后台获取和远程通知后台模式也被启用。
这是我的 AppDelegate.m ```

import "AppDelegate.h"

import <React/RCTBridge.h>

import <React/RCTBundleURLProvider.h>

import <React/RCTRootView.h>

import <Firebase.h>

import <UserNotifications/UserNotifications.h>

import <RNCPushNotificationIOS.h>

import <AppCenterReactNative.h>

import <AppCenterReactNativeAnalytics.h>

import <AppCenterReactNativeCrashes.h>

import <UIKit/UIKit.h>

import <TSBackgroundFetch/TSBackgroundFetch.h>

@implementation AppDelegate

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    if ([FIRApp defaultApp] == nil) {
    [FIRApp configure];
    }
    [AppCenterReactNative register];
    [AppCenterReactNativeAnalytics registerWithInitiallyEnabled:true];
    [AppCenterReactNativeCrashes registerWithAutomaticProcessing];
    [[TSBackgroundFetch sharedInstance] didFinishLaunching];

    RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
    RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
    moduleName:@"ModuleName"
    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];

    // Define UNUserNotificationCenter
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = self;

    return YES;
    }

  • (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
    {

if DEBUG

return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];

else

return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

endif

}

// 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 localNotification event
  • (void)userNotificationCenter:(UNUserNotificationCenter *)center
    didReceiveNotificationResponse:(UNNotificationResponse *)response
    withCompletionHandler:(void (^)(void))completionHandler
    {
    [RNCPushNotificationIOS didReceiveNotificationResponse:response];
    }

//Called when a notification is delivered to a foreground app.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification withCompletionHandler:(void
(^)(UNNotificationPresentationOptions options))completionHandler
{
completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge);
}

@end

还有我的 `info.plist` ```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>BGTaskSchedulerPermittedIdentifiers</key>
    <array>
        <string>com.transistorsoft.fetch</string>
    </array>
    <key>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundleDisplayName</key>
    <string>App name</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>app.bundle.identifier</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>app.bundle.name</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.2.0</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>$(CURRENT_PROJECT_VERSION)</string>
    <key>ITSAppUsesNonExemptEncryption</key>
    <false/>
    <key>LSApplicationCategoryType</key>
    <string></string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>MinimumOSVersion</key>
    <string>9.0</string>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>localhost</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
        </dict>
    </dict>
    <key>NSAppleMusicUsageDescription</key>
    <string>Allow the app access music.</string>
    <key>NSCameraUsageDescription</key>
    <string>This app requires access to the camera. You can make photos to attach to reports or to update your avatar.</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>This app requires access to the user’s location information to search nearby units and buidings.</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>This app requires access to the user’s location information to search nearby units and buidings.</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>This app requires access to the photo library. You can select photos to attach to reports or to update your avatar.</string>
    <key>UIAppFonts</key>
    <array>
        <string>Montserrat-Bold.ttf</string>
        <string>Montserrat-Light.ttf</string>
        <string>Montserrat-Regular.ttf</string>
        <string>SFProDisplay-Bold.otf</string>
        <string>SFProDisplay-Light.otf</string>
        <string>SFProDisplay-Medium.otf</string>
        <string>SFProDisplay-Regular.otf</string>
        <string>SFProDisplay-Semibold.otf</string>
        <string>SFProDisplay-Thin.otf</string>
        <string>SFProText -Regular.otf</string>
        <string>SFProText-Bold.otf</string>
        <string>SFProText-Light.otf</string>
        <string>SFProText-Medium.otf</string>
        <string>SFProText-Semibold.otf</string>
        <string>SFProText-Thin.otf</string>
        <string>AntDesign.ttf</string>
        <string>Entypo.ttf</string>
        <string>EvilIcons.ttf</string>
        <string>Feather.ttf</string>
        <string>FontAwesome.ttf</string>
        <string>FontAwesome5_Brands.ttf</string>
        <string>FontAwesome5_Regular.ttf</string>
        <string>FontAwesome5_Solid.ttf</string>
        <string>Foundation.ttf</string>
        <string>Ionicons.ttf</string>
        <string>MaterialIcons.ttf</string>
        <string>MaterialCommunityIcons.ttf</string>
        <string>SimpleLineIcons.ttf</string>
        <string>Octicons.ttf</string>
        <string>Zocial.ttf</string>
        <string>Fontisto.ttf</string>
    </array>
    <key>UIBackgroundModes</key>
    <array>
        <string>fetch</string>
        <string>processing</string>
        <string>remote-notification</string>
    </array>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIRequiredDeviceCapabilities</key>
    <array>
        <string>armv7</string>
    </array>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>
</dict>
</plist>

为什么会发生这种情况?
p、 将捆绑标识、应用标识或模块名称替换为占位符

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题