Getting react-native-fbsdk to work with CocoaPods - react-native

I've been trying to get react-native-fbsdk to work with CocoaPods, since I much prefer fetching the Facebook SDK as part of the pod install process, but I haven't had much luck. I'm aware that I can react-native link the npm library and manually download and add the necessary frameworks, but this seems rather silly when I have a perfectly good package manager at my disposal.
Judging by the documentation it should be fairly straight forward - just add the necessary pods to the Podfile, right? But no matter what I try the native FBSDK modules never seem to be included. I've tried a whole host of different Podfiles, some with use_framework! and pod 'Bolts', some with just pod 'FBSDKCoreKit'. This is the one I'm currently on:
target 'FacebookPods' do
pod 'FBSDKCoreKit'
pod 'FBSDKShareKit'
pod 'FBSDKLoginKit'
target 'FacebookPodsTests' do
inherit! :search_paths
end
end
But when I run my test app and try to do anything with the react-native-fbsdk module I get errors complaining about various native modules being undefined. Here's my index.ios.js file, trying to access the LoginManager:
import React, {Component} from "react"
import {AppRegistry, Text} from "react-native"
import {LoginManager} from "react-native-fbsdk"
export default class FacebookPods extends Component {
componentWillMount() {
LoginManager.logInWithReadPermissions(["email"])
.then(() => console.log("Success!"))
.catch((err) => console.log("Failure!", err))
}
render() {
return <Text>Hello World</Text>
}
}
AppRegistry.registerComponent("FacebookPods", () => FacebookPods)
But this throws the error undefined is not an object (evaluating 'LoginManager.logInWithReadPermissions' in FBLoginManager.js. Further inspection of NativeModules shows that no native FBSDK modules are included at all. I also get the following warnings at launch:
2017-07-13 19:50:19.006 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RCTFBLikeView" does not exist
2017-07-13 19:50:19.007 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RCTFBLoginButton" does not exist
2017-07-13 19:50:19.008 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RCTFBSendButton" does not exist
2017-07-13 19:50:19.009 [warn][tid:com.facebook.react.JavaScript] Warning: Native component for "RCTFBShareButton" does not exist
So yea, I'm at a complete loss. In my mind, simply adding the pods ought to be enough to include the frameworks. I've scoured the interwebs for any additional steps that I might've missed, but there isn't much, save for a few issues on the react-native-fbsdk project that have since then been removed.

I encountered this issue and managed to get react-native-fbsdk working with the Facebook SDK installed by adding the following to my pod file:
pod 'FBSDKCoreKit'
pod 'FBSDKLoginKit'
pod 'FBSDKShareKit'
and importing the following in AppDelegate.m:
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKShareKit/FBSDKShareKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
Note that these imports are different from the suggestion in the react-native-fbsdk readme. That's because FBSDKCorekit.framework, FBSDKShareKit.framework and FBSDKLoginKit.framework are not available.
You also need to link libFBSDKShareKit.a, libFBSDKCoreKit.a and libFBSDKLoginKit.a from the General tab in Xcode. These are the only three Core/Login/Share things available to link. They refer to the pods, and looking in the pods directory you see there are no .framework files, just .h files, so those are the ones we import into AppDelegate.m. That (I think) gives react-native-fbsdk all the files in the the SDK components that it needs.

It's working for me with my Podfile set up this way (not sure Bolts framework pod is needed):
pod 'Bolts'
pod 'FBSDKCoreKit'
pod 'FBSDKLoginKit'
pod 'FBSDKShareKit'
And I had to do react-native link to make sure that the libRCTFBSDK.a is in the xcode's Build TARGET => build phrases => "Link Binary with libraries" list. If not, you probably need to add the libRCTFBSDK.a in manually. I found that once I ran the react-native link and the libRCTFBSDK.a is in that list, xCode then compiled correctly.

If you use cocoapods, react native will use cocoapods to link link libraries. I created a new project then install and link all packages before run 'pod init' and 'pod install'. Maybe this error from cocoapods when link packages. All packages need 'react-native link' you installed after run 'pod install' it not working. I think we can deintegate cocoapod before run react native link.

Related

React Native: Invariant Violation when using "React-Native-FS"

I have been trying to use "React-Native-FS" while developing a react native application. However, whenever I try to import "React-Native-FS" to my app I get the following message:
Invariant Violation: Native Module Cannot Be Null
Does anyone have any clue what could be causing this? I've searched around and can't find an answer. Any help would be greatly appreciated. Thanks!
try to do link your library with
react-native link react-native-fs
if its not linked try to do manually linking with below step
ANDROID
... 1. android/settings.gradle
include ':react-native-fs'
project(':react-native-fs').projectDir = new File(settingsDir,'../node_modules/react-native-fs/android')
2.android/app/build.gradle
dependencies {
implementation project(':react-native-fs')
}
ANd do build android project with android studio
IOS
Adding with CocoaPods
Add the RNFS pod to your list of application pods in your Podfile, using the path from the Podfile to the installed module:~~
pod 'RNFS', :path => '../node_modules/react-native-fs'
Install pods as usual:
pod install
Adding Manually in XCode
In XCode, in the project navigator, right click Libraries ➜ Add Files to [your project's name] Go to node_modules ➜ react-native-fs and add the .xcodeproj file
In XCode, in the project navigator, select your project. Add the lib*.a from the RNFS project to your project's Build Phases ➜ Link Binary With Libraries. Click the .xcodeproj file you added before in the project navigator and go the Build Settings tab. Make sure 'All' is toggled on (instead of 'Basic'). Look for Header Search Paths and make sure it contains both $(SRCROOT)/../react-native/React and $(SRCROOT)/../../React - mark both as recursive.
Run your project (Cmd+R)

'FirebaseCore/FirebaseCore.h' file not found in RNFIRMessaging.h

In Podfile, when using use_frameworks! globally to integrate swift pods in my react native project, Firebase pod files starts giving error
Firebase pods:-
pod 'Firebase'
pod 'Firebase/Messaging'
Error :-
'FirebaseCore/FirebaseCore.h' file not found in RNFIRMessaging.h
issue gets resolved when comment out use_frameworks! in podfile but then i am unable to install swift pods. also tried :modular_headers => true for specific swift pods but pod file is not installing.
Swift pods i am trying to install are :-
pod 'Kite-Print-SDK'
pod 'PayPal-iOS-SDK/Core'
please help me out to resolve this issue..
Please consider check at edit scheme ->Build -> check if Find Implicit Dependencies. if not enable please enable it and rerun.
I actually had a similar problem,
my solution was to change the code manually wherever there was that error.
change
import <FirebaseCore/FirebaseCore.h>
to
import <FirebaseCore.h>

FirebaseMessaging module not found

When ever I write #import FirebaseMessaging; is says -
Module 'FirebaseMessaging' not found
What I did - I install the pods with only Firebase/Core, but after that I realised Firebase/Messaging is also necessary to enable push notifications.
Then I wrote pod 'Firebase/Messaging' in the pod file and install the pods again.
The pod folder contains the folder as Firebase Messaging, but when I import it it says no module found.
You dont need to import FirebaseMessaging
Just add #import Firebase and you will get access to FIRMessaging
I had this issue and I could solve it this way:
if you have a framework that has Firebase/Messaging as it's dependency, and if you have set your framework's build settings to:
Build Active Architecture only
Debug No
Release No
you will get FirebaseMessaging module not found error. just try to make it like this:
Build Active Architecture only
Debug Yes
Release No
Had the same problem. Turns out that you need to place
use_frameworks!
in your Podfile. My Podfile now looks like this:
platform :ios, '8.4'
use_frameworks!
target 'YourTarget' do
pod 'Fabric'
pod 'Crashlytics'
pod 'Bolts'
pod 'Firebase/Core'
pod 'Firebase/Messaging'
# any other Firebase modules you need
end
You don't need to import FirebaseMessaging separately in the latest Firebase SDK according to the latest https://firebase.google.com/docs/cloud-messaging/ios/client:
#import Firebase & just include in your pod file
pod 'Firebase/Messaging'
I hope it will help.
If anything is not working, then you should try
Comment the Firebase and FirebaseMessaging from your Podfile
run pod install
add following to your pod file
pod 'Firebase', '~> 5.4'
pod 'FirebaseMessaging', '~> 3.0'
next is to pod install --repo-update
close your project and open workspace.
when you import the Firebase and try to import FirebaseMessaging, it will show you red marked lines, which means once you import Firebase it already imported the red marked modules in it.
Try it, if it fixes. I have tried and everything is working fine.
Please follow these process :
Clean the Application from product > clean
Close the Application
Again Open workspace of the Application
Again clean.
Hope it will help to you.Thank you.

Error: RNFirebase core module was not found natively on iOS

I created a new app and I am trying to use react-native-firebase. But I continually get this error:
RNFirebase core module was not found natively on iOS, ensure you have
correctly included the RNFirebase pod in your projects 'Podfile' and
have run 'pod install'.
See http://invertase.link/ios for the ios setup guide.
Steps that I have done:
yarn add react-native-firebase
react-native link react-native-firebase
Set up my .plist file from Google under .../myproject/ios/myproject
Ran pod updateafter ensuring I was using Ruby 2.5.0
Ran pod install
The pod file that I am currently using is:
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
target 'MyProject' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
pod 'Firebase/Core'
pod 'Firebase/Database'
pod 'Firebase/Messaging'
target 'MyProjectTests' do
inherit! :search_paths
# Pods for testing
end
end
These are the versions that I am using:
"react": "^16.3.0-alpha.1",
"react-native": "0.54.2",
"react-native-firebase": "^3.3.1",
If you don't want to manually link, you can try installing RNFirebase as a pod install directly:
pod 'RNFirebase', :path => 'path/to/node_modules/react-native-firebase/ios'
Changing or hardcoding HEADER_SEARCH_PATHS did not help me. When the error recurs, it's not necessary to rm -rf node_modules nor delete the pod file etc, I found it useful to clear the cache.
I always prefer not to use pods with react native, however, the react-native-firebase's instructions for the non-pop installation will not work.
The reason for this is the package's search paths which assumes either /pods or /firebase
Hence, to make it link properly follow these steps:
download firebase sdk
make a folder directly under ios and call it Firebase, copy the frameworks needed of the sdk in that folder WITHOUT keeping the sub-folders (note, you have not entered XCode yet)
If you haven't already npm install -s react-native-firebase
Open XCode and drag and drop the desired frameworks to the Frameworks-folder in XCode (Eg. in my example the contents of the Analytics, Messaging and DynamicLinks folder). Do not copy items when asked as you already have then in the Firebase subfolder of ios:
In XCode right-click Libraries and select "Add files to [project]". Find RNFirebase-project in node_modules and select the RNFirebase.xcodeproj, do not "copy items"
In Project/Target settings go to Linked Frameworks and Libraries. Find and add libRNFirebase.a
In AppDelegate.m make adjustments as per the instructions from react-native-firebase, eg: import <Firebase.h> and [FIRAPP configure]; in didFinishLaunchingWithOptions
In Header Search Paths AND Framework Search Paths, add $(PROJECT_DIR)/Firebase
Don't forget to add you GoogleServices-Info.plist to your project
I had the same problem, while trying to fix it was making my app to crash on start up.
I moved it through the terminal under the ios/AppFolder/ but the Xcode was never aware of this file.
What helped me was to open my project in Xcode. Then left-click on my AppFolder > Add Files and then add the GoogleService-Info.plist.
I manually linked these react-native-firebase/* packages with
react-native link #react-native-firebase/xxx
"#react-native-firebase/analytics","#react-native-firebase/app","#react-native-firebase/auth","#react-native-firebase/crashlytics","#react-native-firebase/messaging"
which generated pod spec in pod and it worked.

React/RCTEventEmitter.h file not found

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 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.
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.
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'
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',
]
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 -.-'
Open up your project in XCode.
Open up the Libraries folder. You should see React.xcodeproj and several RCT*.xcodeproj.
Drag the React.xcodeproj into each of the other projects.
Click on each project and navigate to the Build Phases tab.
Click on Target Dependencies and add React as a target dependency
Just follow these steps:
create project react-native init project.
add this line to pod file in ios folder: pod 'React-RCTPushNotification', :path => '../node_modules/react-native/Libraries/PushNotificationIOS'
cd ios && pod install
cd .. && react-native run-ios
No need to do messy manual linking
Replace #import RCTEventEmitter.h or #import React/RCTEventEmitter.h with #import <React/RCTEventEmitter.h>
Its work for me
this worked for me!
add the missed lib manually
https://github.com/microsoft/react-native-code-push/issues/1565#issuecomment-489738672
USE those libraries:
https://github.com/zo0r/react-native-push-notification
https://github.com/react-native-community/react-native-push-notification-ios
follow step by step,
everything will work
no need anything else
not forget to
pod install