

Test that out by accessing the native module and invoking it’s exported method in JavaScript.įind a place in your application where you would like to add a call to the native module’s createCalendarEvent() method. Test What You Have Built Īt this point you have set up the basic scaffolding for your native module in iOS. For the Google Chrome debugger, React Native runs inside the JS VM in Google Chrome, and communicates asynchronously with the mobile devices via WebSockets. This is because synchronous methods require the JS VM to share memory with the app. Additionally, please note that if you choose to use RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD, your app can no longer use the Google Chrome debugger. NSNumber, NSString, NSArray, NSDictionary).Īt the moment, we do not recommend using synchronous methods, since calling methods synchronously can have strong performance penalties and introduce threading-related bugs to your native modules. This means that the hook can only return nil or JSON values (e.g. The return type of this method must be of object type (id) and should be serializable to JSON. RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD ( getName ) Create a new file called RCTCalendarModule.h Image of creating a custom native module file within the same folder as AppDelegate

The first step is to create our main custom native module header and implementation files. Xcode is built for iOS development, and using it will help you to quickly resolve smaller errors like code syntax. We recommend using Xcode to write your native code. You can find your iOS project here within a React Native app: Image of where you can find your iOS project To get started, open up the iOS project within your React Native application in Xcode.
#HOW TO WRITE C CODE IN XCODE UPGRADE#
Throughout these docs we have added notes around parts of Native Modules that will change in the TurboModules release and how you can best prepare for a smooth upgrade to TurboModules. It will also enable new extensions that weren't possible with the legacy Native Module system. This new system is called TurboModules, and it will help facilitate more efficient type-safe communication between JavaScript and native, without relying on the React Native bridge. The React Native team is currently working on a re-architecture of the Native Module system.

By the end you will be able to call CalendarModule.createCalendarEvent('Dinner Party', 'My House') from JavaScript, invoking a native method that creates a calendar event. In the following guide you will create a native module, CalendarModule, that will allow you to access Apple's calendar APIs from JavaScript. Please start by reading the Native Modules Intro for an intro to what native modules are.
