I am trying to create a custom native module for React 0.61.2.
I have created the Android version, however there seems to be some issue with iOS.
I'm trying to do the following command:
#import <React/RCTBridgeModule.h>
@interface PaypalSdk : NSObject <RCTBridgeModule>
@end
And getting:
'React/RCTBridgeModule.h' file not found
It appears like there have been a lot of changes to how this works in early React Native .6 versions.
In another, earlier version of React, I added React.xcodeproj to my libraries and that worked, however that doesn't seem to be an option here, as React.xcodeproj was removed.
I am going through this issue, and have tested everything, but none of these things seems to work:
https://github.com/facebook/react-native/issues/25838
I have also tried everything here as well, including delete React from my schemes and re-adding it:
https://github.com/facebook/react-native/issues/24363
What might be causing this?
EDIT: part of my PaypalSdk.m file:
#import "PaypalSdk.h"
#import <PayPal-iOS-SDK/PayPalMobile.h>
#import <PayPal-iOS-SDK/PayPalConfiguration.h>
#import <PayPal-iOS-SDK/PayPalOAuthScopes.h>
#import <PayPal-iOS-SDK/PayPalProfileSharingViewController.h>
#import <QuartzCore/QuartzCore.h>
@implementation PaypalSdk
... various methods and properties here
RCT_EXPORT_MODULE()
RCT_EXPORT_METHOD(generateCode:(NSString *)code callback:(RCTResponseSenderBlock)callback)
{
... more code here
callback(@[[NSString stringWithFormat: @"code: %@", "test"]]);
}
@end
Instead of:
#import <React/RCTBridgeModule.h>
You typically would solve using this on 0.59x versions:
#if __has_include("RCTBridgeModule.h")
#import "RCTBridgeModule.h"
#else
#import <React/RCTBridgeModule.h>
#endif
However, from RN >= v0.60x, we need to add .podspec to podfile for whichever 3rd party/custom library that complain unable to find React/{whatever.h}. So please, don't add the .a file into your Xcode's Linked Framework and Libraries
.
To solve this, we can start doing:
Copy podspec
from other 3rd party library (eg, RNDeviceInfo/etc..);
Create own podspec
by replacing a few item (eg, s.name, s.source, s.source_files)
s.name = "MyPayPalLib"
s.source = { :git => "https://github.com/my-super-repo/paypal-lib-repo.git", :tag => "v#{s.version}" }
.
Follow the next steps, taking care if you Library is hosted on npm/yarn/git (remote) or stored locally in your project's dir.
.
Add this to track all your lib files:
s.source_files = "ios/**/*.{h,m}"
Add new lib to Podfile:
pod 'MyPayPalLib', :path => '../node_modules/MyPayPalLib'
Do a pod install
s.source
path as your need.s.source = { :http => 'file:' + __dir__ + '/' }
s.source_files = "customLib/*.{h,m}"
Add new lib to Podfile:
pod 'MyPayPalLib', :path => '../localLibFolder/MyPayPalLib'
Do a pod install
After fix the error: 'React/RCTBridgeModule.h' file not found in React Native 0.61.2
, the NativeModules
object was empty.
So, after some research, we got the issue: the s.source_files
prop had wrong value!
Always take careful to use the right s.source_files
podspec prop.
The OP was using: s.source_files = "react-native-paypal-sdk/*.{h,m}"
However, this should be: s.source_files = "ios/**/*.{h,m}"
This is the recommended way for remote repository.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With