$ npm install @monoku/react-native-magtek --save
$ react-native link @monoku/react-native-magtek
Add the following lines in your Podfile
pod 'MTSCRA', path: '../node_modules/@monoku/react-native-magtek/ios/Magtek'
pod 'RNMagtek', path: '../node_modules/@monoku/react-native-magtek/ios'
and then run pod install
.
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜@monoku/react-native-magtek
and addRNMagtek.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNMagtek.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)<
import RNMagtek, { RNMagtekEventsEmitter } from '@monoku/react-native-magtek';
# Connect device
RNMagtek.connect((data) => {
const { isDeviceConnected, isDeviceOpened } = data;
if (isDeviceConnected && isDeviceOpened) {
console.log("Card reader is connected and ready!!!");
}
});
# Add listener to check device connection
RNMagtekEventsEmitter.addListener('onDeviceConnectionDidChange', (data) => {
const { isDeviceConnected } = data;
if (!isDeviceConnected) {
console.log("Opps! Device have been disconnected.");
}
});
# Add listener to receive card data
RNMagtekEventsEmitter.addListener(
'onDataReceived',
(data) => {
console.log(data)
// The data object has the following attributes:
// sessionID, deviceSN, deviceKSN, magnePrint, magnePrintStatus,
// track1, track2, track3
}
);
Remember to delete the listener before creating a new one or your transaction will be processed multiple times