|
| 1 | +import { Injectable } from '@angular/core'; |
| 2 | +import { Plugin, CordovaProperty, IonicNativePlugin } from '@ionic-native/core'; |
| 3 | + |
| 4 | +/** |
| 5 | + * @name Uid |
| 6 | + * @description |
| 7 | + * Get unique identifiers: UUID, IMEI, IMSI, ICCID and MAC. |
| 8 | + * |
| 9 | + * @usage |
| 10 | + * ```typescript |
| 11 | + * import { Uid } from '@ionic-native/uid'; |
| 12 | + * import { AndroidPermissions } from '@ionic-native/android-permissions'; |
| 13 | + * |
| 14 | + * constructor(private uid: Uid, private androidPermissions: AndroidPermissions) { } |
| 15 | + * |
| 16 | + * |
| 17 | + * async getImei() { |
| 18 | + * const { hasPermission } = await this.androidPermissions.checkPermission( |
| 19 | + * this.androidPermissions.PERMISSION.READ_PHONE_STATE |
| 20 | + * ); |
| 21 | + * |
| 22 | + * if (!hasPermission) { |
| 23 | + * const result = await this.androidPermissions.requestPermission( |
| 24 | + * this.androidPermissions.PERMISSION.READ_PHONE_STATE |
| 25 | + * ); |
| 26 | + * |
| 27 | + * if (!result.hasPermission) { |
| 28 | + * throw new Error('Permissions required'); |
| 29 | + * } |
| 30 | + * |
| 31 | + * // ok, a user gave us permission, we can get him identifiers after restart app |
| 32 | + * return; |
| 33 | + * } |
| 34 | + * |
| 35 | + * return this.uid.IMEI |
| 36 | + * } |
| 37 | + * ``` |
| 38 | + */ |
| 39 | +@Plugin({ |
| 40 | + pluginName: 'Uid', |
| 41 | + plugin: 'https://github.com/hygieiasoft/cordova-plugin-uid', |
| 42 | + pluginRef: 'cordova.plugins.uid', |
| 43 | + repo: 'https://github.com/hygieiasoft/cordova-plugin-uid', |
| 44 | + platforms: ['Android'] |
| 45 | +}) |
| 46 | +@Injectable() |
| 47 | +export class Uid extends IonicNativePlugin { |
| 48 | + |
| 49 | + /** Get the device Universally Unique Identifier (UUID). */ |
| 50 | + @CordovaProperty |
| 51 | + UUID: string; |
| 52 | + |
| 53 | + /** Get the device International Mobile Station Equipment Identity (IMEI). */ |
| 54 | + @CordovaProperty |
| 55 | + IMEI: string; |
| 56 | + |
| 57 | + /** Get the device International mobile Subscriber Identity (IMSI). */ |
| 58 | + @CordovaProperty |
| 59 | + IMSI: string; |
| 60 | + |
| 61 | + /** Get the sim Integrated Circuit Card Identifier (ICCID). */ |
| 62 | + @CordovaProperty |
| 63 | + ICCID: string; |
| 64 | + |
| 65 | + /** Get the Media Access Control address (MAC). */ |
| 66 | + @CordovaProperty |
| 67 | + MAC: string; |
| 68 | + |
| 69 | +} |
0 commit comments