Using React Native within an iOS share extension
Asked Answered
B

1

7

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!

Bunn answered 30/11, 2015 at 3:17 Comment(0)
N
6

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

Nub answered 4/12, 2015 at 23:14 Comment(1)
Good catch, @dijoul! Adding that linker flag fixed the problem. Here's the commit. Thanks!Bunn

© 2022 - 2024 — McMap. All rights reserved.