Use React Native (0.60.4) in an iOS Share Extension - ios

As the title implies, I tried to load a React Native application (version 0.60.4) in my native iOS Share Extension but got the following error: sharedApplication is unavailable: not available on iOS (App Extension)
It seems React-Core (and other libraries like FBSDK) are using sharedApplication which isn't known inside the Share Extension 'architecture'?
I have tried using this sample project but it doesn't compile out of the box.
It uses React Native v0.15 which perhaps worked at the time.
Does anyone have an idea how to implement the latest React Native version inside an iOS Share Extension?

Related

No debugging with VS code for React Native app (expo) possible

I'm currently programming a React Native app (expo) with Visual Studio Code.
For testing I'm using the iOS simulator.
Until now the setup has worked fine. But now I have a problem with debugging my application. When I want to create a new launch.json file, there is no React Native environment in the dropdown list (see picture below).
I already tried to manually add the launch.json file. But when I want to add a configuration there is also no React Native entry available.
Can anyone please help me?
For debugging I installed the React Native Tools Extension (I also tried differnet versions).
Version Info:
macOS Big Sure: 11.3.1
VS Code: 1.61.2
React Native Tools: 1.7.1
The best way for debugging react-native applications is using a react-native-debugger tool, check out the link below for installation and get started with this amazing community-driven tool:
React-Native-Debugger

React native link Ejecting

I tried searching in previous questions, but I did not find it. I made the mistake of using Create React Native App projects. I am trying to do react native link. I did npm i --save. I get an error
react-native link can not be used in Create React Native App projects. If you need to include a library that relies on custom native code, you might have to eject first. See https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md for more information.
I read this and sadly I am completely at a lost. I am using visual studio code and not xcode.
The error is exactly as it states. You cannot link assets and libraries that require linking unless you eject the project from Create React App and get the native project files. Ejecting gives you the native code and with that, you can use Xcode to link libraries with native code.
Create React App is built on Expo, which aims to allow you to develop apps, especially iOS apps, on any platform. But Expo comes with its restrictions due to the very nature of what it accomplishes.
Thus, the problem arises when you want to link platform dependent libraries that require Xcode in iOS's case. Xcode is the proprietary - and really, the only way, to build Apple-based projects that require external libraries because they require APIs and environments only available with it. This was one the huge reasons Expo arose, to allow people to build apps with React Native without having Xcode, but it has its limitations.
So, you cannot use a library that requires linking with native code if you do not have Mac OS because APIs and tools needed for it are only offered on Mac OS.

How to build a react native dynamic library for a specific ios version?

I want to inspect my app and do some CPU profiling and according to this video https://youtu.be/0MlT74erp60, I am supposed to build a react native dynamic library for a specific iOS version. I have managed to build a library and link it through Xcode but can't figure out the command for how to build it for a "specific" ios version.
Any help is much appreciated.

What is the role of RCTSRWebSocket in iOS version React Native?

I saw 'RCTSRWebSocket' in iOS version React Native project, but I can't find any 'import' of this lib in whole project. so what's the role of RCTSRWebSocket in React Native? I guess it's be used to connect Terminal and Simulator?
It's one of the fundamental native modules of React Native.
It's used for dual simultaneous communication, at least, with the bundler service.
Android also has this module (Java implementation) for the same purpose.

Using embedded framework in extension's containing app with deployment target iOS 7.0 and earlier

I'm developing Today Widget Extension for an app with deployment target earlier than iOS 8.0.
In apple Extension Programming Guide they recommended to use embedded framework to share code between app extension and its containing app.
You can create an embedded framework to share code between your app
extension and its containing app.
In the end of this guide they explain how to deploy a containing app to older versions of iOS 8.0 by using dlopen command.
After I have added the framework target the project doesn't build successfully.
It's always failed with the following errors :
Lipo Error : /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: can't open input file: PATH_TO_BUILD/armv7/APP_NAME (No such file or directory)
Apple Mach-O Linker Error : ld: embedded dylibs/frameworks are only supported on iOS 8.0 and later (#rpath/FRAMEWORK_NAME) for architecture armv7
(Error 2 repeats with arm64 architecture)
What I'm doing wrong ?
Is there another way to share code between app extension and its containing app ?
If someone know about the dlopen solution, please input with a "How to" tutorial (examples are welcome).
You can't use embedded frameworks on iOS 7, even with dlopen.
What they're explaining on that page (and not very clearly) is that if your app uses an embedded framework on iOS 8 and you want to deploy the app on iOS 7, you can't have the framework load automatically on iOS 8. Instead you copy the framework into the app bundle as part of the build process and then, on iOS 8 only use dlopen to load the framework from code.
On iOS 7, the framework will exist in the app bundle, but iOS 7 does not support loading it into the app by any means, including dlopen
If you want to share code between an app and an extension and deploy on iOS 7, you cannot use a framework to share the code. You need to include all of the shared code in both the app target and the extension target.

Resources