UUID generator for React Native utilizing native iOS and Android UUID classes
A simple wrapper around the native iOS and Android UUID classes.
Exposes a single method, getRandomUUID
.
$ npm install react-native-uuid-generator --save
$ react-native link react-native-uuid-generator
This library supports both callback and promise interfaces.
import UUIDGenerator from 'react-native-uuid-generator';
// Callback interface
UUIDGenerator.getRandomUUID((uuid) => {
console.log(uuid);
});
// => "42A8A87A-F71C-446B-B81D-0CD16A709625"
// Promise interface
UUIDGenerator.getRandomUUID().then((uuid) => {
console.log(uuid);
});
// => "BD6120BD-3612-4D56-8957-99F5D6F02C52"
If the react-native link
command doesn’t work, you can also install
the native components of this library manually.
Libraries
➜ Add Files to [your project's name]
node_modules
➜ react-native-uuid-generator
and add RNUUIDGenerator.xcodeproj
libRNUUIDGenerator.a
to your project’s Build Phases
➜ Link Binary With Libraries
Cmd+R
)<android/app/src/main/java/[...]/MainApplication.java
import io.github.traviskn.rnuuidgenerator.RNUUIDGeneratorPackage;
to the imports at the top of the filenew RNUUIDGeneratorPackage()
to the list returned by the getPackages()
methodandroid/settings.gradle
:
include ':react-native-uuid-generator'
project(':react-native-uuid-generator').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-uuid-generator/android')
android/app/build.gradle
:
compile project(':react-native-uuid-generator')
See the changelog for instructions on upgrading to the latest version.
Check out the example app included in the github repo to see the UUID Generator in action!
I assume you already have the react-native-cli installed, as well as the required iOS or Android dependencies.
git clone https://github.com/Traviskn/react-native-uuid-generator.git
cd react-native-uuid-generator/example
npm install
Use react-native run-ios
or react-native run-android
to run the example.