How to write IOS framework for react native components - ios

I have few components written in Objective-c and Swift.
When I want to use it in any react native project, i will manually copy those native components and creating a bridge.
Now i want to use the same components in multiple projects, so i'm thinking of putting all those native components along with bridging part into one framework.
To start with i developed a simple framework with a simple native view..as below
When i try to run ComponentTest project, frameworks fails to build with error saying RCTViewManager.h is not found. I'm sure this dependency will be available in all projects which uses my framework.
ComponentTest/node_modules/tmobcomponents/ios/TMobileNativeComponents/TMobileNativeComponents/components/SimpleView/SimpleViewManager.h:12:9: Include of non-modular header inside framework module 'TMobileNativeComponents.SimpleViewManager': '/Users/someone/Library/Developer/Xcode/DerivedData/ComponentTest-auqzutioszphtnhfizcfhndibnnl/Build/Products/Debug-iphonesimulator/include/React/RCTViewManager.h'
Is it possible to build a framework without adding ReactNative dependency in framework, because React native dependency(RCTViewManager) will be available in the project which uses my framework.
How to accomplish this (Native views and also bridging part(native) ) should be in framework

Related

Main app can't reference framework used in React Native Library

I need some advice about building react native library that using framework. I'm trying to build one using this library. My react native library contains these files:
Sample-Bridging-Header.h
Sample.m
Sample.swift
Sample.xcodeproj/
Utilities/Utility.swift
Utilities/Helper.swift
Test.framework
Inside my Utility.swift and Helper.swift, I import library Test and there is no issue there.
However, when I build the sample app which uses the library, it will not build and it gives the error no such module 'Test'.
So it looks like if the main application try to use the react native library, and if the library uses a framework, the main application can't reference the framework. I'm not sure if this is the right approach or not.
I built react native library before and it worked for me but I never have to reference any framework.
Appreciate any help! Thanks!
Actually I just figured out how to handle this. I just need to update the podspec to include the framework by using s.ios.vendored_frameworks = ios/Test.framework.
Once I did that, I run pod install again for my example project. So now it can pull the framework in properly.

How to add a local framework to a Flutter plugin for iOS

So, I've been struggling for some time with embedding a third party framework into a Flutter plugin I'm writing for iOS.
The plugin is fairly straightforward, mostly just forwarding calls and events to/from the third party framework.
The third party framework in questions is for controlling a Sphero robot (RobotKit.framework).
This particular framework is an umbrella framework, with several sub frameworks within.
To include this .framework in my plugin, I've tried a lot of combinations between
preserve_paths
vendored_frameworks
resource
xcconfig
in the .podspec file to link to the RobotKit.framework package (inspired by blog), but without luck.
I can use
vendored_frameworks = 'Frameworks/RobotKit.framework'
to get Xcode to detect the package and import the headers, but when building I get an error linking to a header in one of the sub frameworks (RobotKitClassic is a sub framework):
fatal error: 'RobotKitClassic/RobotKitClassic.h' file not found #import <RobotKitClassic/RobotKitClassic.h>
Am i approaching this the wrong way, or is there a trick that I'm missing?
I ended up working around this by implementing the plugin functionality directly in my main app project instead of in a separate Flutter plugin.
Doing this, i can add the RobotKit framework to the Runner project and it links, builds and runs just fine.
IF your case is nested frameworks to use the result in app then nesting frameworks isn't allowed in IOS , here from apple forums , I faced error like can't load frameWork #rpath to do this all code in dynamic framework must be pure code not pods or plugins

Xcode: Embed Framework in React Native Module without modifying application project

I am developing a React Native Module that includes our Framework 'AntaviSense'.
I am able to include the framework in the main project and by "embed framework" in the Project Settings, everything works fine.
React Native Module
Adding to main project works
My question though is: can I avoid changing the main project, and just include it into the React Native Module project (which is a subproject)? I tried various directories in "React-Module/Build Phases/Copy Files" without luck. This would make the inclusion into other projects much easier.
node-xcode could be an option, it enables you to parse an modify XCode projects, I am not a React developer but you could create a node-script which modifies the project and adds the framework when you add the module (in cordova this would be a hook, maybe there is something similar in React).

Xcode: Linking external framework in a framework project

I am creating a framework (say My.framework) which will make use of an external framework (say External.framework).
I don't want to include External.framework in My.framework, since it increases my framework's binary size.
How do i build My.framework, so that the host project works only if the External.framework is present?
You can create workspace, with your App, your framework and external framework.
In your framework in target general tab add external framework to Linked Frameworks and Libraries.
In project two if you include your framework but without external framework, compiler will signal error.

Using code from framework without linking it

I am building a cocoa touch framework and including in my code third party framework - "framework_X"
How can i use it in a way that "framework_X" will not be linked directly to my framework, instead it will require the consumer project which use my framework to link "framework_X" to his project in order for it to work.
In Android this is done easily, but in Xcode if i am not linking the "framework_X" in my framework the project won't build
You can load libraries at runtime. Here an example of loading zlib with dlopen():
https://github.com/nicklockwood/GZIP/blob/master/GZIP/GZIP.m

Resources