Search code examples
iosobjective-creact-nativejuce

JS errors crash JUCE app


Developing a React Native app that is based on JUCE, using an iOS device for testing, whenever there is a JS error in my code the app crashes and I have to restart from Xcode. The Reload button does not work.

The core of the app is a JUCE application. In Debug mode I get the following exception on JS errors:

exception 'NSInvalidArgumentException', reason: '-[JuceAppStartupDelegate window]: unrecognized selector sent to instance 

I understand that this is because JuceAppStartupDelegate does not have a window property. What I don't know is how to implement a JUCEApplication instance that would respond to the call made by React Native.


Solution

  • So I figured out a solution.

    The React Native code that was causing the crash was in the dismiss method:

    - (void)dismiss
    {
      self.hidden = YES;
      [self resignFirstResponder];
      [RCTSharedApplication().delegate.window makeKeyWindow]; // <-- crash here
    }
    

    I tried simply commenting the offending line out. And it works - I can now use the Reload button after JS errors in my React Native code.

    - (void)dismiss
    {
      self.hidden = YES;
      [self resignFirstResponder];
      //[RCTSharedApplication().delegate.window makeKeyWindow];
    }
    

    EDIT (Jan 2017):

    JUCE has since been updated with a window property on iOS, which resolves this error.