You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native iOS推送报No known class method for selector错误

问题原因

No known class method for selector 'didReceiveNotificationResponse:'报错是因为你调用RNCPushNotificationIOS的didReceiveNotificationResponse方法时参数不匹配,你当前使用的版本要求该方法传入两个参数,你仅传入了response一个参数,编译器找不到对应签名的类方法。

修复方案

1. 修改回调方法实现

把AppDelegate.m中对应的didReceiveNotificationResponse方法替换为以下代码:

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

不需要单独调用completionHandler(),直接将回调透传给RNCPushNotificationIOS即可。

2. 补充协议声明(可选检查)

检查AppDelegate.h文件中是否已经遵循UNUserNotificationCenterDelegate协议,正确的头文件声明参考:

#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>
#import <UserNotifications/UserNotifications.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate>

@property (nonatomic, strong) UIWindow *window;

@end

3. 验证依赖安装

执行以下命令重新安装iOS依赖,确保依赖版本匹配:
cd ios && pod deintegrate && pod install && cd ..


内容的提问来源于stack exchange,提问作者Joseph Vasse

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 03:06:03