Set up a React Native NFC iOS and Android App

Project Source Code

Get the project source code below, and follow along with the lesson material.

Download Project Source Code

To set up the project on your local machine, please follow the directions provided in the README.md file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.

This lesson preview is part of the The newline Guide to NFCs with React Native course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.

This video is available to students only
Unlock This Course

Get unlimited access to The newline Guide to NFCs with React Native, plus 70+ \newline books, guides and courses with the \newline Pro subscription.

Thumbnail for the \newline course The newline Guide to NFCs with React Native

Hello, let's first head into the terminal to start a new Reanative Skeleton project. MPX Reanative init Tech Countergame. Before we go any further, I'd like to explain some basic concepts here. In the Reanative world, there are actually two approaches to start a new project. One is through Expo COI and another is through Reanative COI. Do you ever wonder when to use which? What is the difference between them? To find out, let's see the explanation on Reanative's official site. As you can see, it's set. If you are new to mobile development, the easiest way to get started is with Expo COI. If you are already familiar with mobile development, you might want to use Rean ative. From the official docs, it seems that the differences between them are whether you are new or already familiar with mobile development. But there is another difference, which is much more important. That is, whether your app depends on third-party libraries with native code in it. What does this mean? In Reanative, there are two kinds of libraries. First one is implemented purely in JavaScript. For example, Reanative Element. Reanative Element is a well-known UI library, which provides lots of useful UI components. Since it is a pure UI library, it probably requires no special platform features, so it might be implemented in PureJS. Well, most of the time, but that's not always true. We can see this from the languages area in GitHub page. This project is 96% JavaScript and 3% CSS. On the other hand, let's see the Reanative NFC Manager. Let's check the language section again. It is made by 55% JavaScript, 33% Java, and 21% Objective-C for iOS. If your project needs any of this library which contains native codes, you have two options. The first is to use Reanative-COI to start your project. So your project will contain native platform code and build environment from day one. This is the approach we will take in this course. Second, use Expo-COI and eject later. Though it's possible, but we won't go any further in this approach. If you are interested, you can visit their website to learn more. It looks like the app has been successfully created so we can move on. Next step is to perform native setup for Android. It is quite easy to do. Actually, all we have to do is to edit "endray app src-man" "endray-manifest. xml". The only required modification is to add another uses permission XML element. This basically tells Android we would like to use NFC. And with this declaration, once we publish our app to Google Play Store, these declared permissions will also be listed on your app's page. Let's take NFC tools for example. As you can see, the NFC permission is listed here. Besides use permission, there is an optional element we can consider to edit. That uses feature element. This element allowed us to control our application, show up. What we should consider is whether NFC functionality is crucial for our app. If so, we should add this element. Otherwise, we should omit the "uses" feature element and check for NFC availability at runtime. And I will show you how to do this in later lessons. Finally, let's visit the official Android doc for a quick recap. As you can see, it mentions both uses permission and uses feature. As we just talked about, besides these two, it also mentions uses SDK element. This one is used to define the minimum SDK version required for our app. However, since most Android devices now are in the version much higher than API 10, so it's fine to omit it. Finally, let's move on to iOS setup. iOS setup is slightly more complex comparing to Android, so bear with me. You need to make sure you have enrolled Apple Developer Program and also create an application identity for your app, because we can only test NFC on real devices. For the bundle ID, we use the reverse domain method. For me, I just put my name here. And for you, please remember to change the middle part. We also need to enable the NFC capabilities. It's here. Then register the app. Then open your project in Xcode. First step, we should change the bundle ID into the one we just created. And then make sure we are in the right Apple Developer team. We should add our NFC capability again. After this step, you should see an entitlement file created in your project. This file is generated by Xcode. At this point, this file should look like this. It should contain a near-field communication tech reader session format, which is an array. Content to elements. The first one is NFC data exchange format. And the second one is NFC tech specific data protocol. Finally, edit your info.p list. Now, you are good to go. [ Silence ]