├── ios ├── .DS_Store ├── RCTDeviceCheck.h └── RCTDeviceCheck.m ├── index.js ├── package.json ├── README.md └── LICENSE /ios/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aco/react-native-device-check/HEAD/ios/.DS_Store -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 2 | import { NativeModules } from 'react-native'; 3 | 4 | const DeviceCheck = NativeModules.RNDeviceCheck; 5 | 6 | export default DeviceCheck; 7 | -------------------------------------------------------------------------------- /ios/RCTDeviceCheck.h: -------------------------------------------------------------------------------- 1 | // 2 | // RCTDeviceCheck.h 3 | // casa 4 | // 5 | // Created by ac on 30/12/2018. 6 | // Copyright © 2018 Facebook. All rights reserved. 7 | // 8 | 9 | #ifndef RCTDeviceCheck_h 10 | #define RCTDeviceCheck_h 11 | 12 | #import 13 | #import 14 | 15 | @interface RCTDeviceCheck : NSObject 16 | 17 | + (BOOL)deviceCheckCompatibleWithPlatform; 18 | 19 | @end 20 | 21 | #endif /* RCTDeviceCheck_h */ 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-device-check", 3 | "version": "1.0.0", 4 | "description": "Native bridge to the iOS DeviceCheck API", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/cewpur/react-native-device-check.git" 12 | }, 13 | "keywords": [ 14 | "react", 15 | "native", 16 | "device", 17 | "check", 18 | "devicecheck", 19 | "ios" 20 | ], 21 | "author": "cewpur", 22 | "license": "MIT", 23 | "bugs": { 24 | "url": "https://github.com/cewpur/react-native-device-check/issues" 25 | }, 26 | "homepage": "https://github.com/cewpur/react-native-device-check#readme" 27 | } 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-device-check 2 | 📱 Native bridge to the iOS DeviceCheck API 3 | 4 | ## Introduction 5 | DeviceCheck helps identify a particular device (per development account) and authenticate a request's origin. Check out the [Apple Developer Doc](https://developer.apple.com/documentation/devicecheck) for more detail. This module returns the token in base64 ready for serialization. 6 | 7 | The API was introduced in iOS 11 and requires a physical device, running on a lower target or simulator will throw an exception. 8 | 9 | ## Usage 10 | 11 | Async/await: 12 | ```js 13 | getDeviceToken = async () => { 14 | try { 15 | let token = await DeviceCheck.getDeviceToken(); 16 | } catch (error) { 17 | console.log(error); 18 | } 19 | } 20 | ``` 21 | 22 | Promise: 23 | ```js 24 | getDeviceToken() { 25 | DeviceCheck.getDeviceToken().then(token => 26 | // 27 | ).catch(err => 28 | console.log(err) 29 | ); 30 | } 31 | ``` 32 | 33 | ## License 34 | MIT 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 cewpur 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 | -------------------------------------------------------------------------------- /ios/RCTDeviceCheck.m: -------------------------------------------------------------------------------- 1 | // 2 | // RCTDeviceCheck.m 3 | // casa 4 | // 5 | // Created by ac on 30/12/2018. 6 | // Copyright © 2018 Facebook. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #include "RCTDeviceCheck.h" 12 | 13 | typedef void (^FailureHandleBlock)(NSString *errorDescription); // Rejector wrapper - RN does not support multiple callback invocations 14 | 15 | @implementation RCTDeviceCheck 16 | 17 | + (BOOL)deviceCheckCompatibleWithPlatform 18 | { 19 | if (@available(iOS 11.0, *)) { 20 | return DCDevice.currentDevice.isSupported; 21 | } 22 | 23 | return false; 24 | } 25 | 26 | RCT_EXPORT_MODULE(); 27 | 28 | RCT_REMAP_METHOD(getDeviceToken, 29 | resolver:(RCTPromiseResolveBlock)resolve 30 | rejector:(RCTPromiseRejectBlock)reject) 31 | { 32 | FailureHandleBlock failureHandle = ^void(NSString *errorDescription) { 33 | reject(nil, [NSString stringWithFormat:@"%@ (DeviceCheck API unsupported in simulator)", errorDescription], nil); 34 | }; 35 | 36 | if (RCTDeviceCheck.deviceCheckCompatibleWithPlatform) { 37 | 38 | [DCDevice.currentDevice generateTokenWithCompletionHandler:^(NSData * _Nullable token, NSError * _Nullable error) { 39 | if (error) { 40 | failureHandle(error.localizedDescription); 41 | } else if (token.length < 1) { 42 | failureHandle(@"Token creation failure"); 43 | } else { 44 | resolve([token base64EncodedStringWithOptions:0]); 45 | } 46 | }]; 47 | } else { 48 | failureHandle(@"Platform incompatible"); 49 | } 50 | } 51 | 52 | @end 53 | --------------------------------------------------------------------------------