Using React Native within an iOS share extension - ios

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!

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

Related

How to fix [AWSTask exception] crash in AWSCore (AWS-sdk-ios)

I use AWS-SDK for iOS 2.6.14 (latest through Cocoapods) and have faced next issue:
I got a message in Xcode console:
-[AWSTask exception]: unrecognized selector sent to instance 0x17587ac00
And then application is crashed.
I've tried to prevent it by creating custom extension:
extension AWSTask {
public func exception() {
print("AWSTask exception method called")
}
}
I know that it's awful solution but I have no idea how to fix the issue which source is in 3rd-party component.
Then I've got next message and app crash:
*** Terminating app due to uncaught exception of class 'AWSTask'
Exception breakpoint stops in AWSTask method - (AWSTask *)continueWithExecutor:(AWSExecutor *)executor block:(AWSContinuationBlock)block cancellationToken:(nullable AWSCancellationToken *)cancellationToken
On line id result = block(self);
(It's in source code of AWSCore framework).
I have searched for similar issues on AWS-sdk-ios GitHub and found some but it contain no answer.
I also created new issue myself.
How can I fix it on my side?
As it turns out I have AWSMobileHubHelper.framework integrated as static library. It seems it is the source of the crash.
I found AWSMobilehubHelper's source at this repo.
But unfortunately can't manage to build a static library (because of building script issue).
Eventually, I've added the source to project with the bridging header.
And it seems to work now.

Unrecognized selector UIDeviceRGBColor countByEnumeratingWithState:objects:count:

I know this is kind of a dupe, but I don't have enough reputation yet to comment on the original post and, while I don't have an answer, I do have more useful information (a concrete example). Moderators, feel free to move this to the proper location.
When compiling my code using the latest XCode 8 beta 6 (iOS 10 SDK), I get an exception "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIDeviceRGBColor countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x600000071340'"
This happens during the call:
auto viewController = [[[UIViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
I have isolated the problem by whittling down my project to the bare minimum that will compile and still exhibit the problem. You can download it here:
Example project
Note that I took out lots of code, nearly all classes are gone, which results in a lot of warnings (not errors) for nonexistent classes referenced from the xib. But that doesn't matter, the code still compiles and runs just fine with the iOS 9 SDK. After compiling with the iOS 10 sdk, however, it crashes both in the simulator and on devices running iOS 9.
You can work around the problem by changing "#if 0" into "#if 1" in the file "HackForUnrecognizedSelectorInIOS10.m". This adds a category defining the missing selectors for UIColor. But obviously you can't add that to shipping code, it's just a temporary stopgap measure to continue developing.
I filed a bug report (28153870). But if anyone has any more information on how to avoid this problem without ugly hacks, any information is welcome.
Thanks
Michel Colman
When I try to compile and run my project with the same configuration (XCode 8 beta 6, iOS 10 SDK), I encountered a similar issue, except that my error message was:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIDeviceRGBColor length]: unrecognized selector sent to instance 0x600000479280'
And I noticed that this issue only occurs when the view is init by using interface files, i.e. Xib and Nib. I solved this issue by:
Open your interface file, in the right panel, navigate to the File Inspector tab.
Change the attribute highlighted to "iOS 7.0 and Later" (or whatever iOS version later)
Then compile and run your project again, this should fix your issue, though I am not sure about the reason behind this. I tried the same with your sample project and it solves the issue too.
In my case, I needed to change the project deployment target to 8.0 in the product general settings. Thanks to the hint from the accepted answer!

iOS crash 'failed to generate newParagraphStyle'

After I add a library (a internal common library) to my project I received the following crash:
*** Assertion failure in -[_UICascadingTextStorage setTextAlignment:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3505.16/TextSystem/_UICascadingTextStorage.m:270
Project[784:18448] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'failed to generate newParagraphStyle'
I can't find what are the reasons for the type of crash or what I did wrong for this.
Note: I added the Libray but I haven't yet used any features from library.
Can anyone help me?
The library may call +initialize or +load or do some general swizzling/overriding of Apple classes and it can mess something up, e.g. in a new iOS version, if APIs changed.
If you have the src for the library, look for those things.
Also create an exception breakpoint, maybe it will point you to the problem in code.

Today Extension Crashes before launching on iOS 8.1.2

I've been making a today extension that downloads articles from a feed and display the latest ones.
The whole thing worked fine on iOS 8, still worked on iOS 8.1, then came iOS 8.1.2 and we started having complaints about the today extension not working anymore.
I tried debugging on iOS 8.1.2 devices, and before the extension even launch, it crashes with this error :
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: <__NSConcreteUUID 0x174027280> 5AFB07AB-5DCD-46FE-8D07-44DE0F3789F2)'
I have read this post about frequent bugs happening when developing a today extension : http://www.atomicbird.com/blog/ios-app-extension-tip
In his post, Tom Harrington says :
In iOS 8 (and other recent versions), enabling modules in Xcode's build settings means you don't need to explicitly list all the frameworks you want to use. They'll be found automatically.
But this isn't the case with NotificationCenter.framework, which Today extensions use. If you remove that from the build settings, you won't get any build warnings or errors. But when you try to load the extension, you'll get an exception from libextension.dylib and your extension won't load. The exception message is not enlightening:
2014-08-16 12:06:53.793 TodayTestExtension[41313:6111763] * Terminating
app due to uncaught exception 'NSInvalidArgumentException', reason: '*
setObjectForKey: object cannot be nil (key: <__NSConcreteUUID
0x7fd729422390> ED3B42F8-66CD-4CB0-BCD5-F3DBA6F34DB5)'
If you're doing a today extension, just leave that framework in the build settings. It shouldn't need to be there, but it does.
My extension does include NotificationCenter.framework in its build settings, but I suspect my problem might be similar in some way.
Anyone faced a similar problem? Any idea how to solve it?
This error also occurs if you use NSExtensionPrincipalClass inside "Info.plist" in order to define a base class (instead of using a storyboard) with the name of a ViewController which does not exist.
When using Swift, make sure to prefix the class with the module name (usually the name of the target) like "Module.MyViewController".
Eventually I tried to remove NotificationCenter.framework from my target and put it back, cleaned the project, and it's now working again. I guess the framework wasn't properly linked after all, though I could see it on my target with xcode. Also, I can't figure out why it did work, then stopped working with the arrival of 8.1.2.
I fixed this issue by adding the #objc attribute to the Swift class.
#objc(NotificationViewController)
class NotificationViewController: UIViewController, UNNotificationContentExtension {
...
}
Just experienced the same issue. For me, it was "Main Interface" property in "General settings" of the Keyboard target. It was blank, and i set it to my storyboard file and now it works like a charm.

Getting an error from the Stanford iOS Class, but my code seems identical

I believe I did what the instructor did verbatim, but my app (it's a simple app) won't work and errors out if I press a button.
I click run, and it builds, but when I click a button in the iOS simulator the app crashes and brings me back to Xcode with an error.
I don't know what I did wrong. It brings me to the main.m file when we didn't even deal with that in the Stanford guide (maybe it has to do with the fact that the Stanford guide uses iOS 5.0 and I'm on 5.1?).
Here's the project if anyone wants to take a lot at it. I'm just really confused.
http://cl.ly/212A3q3J1m1F1y3A041A
(Also, did I just need to include the xcodeproject file, or was I right in including the whole project folder in a zip file?)
It looks like you have your buttons linked to a selector called digitedPressed:
They also appear to correctly be linked to digitPressed. Just remove the references to digitedPressed. (Right click the Calculator View Controller in your storyboard)
Don't forget to check the XCode debugger! This is the error the XCode debugger showed me:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CalculatorViewController digitedPressed:]: unrecognized selector sent to instance 0x9129cc0'

Resources