Skip to main content
iOS native modules allow you to write Objective-C or Swift code that can be called from your React Native JavaScript code.

Basic Module Structure

An iOS native module consists of:
  1. A class implementing the RCTBridgeModule protocol
  2. Methods exported with RCT_EXPORT_METHOD macro
  3. Module registration with RCT_EXPORT_MODULE macro

Creating Your First Module

Exporting Methods

Basic Method Export

Use the RCT_EXPORT_METHOD macro to expose methods to JavaScript:

Method Parameters

Supported parameter types:

Custom Method Names

Use RCT_REMAP_METHOD to specify a different JavaScript name:

Using Callbacks

Single Callback

From JavaScript:

Error and Success Callbacks

Using Promises

Promises are the preferred way to handle async operations:
From JavaScript:

Exporting Constants

Export constants that are available synchronously in JavaScript:
From JavaScript:

Module Initialization

Controlling Initialization

Accessing React Bridge

Threading

Running on Main Queue

By default, methods run on a background queue. To run on the main queue:

Custom Method Queue

Swift Modules

Complete Swift Example

Example: Alert Manager Module

Here’s a real-world example based on React Native’s source code (packages/react-native/React/CoreModules/RCTAlertManager.mm:43-48):

Lifecycle Methods

Module Cleanup

Batch Completion

Accessing iOS APIs

Getting Current View Controller

Working with UIKit

Best Practices

  • Always handle errors and reject promises appropriately
  • Use meaningful error codes and messages
  • Run UI operations on the main queue
  • Clean up resources in invalidate
  • Use promises for async operations
  • Document your module’s API
  • Mark Swift classes with @objc for React Native compatibility
  • Use requiresMainQueueSetup to control initialization threading
  • Validate input parameters before processing