Hello Friends 👋,
Welcome To Infinitbility! ❤️
This tutorial will help you to detect screen lock ( pin, password, pattern, and fingerprint ) set or not in device, here we will use react-native-device-info ( https://github.com/react-native-device-info/react-native-device-info ) for detection of screen lock.
Introduction
React Native device info provide isPinOrFingerprintSet()
function to detect pin, password, pattern, and fingerprint lock set or not it will return only true
or false
. isPinOrFingerprintSet()
function work in ios, android, and windows platform.
Installation
- Go to your project directory and install
react-native-device-info
package usingnpm
.
1npm install --save react-native-device-info
- Link
react-native-device-info
package if your react native version less then0.63
.
1npx react-native link react-native-device-info
Syntax
DeviceInfo.isPinOrFingerprintSet()
function usages syntax.
1import DeviceInfo from 'react-native-device-info';234DeviceInfo.isPinOrFingerprintSet().then((isPinOrFingerprintSet) => {5 if (!isPinOrFingerprintSet) {6 // ...7 }8});
Example
In Below Example, we will isPinOrFingerprintSet()
value on constant and show in application.
React Native Device Info isPinOrFingerprintSet example
1import React, { Component } from 'react';2import {3 StyleSheet,4 View,5 Text,6 SafeAreaView,7} from 'react-native';8import DeviceInfo from 'react-native-device-info';910class App extends Component {1112 constructor(props) {13 super(props);1415 this.state = {16 passwordLock: false17 }18 }192021 componentDidMount(){22 DeviceInfo.isPinOrFingerprintSet().then((isPinOrFingerprintSet) => {23 if (isPinOrFingerprintSet) {24 this.setState({passwordLock: true});25 }26 });27 }28293031 render() {32 const { passwordLock } = this.state;33 return (34 <SafeAreaView style={{ flex: 1 }}>35 <View style={styles.container}>36 <Text>Device have password lock</Text>37 <Text>{`${passwordLock}`}</Text>38 </View>39 </SafeAreaView>40 );41 }42}4344const styles = StyleSheet.create({45 container: {46 flex: 1,47 alignItems: 'center',48 marginTop: 20,49 backgroundColor: '#ffffff',50 },51});5253export default App;
Output

Thanks for Reading…
Follow me on Twitter
Join our email list and get notified about new content
No worries, I respect your privacy and I will never abuse your email.
Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.