首页 > 解决方案 > 方法“应用程序:didRegisterUserNotificationSettings:”的重复声明

问题描述

我正在使用 react native 处理“react-native-firebase”:“^5.5.6”和“react-native-push-notification”:“^3.1.9”,但我遇到了错误 Duplicate declaration of method appDelegate.m 上的“应用程序:didRegisterUserNotificationSettings:”

我尝试了通过网络找到的各种解决方案,如果我评论其中一种方法,我会收到错误“本机模块不能为空”

- (void)application:(UIApplication *)application 
didRegisterUserNotificationSettings:(UIUserNotificationSettings 
*)notificationSettings {

  [[RNFirebaseMessaging instance] 
 didRegisterUserNotificationSettings:notificationSettings];
}

// Required to register for notifications
- (void)application:(UIApplication *)application 
didRegisterUserNotificationSettings:(UIUserNotificationSettings 
*)notificationSettings
{
[RCTPushNotificationManager 
didRegisterUserNotificationSettings:notificationSettings];
}

我的代码中需要这两种方法而没有任何错误。我也可以使用 if else 或其他解决方案,但由于我是这项技术的新手,因此将不胜感激。提前致谢!

标签: swiftfirebasereact-nativepush-notification

解决方案


我不建议混合功能,但试试这个:

 - (void)application:(UIApplication *)application 
    didRegisterUserNotificationSettings:(UIUserNotificationSettings 
    *)notificationSettings {

      [[RNFirebaseMessaging instance] 
     didRegisterUserNotificationSettings:notificationSettings];

[RCTPushNotificationManager 
    didRegisterUserNotificationSettings:notificationSettings];

    }

所以你用同样的方法初始化两者。同样,不知道为什么你需要两者,你应该尽量只保留一个。


推荐阅读