title: React Native(RCT_REMAP_METHOD) : How to export a method with a parameter and return value?
body: <p>I'm trying to use gRPC at React Native.
  First, I was able to setup my gRPC module with Objective-C.
  Next, I made a native module for that gRPC module.</p>
  
  <p>The gRPC module is quite simple.</p>
  
  <pre><code>rpc CheckEmail(EmailCheckRequest) returns (EmailCheckResponse) {}
  
  message EmailCheckRequest {
      string email = 1;
  }
  
  message EmailCheckResponse {
      common.RetCode ret = 1; 
  }
  </code></pre>
  
  <p>As you can see, there is one input parameter(email address) and returns a "Return Code".</p>
  
  <p>I checked how to make a native module at <a href="https://facebook.github.io/react-native/docs/native-modules-ios.html" rel="nofollow noreferrer">https://facebook.github.io/react-native/docs/native-modules-ios.html</a> and it shows how to make a module with a parameter or a module with a return value, but it does not explain how to make one with both.</p>
  
  <p>Here are the examples.</p>
  
  <p>Module with a parameter</p>
  
  <pre><code>RCT_EXPORT_METHOD(addEvent:(NSString *)name)
  {
    RCTLogInfo(@"Pretending to create an event %@", name);
  }
  </code></pre>
  
  <p>Module with a return value(Actually, with Promise)</p>
  
  <pre><code>RCT_REMAP_METHOD(findEvents,
                   findEventsWithResolver:(RCTPromiseResolveBlock)resolve
                   rejecter:(RCTPromiseRejectBlock)reject)
  {
    NSArray *events = ...
    if (events) {
      resolve(events);
   } else {
      NSError *error = ...
      reject(@"no_events", @"There were no events", error);
    }
  }
  </code></pre>
  
  <p>Anyway, based on this, I made my own code like this.</p>
  
  <pre><code>RCT_REMAP_METHOD(checkEmail: (NSString *)email, resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
  {
      /* ... */
  }
  </code></pre>
  
  <p>And the react-native side javascript code is like this.
      var NetworkService = NativeModules.NetworkService;
      var ret = NetworkService.checkEmail('spike@merong.com');</p>
  
  <p>There was no compile error, but while running the app, XCode returns this runtime error at RCT_REMAP_METHOD line
  "com.facebook.React.JavaScript (11):EXC_BAD_ACCESS(code=1, address=0x88)</p>
  
  <p>It looks like there is something wrong with RCT_REMAP_METHOD macro, but don't know Objective-C details and don't know how to use marco.</p>
  
  <p>If there is someone who knows how to use RCT_REMAP_METHOD macro to export a module with a parameter and a return value or if there is something wrong with my code, please let me know.</p>
  
  <p><strong>Additional Finding</strong>
  I followed the definition of RCT_REMAP_METHOD and it seems that it is okay to use RCT_EXPORT_METHOD instead, because EXPORT is redefinition of REMAP and there is an example of Promises with EXPORT, but not sure whether it is the right way to do this.</p>
  
  <pre><code>* ## Promises
   *
   * Bridge modules can also define methods that are exported to JavaScript as
   * methods that return a Promise, and are compatible with JS async functions.
   *
   * Declare the last two parameters of your native method to be a resolver block
   * and a rejecter block. The resolver block must precede the rejecter block.
   *
   * For example:
   *
   * RCT_EXPORT_METHOD(doSomethingAsync:(NSString *)aString
   *                           resolver:(RCTPromiseResolveBlock)resolve
   *                           rejecter:(RCTPromiseRejectBlock)reject
   * { ... }
   *
   * Calling `NativeModules.ModuleName.doSomethingAsync(aString)` from
   * JavaScript will return a promise that is resolved or rejected when your
   * native method implementation calls the respective block.
   *
   */
  </code></pre>