【问题标题】:Not receiving notifications react-native-push-notification on iOS在 iOS 上没有收到通知 react-native-push-notification
【发布时间】:2018-12-29 00:59:49
【问题描述】:

我按照文档以及 youtube 上的一些教程将 react-native-push-notification 与 ios 和 android 集成,但我有一个问题,我在 iOS 设备上没有收到任何通知,甚至是本地通知,但是在Android上,它运行良好。我不知道我是否需要给你看代码,因为和文档中的一样。

顺便说一句,我正在使用 firebase 进行云消息传递,并使用我的 p8 密钥对其进行了配置。

【问题讨论】:

  • 请分享发送通知的代码

标签: android ios react-native push-notification react-native-push-notification


【解决方案1】:

您没有收到通知可能是因为 firebase 未正确集成到您的应用程序中。正确集成的步骤如下:

react-native-firebase 库对我不起作用。使用 react-native-fcm 集成 firebase 以响应本机应用程序成功接收推送通知。

1.安装 react-native-fcm: npm install react-native-fcm --save

  1. 从 Firebase 控制台, 对于 Android:下载 google-services.json 文件并将其放在 android/app 目录中。 对于 iOS:下载 GoogleService-Info.plist 文件并将其放在 /ios/your-project-name 目录中(Info.plist 旁边)

3.配置项目使用: cd ios && pod init

4.编辑新创建的 Podfile: 吊舱安装

5.编辑AppDelegate.h:

    @import UserNotifications;

    @interface AppDelegate:UIResponder<UIApplicationDelegate,UNUserNotificationCenterDelegate>

    @interface AppDelegate : UIResponder <UIApplicationDelegate>

6.编辑AppDelegate.m:

#import "RNFIRMessaging.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

[FIRApp configure];
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];

return YES;

}

-(void)userNotificationCenter:(UNUserNotificationCenter *)center 
willPresentNotification:(UNNotification *)notification 
withCompletionHandler:(void (^) . 
      (UNNotificationPresentationOptions))completionHandler
 {
    [RNFIRMessaging willPresentNotification:notification 
     withCompletionHandler:completionHandler];
 }

#if defined(__IPHONE_11_0)

- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
  didReceiveNotificationResponse:(UNNotificationResponse *)response 
   withCompletionHandler:(void (^)(void))completionHandler
{
    [RNFIRMessaging didReceiveNotificationResponse:response 
     withCompletionHandler:completionHandler];
}

#else

- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
  didReceiveNotificationResponse:(UNNotificationResponse *)response 
  withCompletionHandler:(void(^)())completionHandler
{
    [RNFIRMessaging didReceiveNotificationResponse:response 
    withCompletionHandler:completionHandler];
 }

#endif

 //You can skip this method if you don't want to use local notification
-(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];
}

7.XCode中添加头文件路径:

打开 XCode。 按 CMD+1 或单击 XCode 项目。 转到构建设置,选择全部和组合。 在 searchg 选项卡中搜索标题搜索路径。 确保有一行 $(SRCROOT)/../node_modules/react-native-fcm/ios。如果没有,请添加它。

8.添加GoogleService-Info.plist:

确保文件不只是移动到文件夹中。您需要右键单击 XCode 中的项目文件夹并将文件添加到 .选择文件时,在选项页面中根据需要选择复制。

9.共享库设置:

如果您使用 Pod 安装方法,请确保您在 Library 文件夹下看到 Pods.xcodeproj。 确保您在 Library 文件夹下看到 RNFIRMessaging.xcodeproj。 如果您没有看到任何这些文件,请通过右键单击库文件夹并添加文件来添加它们以将它们添加回来。 Pods.xcodeproj 应该在 ios/Pods/ 下,RNFIRMessaging.xcodeproj 应该在 node_modules/react-native-fcm/ios 下。 确保在 Build Phases 选项卡下的 Link Binary With Libraries 下看到 libRNFIRMessaging.a。如果没有,请将Library文件夹下的RNFIRMessaging.xcodeproj下的文件拖到那里。

10.添加功能 选择您的项目功能并启用: 推送通知 后台模式 > 远程通知。

FirebaseAppDelegateProxyEnabled 此说明假定您有 FirebaseAppDelegateProxyEnabled=YES(默认),以便 Firebase 将挂钩推送通知注册事件。如果您关闭此标志,您将自行管理 APNS 令牌并与 Firebase 令牌链接。

【讨论】:

    【解决方案2】:

    我也尝试过 react-native-firebase 但它不起作用。没有收到推送通知。后来我使用 react-native-fcm 实现了推送通知并且它起作用了。可以查看链接https://github.com/evollu/react-native-fcm

    【讨论】:

      【解决方案3】:

      即使打开了所有相关设置,我也遇到了类似的问题。令人沮丧 - 我使用了管理通知的 Google Play 商店的“hi security”。将“通知”设置为开启后,我发现所有的徽章都出现了——主屏幕和应用程序上的未接来电和未读消息。

      【讨论】:

        猜你喜欢
        • 2021-07-04
        • 2020-07-09
        • 1970-01-01
        • 2019-05-16
        • 2018-09-12
        • 2019-02-06
        • 2021-11-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多