<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: John Rajan</title>
    <description>The latest articles on DEV Community by John Rajan (@johnrajan95908).</description>
    <link>https://dev.to/johnrajan95908</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1226047%2F479abd49-469d-402c-b917-d5b61ff30269.jpg</url>
      <title>DEV Community: John Rajan</title>
      <link>https://dev.to/johnrajan95908</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/johnrajan95908"/>
    <language>en</language>
    <item>
      <title>E-passport Reader</title>
      <dc:creator>John Rajan</dc:creator>
      <pubDate>Mon, 11 Dec 2023 16:53:12 +0000</pubDate>
      <link>https://dev.to/johnrajan95908/e-passport-reader-4f35</link>
      <guid>https://dev.to/johnrajan95908/e-passport-reader-4f35</guid>
      <description>&lt;h2&gt;
  
  
  Hello everyone!
&lt;/h2&gt;

&lt;p&gt;Nice to meet you. &lt;br&gt;
I'm glad to share my experience working on a project that involved reading MRZ data from e-passports using the 'react-native-nfc-passport-reader' module. &lt;br&gt;
In this blog post, I will guide you through the steps to use this module effectively.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is MRZ Data?
&lt;/h2&gt;

&lt;p&gt;MRZ stands for Machine Readable Zone, which is a sequence of characters at the bottom of an e-passport that contains personal information of the passport holder. This information includes the passport holder's name, date of birth, passport number, and expiration date.&lt;/p&gt;
&lt;h2&gt;
  
  
  ✔️Prerequisites
&lt;/h2&gt;
&lt;h2&gt;
  
  
  1.Creating Type Script Template
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;:I recommend to use Method 3.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  Method 1: Using Expo
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-expo-app &lt;span class="nt"&gt;--template&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Method 2: Adding TypeScript
&lt;/h3&gt;
&lt;h4&gt;
  
  
  STEP1:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-D&lt;/span&gt; @tsconfig/react-native @types/jest @types/react @types/react-test-renderer typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  STEP2:
&lt;/h4&gt;

&lt;p&gt;-Create a tsconfig.json and add the following part in root directory&lt;br&gt;
{&lt;br&gt;
  "extends": "@tsconfig/react-native/tsconfig.json"&lt;br&gt;
}&lt;/p&gt;
&lt;h3&gt;
  
  
  Method 3: Using template
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx react-native init MyAwesomeProject &lt;span class="nt"&gt;--template&lt;/span&gt; react-native-template-typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  2.Running your first App
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;:Make sure that you have installed the Android Studio (or only Emulator) and followed &lt;a href="https://reactnative.dev/docs/environment-setup"&gt;React Native - Environment Setup&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once you installed your first template, you can execute your first App by the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#using npm&lt;/span&gt;
npm run start

&lt;span class="c"&gt;#in another terminal&lt;/span&gt;
npm run android
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to install module
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#using npm &lt;/span&gt;
npm i react-native-nfc-passport-reader

&lt;span class="c"&gt;#using yarn&lt;/span&gt;
yarn i react-native-nfc-passport-reader
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ✔️Usage
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;import React, &lt;span class="o"&gt;{&lt;/span&gt; useState &lt;span class="o"&gt;}&lt;/span&gt; from &lt;span class="s1"&gt;'react'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
import &lt;span class="o"&gt;{&lt;/span&gt; View, Button, Text &lt;span class="o"&gt;}&lt;/span&gt; from &lt;span class="s1"&gt;'react-native'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
import NfcCardReader from &lt;span class="s1"&gt;'react-native-nfc-card-reader'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

interface CardDetails &lt;span class="o"&gt;{&lt;/span&gt;
  cardNumber: string | null&lt;span class="p"&gt;;&lt;/span&gt;
  expiryDate: string | null&lt;span class="p"&gt;;&lt;/span&gt;
  cardType: string | null&lt;span class="p"&gt;;&lt;/span&gt;
  firstname: string | null&lt;span class="p"&gt;;&lt;/span&gt;
  surname: string | null&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

const PassportReaderNew &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  const &lt;span class="o"&gt;[&lt;/span&gt;cardDetails, setCardDetails] &lt;span class="o"&gt;=&lt;/span&gt; useState&amp;lt;CardDetails&amp;gt;&lt;span class="o"&gt;({&lt;/span&gt;
    cardNumber: null,
    expiryDate: null,
    cardType: null,
    firstname: null,
    surname: null,
  &lt;span class="o"&gt;})&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  const startScan &lt;span class="o"&gt;=&lt;/span&gt; async &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    try &lt;span class="o"&gt;{&lt;/span&gt;
      const scannedCardDetails &lt;span class="o"&gt;=&lt;/span&gt; await NfcCardReader.startNfc&lt;span class="o"&gt;()&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      console.log&lt;span class="o"&gt;(&lt;/span&gt;scannedCardDetails&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      setCardDetails&lt;span class="o"&gt;(&lt;/span&gt;scannedCardDetails&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt; catch &lt;span class="o"&gt;(&lt;/span&gt;error&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
      console.error&lt;span class="o"&gt;(&lt;/span&gt;error&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;
    &amp;lt;View &lt;span class="nv"&gt;style&lt;/span&gt;&lt;span class="o"&gt;={{&lt;/span&gt; flex: 1, justifyContent: &lt;span class="s1"&gt;'center'&lt;/span&gt;, margin: 20, alignContent: &lt;span class="s1"&gt;'center'&lt;/span&gt; &lt;span class="o"&gt;}}&amp;gt;&lt;/span&gt;
      &amp;lt;Button &lt;span class="nv"&gt;title&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Start NFC Scan!"&lt;/span&gt; &lt;span class="nv"&gt;onPress&lt;/span&gt;&lt;span class="o"&gt;={&lt;/span&gt;startScan&lt;span class="o"&gt;}&amp;gt;&lt;/span&gt;&amp;lt;/Button&amp;gt;
      &amp;lt;Text&amp;gt;&lt;span class="o"&gt;{&lt;/span&gt;cardDetails.cardNumber&lt;span class="o"&gt;}&lt;/span&gt;&amp;lt;/Text&amp;gt;
      &amp;lt;Text&amp;gt;&lt;span class="o"&gt;{&lt;/span&gt;cardDetails.expiryDate&lt;span class="o"&gt;}&lt;/span&gt;&amp;lt;/Text&amp;gt;
      &amp;lt;Text&amp;gt;&lt;span class="o"&gt;{&lt;/span&gt;cardDetails.cardType&lt;span class="o"&gt;}&lt;/span&gt;&amp;lt;/Text&amp;gt;
      &amp;lt;Text&amp;gt;&lt;span class="o"&gt;{&lt;/span&gt;cardDetails.firstname&lt;span class="o"&gt;}&lt;/span&gt;&amp;lt;/Text&amp;gt;
      &amp;lt;Text&amp;gt;&lt;span class="o"&gt;{&lt;/span&gt;cardDetails.surname&lt;span class="o"&gt;}&lt;/span&gt;&amp;lt;/Text&amp;gt;
    &amp;lt;/View&amp;gt;
  &lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;export &lt;/span&gt;default PassportReaderNew&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ✔️Realse App
&lt;/h2&gt;

&lt;h2&gt;
  
  
  STEP1: Keytool install!
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;:Make sure that you have installed keytool&lt;br&gt;
if didn't so, you can follow this- &lt;a href="https://codewithandrea.com/articles/keytool-command-not-found-how-to-fix-windows-macos/"&gt;Keytool install Guide&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  -Install JDK
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html"&gt;Download JDK&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  -Set Environment Variable
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;example: C:\Program Files\Java\jdk-17\bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  STEP2: Perfect Release Guide!(by both the React Native CLI and Android)
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;:Follow this guide!-&lt;a href="https://instamobile.io/android-development/generate-react-native-release-build-android/"&gt;How to Release your App&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  ✔️Error Report
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Error:Could not find a declaration file for module 'react-native-nfc-card-reader'
Solution:
-creat a a file named " index.d.ts "
-adding " declare module 'react-native-nfc-card-reader' "

Error:cann't build your project, undefined SDK Version for 'react-native-nfc-card-reader'
Solution:
-cd node_modules/react-native-nfc-passport-reader/android/build.gradle
-Add the followings:
android {
    compileSdkVersion 33 //your sdk Version
    buildToolsVersion "33.0.0" //your buildTool Version
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ✔️What is Next?
&lt;/h2&gt;

&lt;p&gt;I'd like to post a great way to dive into your first React Native project using TypeScript.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
