-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCardReader.ts
45 lines (39 loc) · 1.01 KB
/
CardReader.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import {NativeModules} from 'react-native';
const {NFCCardReader} = NativeModules;
const gotoSettings = async () => {
try {
const setting = await NFCCardReader.gotoSettings();
return setting;
} catch (error) {
console.error('Error checking NFC availability:', error);
return false;
}
};
const isEnabled = async () => {
try {
const enabled = await NFCCardReader.isEnabled();
return enabled;
} catch (error) {
console.error('Error checking NFC availability:', error);
return false;
}
};
const isSupported = async () => {
try {
const supported = await NFCCardReader.isSupported();
return supported;
} catch (error) {
console.error('Your mobile does not support NFC:', error);
return false;
}
};
const readNFC = async () => {
try {
const result = await NFCCardReader.readNFC();
return JSON.parse(result);
} catch (error) {
console.error('Error reading NFC:', error);
return false;
}
};
export {isEnabled, isSupported, gotoSettings, readNFC};