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

React Native PushNotificationIOS无法正常工作,编译报错求助

Fixing PushNotificationIOS Compilation Error: 'React/RCTEventEmitter.h' file not found

Hey, I’ve run into this exact issue before when setting up PushNotificationIOS in a React Native project—super frustrating when you’ve followed all the docs and still hit this error. Let’s walk through the most common fixes that worked for me and other developers:

1. Verify React Native Version Compatibility

This error often pops up when there’s a version mismatch between React Native and the PushNotificationIOS component, especially after upgrading/downgrading RN:

  • For RN 0.60+ (which uses auto-linking): First, unlink any manual links that might be causing conflicts:
    react-native unlink @react-native-community/push-notification-ios
    rm -rf node_modules && yarn install # or npm install
    cd ios && pod install && cd ..
    
  • For RN 0.59 and older: Double-check your manual linking setup, specifically the Header Search Paths:
    • Open Xcode, select your project → Build Settings → Search for Header Search Paths
    • Make sure $(SRCROOT)/../node_modules/react-native/Libraries/EventEmitter is listed and set to recursive
    • Also confirm $(SRCROOT)/../node_modules/react-native/React is present, also set to recursive

2. Clear Xcode Cache & Build Files

Xcode’s cached build files are often the culprit for weird compile errors. Do a full clean:

  • Close Xcode entirely
  • Delete the ios/build folder in your project root
  • Reopen Xcode, press Cmd+Shift+K to clean the build, then Cmd+Option+Shift+K to clear derived data
  • Try compiling again

3. Double-Check AppDelegate.m Imports & Setup

Make sure your AppDelegate.m has the correct imports and required delegate methods—mixing old/new syntax can break things:

// For RN 0.60+
#import <React/RCTPushNotificationManager.h>

// For older RN versions
// #import "RCTPushNotificationManager.h"

// Don't forget these required methods
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
  [RCTPushNotificationManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification
{
  [RCTPushNotificationManager didReceiveRemoteNotification:notification];
}

4. Confirm React Libraries Are Properly Linked

Sometimes the core React libraries themselves aren’t linked correctly:

  • In Xcode, go to your project → Build Phases → Link Binary With Libraries
  • Check if libReact.a (or libReact-Core.a for newer RN versions) is in the list. If not, click the + button to add it
  • Also verify that libRCTEventEmitter.a is present here

5. Validate Podfile Configuration (RN 0.60+)

If you’re using CocoaPods, make sure your Podfile includes all necessary React and PushNotificationIOS dependencies:

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

target 'YourProjectName' do
  config = use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath]
    # Uncomment if using Hermes
    # :hermes_enabled => true
  )

  # Ensure PushNotificationIOS pod is included
  pod 'RNCPushNotificationIOS', :path => '../node_modules/@react-native-community/push-notification-ios'

  target 'YourProjectNameTests' do
    inherit! :complete
    # Pods for testing go here
  end
end

After updating the Podfile, run cd ios && pod install again.

If none of these steps work, try creating a fresh React Native project and only add PushNotificationIOS to it—this will help you rule out any project-specific configuration issues.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 08:35:00