23

I am trying to implement PushNotificationIOS with a detached Expo app. I am running SDK 21.0.0 (React Native 0.48).

I am getting React/RCTEventEmitter file not found

I have completed the following steps:

  • Open my .xcworkspace project
  • Drag the RCTPushNotification.xcodeproj into my Libraries folder
  • Added libRCTPushNotification.a into App > Build Phases > Link Binary With Libraries
  • Added $(SRCROOT)/../node_modules/react-native/Libraries under Header Search Paths - I also tried without the /../. I have a bunch of Pods in the Header Search Paths list too.

I then added the following into AppDelegate.m but when I click through to the file (⌘ + click), I get a question mark.

#import <React/RCTPushNotificationManager.h>

If I change it to the below, it works, I can click through

#import "RCTPushNotificationManager.h"

However, this is my problem

When I clean and build my project, I get the below error in RCTPushNotificationManager.h to say:

'React/RCTEventEmitter.h' file not found
Dan
  • 8,041
  • 8
  • 41
  • 72

8 Answers8

21

@Dan I have ran into this exact same issue, it also occurs for RCTLinking, and other libraries dependent on eventEmitter.h and a detached Expo project.

The issue turns out to be that RCTPushNotification doesn't have the reference to React from Cocoapods file React since Expo manages React in Cocoapods. So you should go into RCTPushNotification.xcodeproj then into Targets - RCTPushNotification Header Search Paths and add the link to "ios/Pods/Headers/Public/React" and set to recursive.

RCTPushNotification Target Build Settings The easiest way to do the above is navigate to your iOS/Pods/Headers/Public/React and drag and drop the folder straight into build settings for header search paths like the below image.

enter image description here

Heads up finally after this you will have to reference ReactCommon/yoga most likely as well, ReactCommon/yoga however should be in your 'node_modules/react-native/ReactCommon/yoga'

Escamilla
  • 321
  • 2
  • 8
  • 3
    This worked for all of my `RCTxxxx` `Libraries` that had this problem. – ewizard Oct 24 '18 at 13:54
  • I have the same problem, I have expoKit project and I don't have Libraries folder with RCTPushNotification in it, I added "RCTPushNotification" through Pod file. How can I go to the "RCTPushNotification.xcodeproj then into Targets - RCTPushNotification Header Search Paths" - in that case? – Lucky_girl Apr 17 '19 at 15:10
  • 2
    I'm trying with .60 and they've renamed it to `React-Core`, so the path is slightly different. This is a reasonable fix however if you clean out the node_modules folder you'd have to redo this fix (correct?). Lastly this caused another issue where React-Core couldn't see yoga/Yoga.h. I'm just going to manually link everything similar to how .57 did. – Chris Jul 12 '19 at 17:49
  • Did not work. Now I get `linker command failed with exit code 1 (use -v to see invocation)` :/ – chitzui Jul 28 '19 at 15:10
  • The subsequent problem reported by @chitzui is caused by opening the project's `.xcodeproj` instead of the `.xcworkspace`. If you use the `.xcworkspace` file, the linker will run successfully. – Jim Riordan May 30 '20 at 11:16
8

This works for me on detached Expo project

"react": "16.6.3",
"react-native": "0.58.6",

Add 'RCTPushNotification' to your pod and run pod install

pod 'React', :path => '../node_modules/react-native', :subspecs => [    
    'RCTPushNotification',
  ]
Underdog
  • 785
  • 10
  • 21
  • 5
    This solution worked for me with React 0.60 (too bad their docs don't say this). The only difference is I used this line: `pod 'React-RCTPushNotification', :path => '../node_modules/react-native/Libraries/PushNotificationIOS'` instead of the subspecs bit. – Chris Jul 12 '19 at 18:04
  • 1
    @Chris I'm also on RN 0.60 but I'm getting a not found error when importing `RNCPushNotificationIOS` in `AppDelegate.m` even after successful import in Podfile and after importing the `RCTPushNotification.xcodeproj` and linking `libRCTPushNotification.a`. Can you please share your working example somewhere like Github. Thanks – Raees Iqbal Jul 16 '19 at 12:22
  • 2
    @RaeesBhatti with the pod install you do not need to import the `xcodeproj` or manually link the `.a` file. After updating my pod file (be sure to delete the Pods directory and run `pod install` again) I'm able to add `#import ` to my `AppDelegate.m` just fine. All the other items are automatic. – Chris Jul 16 '19 at 13:23
  • 4
    `pod 'React-RCTPushNotification', :path => '../node_modules/react-native/Libraries/PushNotificationIOS'` and undoing the manual linking worked for me as well – The instructions at https://facebook.github.io/react-native/docs/pushnotificationios seem to be out of date. Just wasted half a day on this. – nexus Jul 17 '19 at 07:59
  • 1
    @nexus I concur. I just wasted about half a day as well. :( – bobber205 Jul 19 '19 at 21:28
  • I think you guys just saved my job ! Spent about a day on this ... Thank you. – T M Aug 01 '19 at 11:31
  • I have tried everything, include the solution in the comments.... and when I do that it will compile, but then will not run... I see this: https://www.dropbox.com/s/pat9286hmcd4ifg/Screenshot%202019-08-02%2014.01.50.png?dl=0 – harrisreynolds Aug 02 '19 at 19:05
7

Since nothing mentioned above worked for me, I started experimenting, and this is what solved it for me:

1. Link React-Core & Public

As mentioned by Escamilla, in xcode open the RCTPushNotification.xcodeproj and under Build Settings search for header search path and add there the 2 path:

  • "$(SRCROOT)/../../../../ios/Pods/Headers/Public"
  • "$(SRCROOT)/../../../../ios/Pods/Headers/Public/React-Core"

2. Copy RCTPushNotificationManager.h manually into React-Core

In the root folder of your project execute:

cp ./node_modules/react-native/Libraries/PushNotificationIOS/RCTPushNotificationManager.h ./ios/Pods/Headers/Public/React-Core/React

This will copy RCTPushNotificationManager.h wich is in node_modules/react-native/Libraries/PushNotificationIOS/ manually into the React folder which is in ios/Pods/Headers/Public/React-Core/React.


I have no idea if that is a good solution but it works. Maybe if someone could explain me why it was not in there in the first place? That would be golden.

I followed the setup instructions 1 by 1 very carefully doing everything right but nothing worked except the manual copy mentioned above…

Also, this is randomly resetted once in a while and has to be done again -.-'

chitzui
  • 3,778
  • 4
  • 28
  • 38
  • 2
    I've spent about two days trying to fix this issue, and came across your #1 solution; it did the trick. Thank you! – schoenbl Aug 22 '19 at 03:15
4
  1. Open up your project in XCode.
  2. Open up the Libraries folder. You should see React.xcodeproj and several RCT*.xcodeproj.
  3. Drag the React.xcodeproj into each of the other projects.
  4. Click on each project and navigate to the Build Phases tab.
  5. Click on Target Dependencies and add React as a target dependency
3

Just follow these steps:

  1. create project react-native init project.
  2. add this line to pod file in ios folder: pod 'React-RCTPushNotification', :path => '../node_modules/react-native/Libraries/PushNotificationIOS'
  3. cd ios && pod install
  4. cd .. && react-native run-ios

No need to do messy manual linking

Umair Riaz
  • 456
  • 3
  • 12
1

Replace #import RCTEventEmitter.h or #import React/RCTEventEmitter.h with #import <React/RCTEventEmitter.h>

Its work for me

J.K.Rai
  • 104
  • 3
0

this worked for me!

add the missed lib manually

https://github.com/microsoft/react-native-code-push/issues/1565#issuecomment-489738672

-1

USE those libraries:

follow step by step, everything will work no need anything else

not forget to

pod install

Govan
  • 1,322
  • 1
  • 14
  • 13