I'm creating a react-native module I would like for this custom module to import another pod, specifically AFNetworking.
How do I go about this?
What I've done:
Adding pod 'AFNetworking', '~> 4.0' to my project's Podfile
Added s.dependency "AFNetworking" in my custom module's podspec
import "AFNetworking.h" in MyModule.mm
I get the error Expected unqualified-id
I've tried all variations of
#import “../../../Pods/AFNetworking/AFNetworking.h”
#import "AFNetworking.h"
#import "AFNetworking/AFNetworking.h"
#import <AFNetworking.h>
#import <AFNetworking/AFNetworking.h>
None of which seem to work
This does the trick
#import <AFNetworking/AFNetworking.h>
See What is the difference between #include <filename> and #include "filename"?
Related
I started a new react native application using :
react-native init myApplication
I started with splash screen so i used this library react native spalsh screen
I linked the library to generate native code using this command :
react-native link react-native-splash-screen
And i added files using Xcode like this :
In XCode, in the project navigator, right click Libraries ➜ Add Files to [your project's name]
Go to node_modules ➜ react-native-splash-screen and add SplashScreen.xcodeproj
In XCode, in the project navigator, select your project. Add libSplashScreen.a to your project's Build Phases ➜ Link Binary With Libraries
To fix 'RNSplashScreen.h' file not found, you have to select your project → Build Settings → Search Paths → Header Search Paths to add: $(SRCROOT)/../node_modules/react-native-splash-screen/ios
I build the app using Xcode in a real Iphone and i get this error in RNSplashScreen.h :
/**
* SplashScreen
* 启动屏
* from:http://www.devio.org
* Author:CrazyCodeBoy
* GitHub:https://github.com/crazycodeboy
* Email:crazycodeboy#gmail.com
*/
#import <React/RCTBridgeModule.h> // <------'React/RCTBridgeModule.h' file not found
#import <UIKit/UIKit.h>
#interface RNSplashScreen : NSObject<RCTBridgeModule>
+ (void)showSplash:(NSString*)splashScreen inRootView:(UIView*)rootView;
+ (void)show;
+ (void)hide;
#end
'React/RCTBridgeModule.h' file not found
the Podfile :
pod 'React', :path => '../node_modules/react-native/'
pod 'React-Core', :path => '../node_modules/react-native/React'
...... # other libaries
pod 'react-native-splash-screen', :path => '../node_modules/react-
native-splash-screen'
AppDelegate.m :
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "RNSplashScreen.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
.... <------- other code
[RNSplashScreen show];
return YES;
}
Instead of
#import <React/RCTBridgeModule.h>
use
#import "RCTBridgeModule.h"
Hope this helps you. Feel free for doubts.
I'm trying to implement a share extension with a firebase-based app. So I have created a pod file and generated a .xcworkspace project.
I'm using [react-native-share-extension][1]. Followed all installation tutorial and all seem ok, but when I try to launch the extension Xcode console says:
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'.
This is my pod file:
target 'Together' do
# Pods for Together
pod 'Firebase/Core'
pod 'Firebase/Auth'
pod 'Firebase/Firestore'
pod 'Firebase/Messaging'
pod 'Firebase/Storage'
pod "QBImagePickerController"
end
target 'TogetherShareEx' do
# Pods for TogetherShareEx
pod 'Firebase/Core'
pod 'Firebase/Auth'
pod 'Firebase/Firestore'
pod 'Firebase/Storage'
end
And this my TogetherShareEx.m:
#import <Foundation/Foundation.h>
#import "ReactNativeShareExtension.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <React/RCTLog.h>
#import <Firebase.h>
#interface TogetherShareEx : ReactNativeShareExtension
#end
#implementation TogetherShareEx
RCT_EXPORT_MODULE();
- (UIView*) shareView {
NSURL *jsCodeLocation;
[FIRApp configure];
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:#"index" fallbackResource:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:#"TogetherShareEx"
initialProperties:nil
launchOptions:nil];
rootView.backgroundColor = nil;
return rootView;
}
#end
I have also added these:
added '$(inherited)' in Other Linker Flags
added '$(SRCROOT)/../node_modules/react-native-firebase/ios/RNFirebase' in Header Search Paths
The result is that extension is created but when I try to share something, nothing happens. On Debugging the extension with Xcode the log shows the error shown above.
Any idea? Thanks
I was able to get this working after following the standard installation instructions, make sure you do the following:
Link libRNFirebase.a in your Extension's Build Phases. Also, make sure that libPods-{YOUR_EXTENSION_NAME}.a is linked as well.
Set the GoogleService-Info.plist target for both your main app
and your share extension in the right panel.
In your share extension's Build Settings > Other Linker Flags,
make sure you add $(inherited)
In your Share Extension .m file, make sure you import
Firebase and configure it there as well!
For more info, see the following GitHub thread: https://github.com/alinz/react-native-share-extension/issues/79
Steps I did:
pod repo remove master
pod setup
pod update --verbose (Just to check the progress especially when updating the Google SDKs, took so long to finish).
And there, I got the warning. In my logs, Google SDKs were updated successfully:
-> Installing Google 3.1.0 (was 3.0.3)
-> Installing GoogleMaps 2.3.0 (was 2.2.0)
Podfile:
target 'MyProj' do
...
pod 'Google/Analytics'
pod 'GoogleMaps'
...
target 'MyProjTests' do
inherit! :search_paths
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
end
end
end
end
I would like to know how to get rid of this warning.
Change pod 'Google/Analytics' to pod 'GoogleAnalytics' removing the slash.
Extending on Paul Beusterien answer:
First, remove old import from your bridging header:
#import <Google/Analytics.h>
Then, add the following to the bridging header instead:
#import "GAI.h"
#import "GAIDictionaryBuilder.h"
#import "GAIEcommerceFields.h"
#import "GAIEcommerceProduct.h"
#import "GAIEcommerceProductAction.h"
#import "GAIEcommercePromotion.h"
#import "GAIFields.h"
#import "GAILogger.h"
#import "GAITrackedViewController.h"
#import "GAITracker.h"
Finally you might want to recheck:
https://developers.google.com/analytics/devguides/collection/ios/v3/
You don't need GGLContext line anymore.
Hope this helps.
I'm very new to iOS and I'm coming from the Android background. I've read many post about this issue but I'm unable to resolve this issue.
My problem is that the app runs fine on the iPhone simulator but while running on the device it gives me following error -
error: 'AFNetworking.h' file not found
#import "AFNetworking.h"
^
<unknown>:0: error: failed to import bridging header ‘path/to/project/<main project directory>/projectName-Bridging-Header.h'
Update:
platform :ios, '7.0'
use_frameworks!
target 'SomeTarget' do
pod 'AFNetworking'
pod 'MSDynamicsDrawerViewController'
pod 'KRLCollectionViewGridLayout', '~> 0.2.0'
pod 'Canvas'
pod 'MBProgressHUD'
pod 'RBMenu'
pod 'RKTabView'
pod 'AHTabBarController'
pod 'Fabric'
pod 'Crashlytics'
end
My Bridging Header File
#import "AFNetworking.h"
#import "UIKit+AFNetworking.h"
#import "MSDynamicsDrawerStyler.h"
#import "KRLCollectionViewGridLayout.h"
#import "Canvas.h"
#import "MBProgressHUD.h"
#import "UIScrollView+TwitterCover.h"
#import "A3ParallaxScrollView.h"
#import "ParallaxHeaderView.h"
#import "UIImage+ImageEffects.h"
#import "SGFocusImageFrame.h"
#import "RBMenu.h"
#import "ILBarButtonItem.h"
#import "CMPopTipView.h"
#import "RKTabView.h"
#import "AHTabBarController.h"
#import "UIViewController+MJPopupViewController.h"
#import "NSString+FontAwesome.h"
#import “KMAccordionTableViewController.h"
#import <Crashlytics/Crashlytics.h>
Can you please point the issue I'm getting right now. Why it is running fine on emulator and not on actual device?
This might help somebody.
I've fixed this issue by adding an entry for Header Search Paths to "${PODS_ROOT}/" with recursive. Thanks to lostInTransit for pointing this attribute.
You can find Header Search Paths under BuildSettings for your project target.
As suggest title, I need to use InstagramKit (3.5.0) pod (written in objective-c) in a new swift project.
So I install pod (pod install), then I create my InstagramSwift-Bridging-Header.h and add-import library:
#import <InstagramKit/InstagramEngine.h>
Then, just building this empty project, I get:
/Users/.../workspace/InstagramSwift/InstagramSwift/InstagramSwift-Bridging-Header.h:5:9:
note: in file included from
/Users/.../workspace/InstagramSwift/InstagramSwift/InstagramSwift-Bridging-Header.h:5:
-(BOOL)application:(UIApplication *)application
^ <unknown>:0:
error: failed to import bridging header
'/Users/.../workspace/InstagramSwift/InstagramSwift/InstagramSwift-Bridging-Header.h'
Expected a type Failed to import bridging header
'/Users/.../workspace/InstagramSwift/InstagramSwift/InstagramSwift-Bridging-Header.h'
What could I miss?
After a lot of discussions with #eric-d, I probably find the problem in my podfile that was:
target "InstagramSwift" do
pod 'InstagramKit', '3.5.0'
end
So I deleted project and start again from an empty project using Podfile:
use_frameworks!
platform :ios, '8.0'
pod 'AFNetworking', '~> 2.5'
pod 'InstagramKit', '3.5.0'
Than I manually created SwitBridge.h and linked it in build settings.
Finally, in any swift file I can use instagramKit module, for example:
import InstagramKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let instagramEngine: InstagramEngine = InstagramEngine.sharedEngine()
}
}
Probably, problem was that platform setting is missing.
edit
Also,
"use_frameworks!"
thanks to this answer.