diff --git a/README.md b/README.md index b19b250..487e57c 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,33 @@ -# NativeScript iOS UUID +# NativeScript UUID -This is a plugin for iOS that allows you to get a UUID (Universal Unique Identifier) for a device. +This is a plugin for Nativescript that allows you to get a UUID (Universal Unique Identifier) for a device. -Inspired from [`StackOverflow: How to preserve identifierForVendor in ios after uninstalling ios app on device?`] (http://stackoverflow.com/questions/21878560/how-to-preserve-identifierforvendor-in-ios-after-uninstalling-ios-app-on-device). +Inspired from [`StackOverflow: How to preserve identifierForVendor in ios after uninstalling ios app on device?`](http://stackoverflow.com/questions/21878560/how-to-preserve-identifierforvendor-in-ios-after-uninstalling-ios-app-on-device). -Uses [`SSKeychain Cocoa Pod`](https://cocoapods.org/pods/SSKeychain). +Uses [`SAMKeychain Cocoa Pod`](https://cocoapods.org/pods/SAMKeychain). ## Installation -`tns plugin add nativescript-ios-uuid` + +Run the following command from the root of your project: + +``` +tns plugin add nativescript-uuid +``` ## Usage + +#### JavaScript +```js + const nsUuid = require("nativescript-uuid"); + + const uuid = nsUuid.getUUID(); + console.log(`The device UUID is ${uuid}`); ``` -var plugin = require("nativescript-ios-uuid"); -var uuid = plugin.getUUID(); -console.log("The device UUID is " + uuid); + +#### TypeScript +```typescript + import {getUUID} from 'nativescript-uuid'; + + const uuid = getUUID(); + console.log(`The device UUID is ${uuid}`); ``` diff --git a/index.android.js b/index.android.js new file mode 100644 index 0000000..0283f3d --- /dev/null +++ b/index.android.js @@ -0,0 +1,7 @@ +var device = require('tns-core-modules/platform/platform'); + +function getUUID() { + return device ? device.uuid : ""; +} + +exports.getUUID = getUUID; diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..9d78f0a --- /dev/null +++ b/index.d.ts @@ -0,0 +1,4 @@ + + + +export function getUUID(): string; \ No newline at end of file diff --git a/index.ios.js b/index.ios.js index 1b108f8..71f373e 100644 --- a/index.ios.js +++ b/index.ios.js @@ -1,9 +1,9 @@ function getUUID() { var appName = NSBundle.mainBundle.infoDictionary.objectForKey(kCFBundleNameKey); - var strApplicationUUID = SSKeychain.passwordForServiceAccount(appName, "incoding"); + var strApplicationUUID = SAMKeychain.passwordForServiceAccount(appName, "incoding"); if (!strApplicationUUID){ strApplicationUUID = UIDevice.currentDevice.identifierForVendor.UUIDString; - SSKeychain.setPasswordForServiceAccount(strApplicationUUID, appName, "incoding"); + SAMKeychain.setPasswordForServiceAccount(strApplicationUUID, appName, "incoding"); } return strApplicationUUID; diff --git a/package.json b/package.json index 8e7ac0a..43a2f34 100644 --- a/package.json +++ b/package.json @@ -1,26 +1,24 @@ { - "name": "nativescript-ios-uuid", + "name": "nativescript-uuid", "version": "0.0.1", - "description": "A NativeScript plugin for iOS that allows you to get a UUID (Universal Unique Identifier) for a device.", + "description": "A NativeScript plugin that allows you to get a UUID (Universal Unique Identifier) for a device.", "main": "index.js", + "type": "index.d.ts", "nativescript": { - "id": "org.nativescript.iosuuid", + "id": "org.nativescript.uuid", "platforms": { - "ios": "1.3.0" + "ios": "1.3.0", + "android": "1.3.0" } }, "repository": { "type": "git", - "url": "https://github.com/hamorphis/nativescript-ios-uuid.git" + "url": "https://github.com/gdtdpt/nativescript-uuid.git" }, "keywords": [ "NativeScript", - "iOS", "UUID", "Device" ], - "author": "Rossen Hristov (https://github.com/hamorphis)", - "license": "Apache-2.0", - "bugs": "https://github.com/hamorphis/nativescript-ios-uuid/issues", - "homepage": "https://github.com/hamorphis/nativescript-ios-uuid" + "license": "Apache-2.0" } diff --git a/platforms/ios/Podfile b/platforms/ios/Podfile index 749bc13..456d93d 100644 --- a/platforms/ios/Podfile +++ b/platforms/ios/Podfile @@ -1 +1 @@ -pod 'SSKeychain' +pod 'SAMKeychain', '~> 1.5.3'