项目作者: Traviskn

项目描述 :
UUID generator for React Native utilizing native iOS and Android UUID classes
高级语言: Objective-C
项目地址: git://github.com/Traviskn/react-native-uuid-generator.git
创建时间: 2016-08-14T03:47:53Z
项目社区:https://github.com/Traviskn/react-native-uuid-generator

开源协议:MIT License

下载


react-native-uuid-generator

npm version downloads

A simple wrapper around the native iOS and Android UUID classes.
Exposes a single method, getRandomUUID.

Example App Screen Capture

Getting started

$ npm install react-native-uuid-generator --save

$ react-native link react-native-uuid-generator

Usage

This library supports both callback and promise interfaces.

  1. import UUIDGenerator from 'react-native-uuid-generator';
  2. // Callback interface
  3. UUIDGenerator.getRandomUUID((uuid) => {
  4. console.log(uuid);
  5. });
  6. // => "42A8A87A-F71C-446B-B81D-0CD16A709625"
  7. // Promise interface
  8. UUIDGenerator.getRandomUUID().then((uuid) => {
  9. console.log(uuid);
  10. });
  11. // => "BD6120BD-3612-4D56-8957-99F5D6F02C52"

Manual installation

If the react-native link command doesn’t work, you can also install
the native components of this library manually.

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-uuid-generator and add RNUUIDGenerator.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNUUIDGenerator.a to your project’s Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<

Android

  1. Open up android/app/src/main/java/[...]/MainApplication.java
    • Add import io.github.traviskn.rnuuidgenerator.RNUUIDGeneratorPackage; to the imports at the top of the file
    • Add new RNUUIDGeneratorPackage() to the list returned by the getPackages() method
  2. Append the following lines to android/settings.gradle:
    1. include ':react-native-uuid-generator'
    2. project(':react-native-uuid-generator').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-uuid-generator/android')
  3. Insert the following lines inside the dependencies block in android/app/build.gradle:
    1. compile project(':react-native-uuid-generator')

Upgrading

See the changelog for instructions on upgrading to the latest version.

Example

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.

  1. git clone https://github.com/Traviskn/react-native-uuid-generator.git
  2. cd react-native-uuid-generator/example
  3. npm install

Use react-native run-ios or react-native run-android to run the example.