├── .gitignore ├── DeviceUUID.ios.js ├── LICENSE ├── RCTDeviceUUID.h ├── RCTDeviceUUID.m ├── RCTDeviceUUID.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── README.md └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io 2 | 3 | ### Xcode ### 4 | build/ 5 | *.pbxuser 6 | !default.pbxuser 7 | *.mode1v3 8 | !default.mode1v3 9 | *.mode2v3 10 | !default.mode2v3 11 | *.perspectivev3 12 | !default.perspectivev3 13 | xcuserdata 14 | *.xccheckout 15 | *.moved-aside 16 | DerivedData 17 | *.xcuserstate 18 | 19 | 20 | ### OSX ### 21 | .DS_Store 22 | .AppleDouble 23 | .LSOverride 24 | 25 | # Icon must end with two \r 26 | Icon 27 | 28 | # Thumbnails 29 | ._* 30 | 31 | # Files that might appear in the root of a volume 32 | .DocumentRevisions-V100 33 | .fseventsd 34 | .Spotlight-V100 35 | .TemporaryItems 36 | .Trashes 37 | .VolumeIcon.icns 38 | 39 | # Directories potentially created on remote AFP share 40 | .AppleDB 41 | .AppleDesktop 42 | Network Trash Folder 43 | Temporary Items 44 | .apdisk 45 | 46 | 47 | ### Node ### 48 | # Logs 49 | logs 50 | *.log 51 | 52 | # Dependency directory 53 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 54 | node_modules 55 | -------------------------------------------------------------------------------- /DeviceUUID.ios.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var DeviceUUID = require('react-native').NativeModules.DeviceUUID; 4 | 5 | /** 6 | * High-level docs for the Sample iOS API can be written here. 7 | */ 8 | 9 | module.exports = { 10 | getUUID() { 11 | return new Promise((resolve, reject) => { 12 | DeviceUUID.getUUID((error, uuid) => { 13 | if (error) { 14 | console.log("Got error when trying to get uuid from Native side"); 15 | reject(error); 16 | } else { 17 | resolve(uuid[0]); 18 | } 19 | }); 20 | }); 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Chih-Wei (Bert) Chang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /RCTDeviceUUID.h: -------------------------------------------------------------------------------- 1 | // 2 | // RCTDeviceUUID.h 3 | // RCTDeviceUUID 4 | // 5 | // Created by Johannes Lumpe on 12/04/15. 6 | // Copyright (c) 2015 Johannes Lumpe. All rights reserved. 7 | // 8 | 9 | #import "RCTBridgeModule.h" 10 | #import "RCTLog.h" 11 | 12 | @interface RCTDeviceUUID : NSObject 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /RCTDeviceUUID.m: -------------------------------------------------------------------------------- 1 | // 2 | // RCTDeviceUUID.m 3 | // RCTDeviceUUID 4 | // 5 | // Created by Johannes Lumpe on 12/04/15. 6 | // Copyright (c) 2015 Johannes Lumpe. All rights reserved. 7 | // 8 | 9 | #import "RCTDeviceUUID.h" 10 | 11 | @implementation RCTDeviceUUID 12 | 13 | @synthesize bridge = _bridge; 14 | 15 | RCT_EXPORT_MODULE(); 16 | 17 | RCT_EXPORT_METHOD(getUUID:(RCTResponseSenderBlock)callback) 18 | { 19 | NSUUID *deviceId = [UIDevice currentDevice].identifierForVendor; 20 | 21 | RCTLogInfo(@"Pretending to create an event"); 22 | callback(@[[NSNull null], [NSArray arrayWithObjects: [deviceId UUIDString], nil]]); 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /RCTDeviceUUID.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 088AACF11B312E270044938E /* RCTDeviceUUID.m in Sources */ = {isa = PBXBuildFile; fileRef = F1E59BDE1ADD662800ACA28A /* RCTDeviceUUID.m */; }; 11 | /* End PBXBuildFile section */ 12 | 13 | /* Begin PBXCopyFilesBuildPhase section */ 14 | F12AFB991ADAF8F800E0535D /* CopyFiles */ = { 15 | isa = PBXCopyFilesBuildPhase; 16 | buildActionMask = 2147483647; 17 | dstPath = "include/$(PRODUCT_NAME)"; 18 | dstSubfolderSpec = 16; 19 | files = ( 20 | ); 21 | runOnlyForDeploymentPostprocessing = 0; 22 | }; 23 | /* End PBXCopyFilesBuildPhase section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | F12AFB9B1ADAF8F800E0535D /* libRCTDeviceUUID.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTDeviceUUID.a; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | F1E59BDD1ADD662800ACA28A /* RCTDeviceUUID.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTDeviceUUID.h; sourceTree = ""; }; 28 | F1E59BDE1ADD662800ACA28A /* RCTDeviceUUID.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTDeviceUUID.m; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | F12AFB981ADAF8F800E0535D /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | F12AFB921ADAF8F800E0535D = { 43 | isa = PBXGroup; 44 | children = ( 45 | F1E59BDD1ADD662800ACA28A /* RCTDeviceUUID.h */, 46 | F1E59BDE1ADD662800ACA28A /* RCTDeviceUUID.m */, 47 | F12AFB9C1ADAF8F800E0535D /* Products */, 48 | ); 49 | sourceTree = ""; 50 | }; 51 | F12AFB9C1ADAF8F800E0535D /* Products */ = { 52 | isa = PBXGroup; 53 | children = ( 54 | F12AFB9B1ADAF8F800E0535D /* libRCTDeviceUUID.a */, 55 | ); 56 | name = Products; 57 | sourceTree = ""; 58 | }; 59 | /* End PBXGroup section */ 60 | 61 | /* Begin PBXNativeTarget section */ 62 | F12AFB9A1ADAF8F800E0535D /* RCTDeviceUUID */ = { 63 | isa = PBXNativeTarget; 64 | buildConfigurationList = F12AFBAF1ADAF8F800E0535D /* Build configuration list for PBXNativeTarget "RCTDeviceUUID" */; 65 | buildPhases = ( 66 | F12AFB971ADAF8F800E0535D /* Sources */, 67 | F12AFB981ADAF8F800E0535D /* Frameworks */, 68 | F12AFB991ADAF8F800E0535D /* CopyFiles */, 69 | ); 70 | buildRules = ( 71 | ); 72 | dependencies = ( 73 | ); 74 | name = RCTDeviceUUID; 75 | productName = RNLocalNotification; 76 | productReference = F12AFB9B1ADAF8F800E0535D /* libRCTDeviceUUID.a */; 77 | productType = "com.apple.product-type.library.static"; 78 | }; 79 | /* End PBXNativeTarget section */ 80 | 81 | /* Begin PBXProject section */ 82 | F12AFB931ADAF8F800E0535D /* Project object */ = { 83 | isa = PBXProject; 84 | attributes = { 85 | LastUpgradeCheck = 0630; 86 | ORGANIZATIONNAME = "Johannes Lumpe"; 87 | TargetAttributes = { 88 | F12AFB9A1ADAF8F800E0535D = { 89 | CreatedOnToolsVersion = 6.3; 90 | }; 91 | }; 92 | }; 93 | buildConfigurationList = F12AFB961ADAF8F800E0535D /* Build configuration list for PBXProject "RCTDeviceUUID" */; 94 | compatibilityVersion = "Xcode 3.2"; 95 | developmentRegion = English; 96 | hasScannedForEncodings = 0; 97 | knownRegions = ( 98 | en, 99 | ); 100 | mainGroup = F12AFB921ADAF8F800E0535D; 101 | productRefGroup = F12AFB9C1ADAF8F800E0535D /* Products */; 102 | projectDirPath = ""; 103 | projectRoot = ""; 104 | targets = ( 105 | F12AFB9A1ADAF8F800E0535D /* RCTDeviceUUID */, 106 | ); 107 | }; 108 | /* End PBXProject section */ 109 | 110 | /* Begin PBXSourcesBuildPhase section */ 111 | F12AFB971ADAF8F800E0535D /* Sources */ = { 112 | isa = PBXSourcesBuildPhase; 113 | buildActionMask = 2147483647; 114 | files = ( 115 | 088AACF11B312E270044938E /* RCTDeviceUUID.m in Sources */, 116 | ); 117 | runOnlyForDeploymentPostprocessing = 0; 118 | }; 119 | /* End PBXSourcesBuildPhase section */ 120 | 121 | /* Begin XCBuildConfiguration section */ 122 | F12AFBAD1ADAF8F800E0535D /* Debug */ = { 123 | isa = XCBuildConfiguration; 124 | buildSettings = { 125 | ALWAYS_SEARCH_USER_PATHS = NO; 126 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 127 | CLANG_CXX_LIBRARY = "libc++"; 128 | CLANG_ENABLE_MODULES = YES; 129 | CLANG_ENABLE_OBJC_ARC = YES; 130 | CLANG_WARN_BOOL_CONVERSION = YES; 131 | CLANG_WARN_CONSTANT_CONVERSION = YES; 132 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 133 | CLANG_WARN_EMPTY_BODY = YES; 134 | CLANG_WARN_ENUM_CONVERSION = YES; 135 | CLANG_WARN_INT_CONVERSION = YES; 136 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 137 | CLANG_WARN_UNREACHABLE_CODE = YES; 138 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 139 | COPY_PHASE_STRIP = NO; 140 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 141 | ENABLE_STRICT_OBJC_MSGSEND = YES; 142 | GCC_C_LANGUAGE_STANDARD = gnu99; 143 | GCC_DYNAMIC_NO_PIC = NO; 144 | GCC_NO_COMMON_BLOCKS = YES; 145 | GCC_OPTIMIZATION_LEVEL = 0; 146 | GCC_PREPROCESSOR_DEFINITIONS = ( 147 | "DEBUG=1", 148 | "$(inherited)", 149 | ); 150 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 151 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 152 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 153 | GCC_WARN_UNDECLARED_SELECTOR = YES; 154 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 155 | GCC_WARN_UNUSED_FUNCTION = YES; 156 | GCC_WARN_UNUSED_VARIABLE = YES; 157 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 158 | MTL_ENABLE_DEBUG_INFO = YES; 159 | ONLY_ACTIVE_ARCH = YES; 160 | SDKROOT = iphoneos; 161 | }; 162 | name = Debug; 163 | }; 164 | F12AFBAE1ADAF8F800E0535D /* Release */ = { 165 | isa = XCBuildConfiguration; 166 | buildSettings = { 167 | ALWAYS_SEARCH_USER_PATHS = NO; 168 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 169 | CLANG_CXX_LIBRARY = "libc++"; 170 | CLANG_ENABLE_MODULES = YES; 171 | CLANG_ENABLE_OBJC_ARC = YES; 172 | CLANG_WARN_BOOL_CONVERSION = YES; 173 | CLANG_WARN_CONSTANT_CONVERSION = YES; 174 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 175 | CLANG_WARN_EMPTY_BODY = YES; 176 | CLANG_WARN_ENUM_CONVERSION = YES; 177 | CLANG_WARN_INT_CONVERSION = YES; 178 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 179 | CLANG_WARN_UNREACHABLE_CODE = YES; 180 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 181 | COPY_PHASE_STRIP = NO; 182 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 183 | ENABLE_NS_ASSERTIONS = NO; 184 | ENABLE_STRICT_OBJC_MSGSEND = YES; 185 | GCC_C_LANGUAGE_STANDARD = gnu99; 186 | GCC_NO_COMMON_BLOCKS = YES; 187 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 188 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 189 | GCC_WARN_UNDECLARED_SELECTOR = YES; 190 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 191 | GCC_WARN_UNUSED_FUNCTION = YES; 192 | GCC_WARN_UNUSED_VARIABLE = YES; 193 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 194 | MTL_ENABLE_DEBUG_INFO = NO; 195 | SDKROOT = iphoneos; 196 | VALIDATE_PRODUCT = YES; 197 | }; 198 | name = Release; 199 | }; 200 | F12AFBB01ADAF8F800E0535D /* Debug */ = { 201 | isa = XCBuildConfiguration; 202 | buildSettings = { 203 | HEADER_SEARCH_PATHS = ( 204 | "$(inherited)", 205 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 206 | "$(SRCROOT)/../../React/**", 207 | "$(SRCROOT)/../react-native/React/**", 208 | "$(SRCROOT)/node_modules/react-native/React/**", 209 | ); 210 | OTHER_LDFLAGS = "-ObjC"; 211 | PRODUCT_NAME = RCTDeviceUUID; 212 | SKIP_INSTALL = YES; 213 | }; 214 | name = Debug; 215 | }; 216 | F12AFBB11ADAF8F800E0535D /* Release */ = { 217 | isa = XCBuildConfiguration; 218 | buildSettings = { 219 | HEADER_SEARCH_PATHS = ( 220 | "$(inherited)", 221 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 222 | "$(SRCROOT)/../../React/**", 223 | "$(SRCROOT)/../react-native/React/**", 224 | "$(SRCROOT)/node_modules/react-native/React/**", 225 | ); 226 | OTHER_LDFLAGS = "-ObjC"; 227 | PRODUCT_NAME = RCTDeviceUUID; 228 | SKIP_INSTALL = YES; 229 | }; 230 | name = Release; 231 | }; 232 | /* End XCBuildConfiguration section */ 233 | 234 | /* Begin XCConfigurationList section */ 235 | F12AFB961ADAF8F800E0535D /* Build configuration list for PBXProject "RCTDeviceUUID" */ = { 236 | isa = XCConfigurationList; 237 | buildConfigurations = ( 238 | F12AFBAD1ADAF8F800E0535D /* Debug */, 239 | F12AFBAE1ADAF8F800E0535D /* Release */, 240 | ); 241 | defaultConfigurationIsVisible = 0; 242 | defaultConfigurationName = Release; 243 | }; 244 | F12AFBAF1ADAF8F800E0535D /* Build configuration list for PBXNativeTarget "RCTDeviceUUID" */ = { 245 | isa = XCConfigurationList; 246 | buildConfigurations = ( 247 | F12AFBB01ADAF8F800E0535D /* Debug */, 248 | F12AFBB11ADAF8F800E0535D /* Release */, 249 | ); 250 | defaultConfigurationIsVisible = 0; 251 | defaultConfigurationName = Release; 252 | }; 253 | /* End XCConfigurationList section */ 254 | }; 255 | rootObject = F12AFB931ADAF8F800E0535D /* Project object */; 256 | } 257 | -------------------------------------------------------------------------------- /RCTDeviceUUID.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | react-native-device-uuid 2 | ========================= 3 | 4 | ## What? 5 | 6 | Allow developer to retrieve iOS's [identifierForVendor](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDevice_Class/index.html#//apple_ref/occ/instp/UIDevice/identifierForVendor) as UUID for React Native Application. 7 | 8 | ## Why? 9 | 10 | Sometimes we need an unique identifier (e.g., when implementing special authentication flow) to identify an "user-device" pair. 11 | However, device token, which is mainly used for push notification, is not suitable in such use case. The reason is that device token **can** and **will change**. 12 | For details, please refers to [Is the device token as unique as the device ID?](http://stackoverflow.com/questions/6927011/is-the-device-token-as-unique-as-the-device-id). 13 | 14 | ### Note: The UUID will change if the app is reinstalled 15 | 16 | "The value in this property remains the same while the app (or another app from the same vendor) is installed on the iOS device. The value changes when the user deletes all of that vendor’s apps from the device and subsequently reinstalls one or more of them. The value can also change when installing test builds using Xcode or when installing an app on a device using ad-hoc distribution. Therefore, if your app stores the value of this property anywhere, you should gracefully handle situations where the identifier changes." - [source: identifierForVendor](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDevice_Class/index.html#//apple_ref/occ/instp/UIDevice/identifierForVendor) 17 | 18 | ## How? 19 | 20 | ### Install 21 | 22 | ```bash 23 | npm install --save react-native-device-uuid 24 | react-native link 25 | ``` 26 | 27 | ### Usage 28 | 29 | ```javascript 30 | var DeviceUUID = require("react-native-device-uuid"); 31 | DeviceUUID.getUUID().then((uuid) => { 32 | console.log(uuid); 33 | }); 34 | ``` 35 | 36 | ## Troubleshooting 37 | 38 | ### DeviceUUID just hangs and does not log the uuid to the console ([#2](https://github.com/lazywei/react-native-device-uuid/issues/2)), thanks to [@irfaan](https://github.com/irfaan) 39 | 40 | 1. In XCode, in the project navigator, right click Libraries 41 | 2. Add Files to [your project's name] 42 | 3. Go to node\_modules 43 | 4. react-native-device-uuid and add the .xcodeproj file 44 | 5. In XCode, in the project navigator, select your project 45 | 6. Add the lib\*.a from the react-native-device-uuid project to your project's Build Phases - Link Binary With Libraries. Select the .a file. 46 | 7. Go to the Build Settings tab. 47 | 8. Make sure 'All' is toggled on (instead of 'Basic'). 48 | 9. Look for Header Search Paths and make sure it contains both `$(SRCROOT)/../react-native/React` and `$(SRCROOT)/../../React` - mark both as recursive. 49 | 50 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-device-uuid", 3 | "version": "1.2.0", 4 | "description": "Get the device UUID for iOS device", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/lazywei/react-native-device-uuid.git" 8 | }, 9 | "main": "DeviceUUID.ios.js", 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "keywords": [ 14 | "javascript", 15 | "reactjs", 16 | "react-native", 17 | "ios" 18 | ], 19 | "author": "Chih-Wei (Bert)", 20 | "license": "MIT" 21 | } 22 | --------------------------------------------------------------------------------