Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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}`);
```
7 changes: 7 additions & 0 deletions index.android.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var device = require('tns-core-modules/platform/platform');

function getUUID() {
return device ? device.uuid : "";
}

exports.getUUID = getUUID;
4 changes: 4 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@



export function getUUID(): string;
4 changes: 2 additions & 2 deletions index.ios.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <rossen.hristov@telerik.com> (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"
}
2 changes: 1 addition & 1 deletion platforms/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pod 'SSKeychain'
pod 'SAMKeychain', '~> 1.5.3'