Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using React Native within an iOS share extension

Jumping off of this facebook/react-native#1626 GitHub issue, I had a question about setting up a React Native view within an iOS share extension

I posted an example GitHub repo that demonstrates the problem, summarized below.

So far the proof-of-concept setup is pretty straightforward, but I feel like I'm missing something very simple.

In my react-native init scaffolded Xcode project I created a new Share Extension target, and within it linked the appropriate React Native static libraries (libReact.a, libRCTWebSocket.a, etc.). This gets our project compiling for a very simple ShareViewController that's a plain ‘ol UIViewController.

Upon activating my Share Extension from another app, my ShareViewController is initialized but immediately crashes with the following log messages:

2015-11-29 12:44:34.721 [warn][tid:com.facebook.React.JavaScript][RCTContextExecutor.m:129] 'undefined is not an object (evaluating \'RCTWebSocketModule.connect\')'
2015-11-29 12:44:34.726 ShareExtension[66473:2179009] -[RCTBatchedBridge redBox]: unrecognized selector sent to instance 0x7fb59d8ab200
2015-11-29 12:53:47.160 [warn][tid:com.facebook.React.JavaScript][RCTContextExecutor.m:129] 'Requiring module "InitializeJavaScriptAppEngine" which threw an exception'
2015-11-29 12:53:47.160 ShareExtension[66473:2179009] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RCTBatchedBridge redBox]: unrecognized selector sent to instance 0x7fb59d8ab200'

The line 'Requiring module "InitializeJavaScriptAppEngine" which threw an exception' looks particularly suspicious, and leads me to believe that I'm missing some basic JavaScriptCore setup within the share extension. Curious to know if there are any obvious areas to investigate, or if anyone else has solved this problem. Thanks!

like image 915
andrewsardone Avatar asked Nov 30 '15 03:11

andrewsardone


1 Answers

I had the same error and fixed it by adding "-ObjC" in my app extension target build settings (Other linker flags)

like image 183
djioul Avatar answered Oct 19 '22 12:10

djioul