Listening for events in react native ios
<p>I cannot for the life of me get an event to properly send from iOS native across the bridge to the react native JS context. On the Objective-C side I want to have a module to easily send events across the bridge. I have called this class EventEmitter and its definition is as follows:</p>

<pre><code>// EventEmitter.h

#import "RCTBridge.h"
#import "RCTEventDispatcher.h"

@interface EventEmitter : NSObject&lt;RCTBridgeModule&gt;

  - (void)emitEvent:(NSString *) eventName withData:(id) eventData;

@end
</code></pre>

<p>and the implementation:</p>

<pre><code>// EventEmitter.m

#import "EventEmitter.h"

@implementation EventEmitter

  RCT_EXPORT_MODULE();

  @synthesize bridge = _bridge;

  - (void)emitEvent:(NSString *) eventName withData:(id) eventData
  {
    NSLog( @"emitting %@ with data %@", eventName, [eventData description] );
    [[_bridge eventDispatcher] sendDeviceEventWithName:eventName body:eventData];
    [[_bridge eventDispatcher] sendAppEventWithName:eventName body:eventData];
  }

@end
</code></pre>

<p>I'm using both sendDeviceEvent and sendAppEvent because I can't get either to work.</p>

<p>On the JS side of things I register to receive these events in the global namespace of one of my modules (so that I know the event subscription will happen before the event is emitted). I register like this:</p>

<pre><code>console.log( 'ADDING EVENT LISTENERS' );
NativeAppEventEmitter.addListener( 'blah', test =&gt; console.log( 'TEST1', test ) );
DeviceEventEmitter.addListener( 'blah', test =&gt; console.log( 'TEST2', test ) );
</code></pre>

<p>In my log statements I get the following:</p>

<pre><code>2016-03-19 12:26:42.501 [trace][tid:com.facebook.React.JavaScript] ADDING EVENT LISTENERS
2016-03-19 12:26:43.613 [name redacted][348:38737] emitting blah with data [data redacted]
</code></pre>

<p>So I can tell that I am sending both an app event and a device event with the tag blah and I have registered to listen for the blah event with both the DeviceEventEmitter and NativeAppEventEmitters but I'm not getting called back in the listeners.</p>

<p>What am I doing wrong?? Thanks for reading!</p>