Получение устройства uuid ionic 3? - PullRequest
0 голосов
/ 03 октября 2018

Я пытаюсь получить информацию об устройстве, такую ​​как модель uuid и т. Д., Используя ionic 3. Я использую https://ionicframework.com/docs/native/device/ этот пакет для получения этого, но у меня появляется следующая ошибка.

Мой код: у меня есть встроенный импортустройство в моем приложении module.ts и добавьте в провайдеры.

 App Module.ts
    import { Device } from '@ionic-native/device';

     providers: [
        Device,
        {provide: ErrorHandler, useClass: IonicErrorHandler}
     ]

, где я пытаюсь получить значения.следуя коду

import { Device } from '@ionic-native/device';
    constructor(
        public navCtrl: NavController,
        public navParams: NavParams,
        public alertCtrl: AlertController,
        private authService: AuthService,
        private platform: Platform, 
        private device: Device
    ){}

console.log('Device UUID is: ' + this.device.uuid);

Following Errors:
    > ionic-app-scripts serve --address 0.0.0.0 --port 8101 --livereload-port 35730 --dev-logger-port 53703 --nobrowsertions that are not handled will terminate the Node.js process with a non-zero exit code.[app-scripts] [12:36:11]  ionic-app-scripts 3.1.8[app-scripts] [12:36:11]  watch started ...
[app-scripts] [12:36:11]  build dev started ...[app-scripts] events.js:167[app-scripts]       throw er; // Unhandled 'error' event
[app-scripts]       ^
[app-scripts] Error: listen EADDRINUSE :::53703
[app-scripts]     at Server.setupListenHandle [as _listen2] (net.js:1286:14)
[app-scripts]     at listenInCluster (net.js:1334:12)
[app-scripts]     at Server.listen (net.js:1421:7)
[app-scripts]     at new WebSocketServer (D:\important\important\hbload\node_modules\ws\lib\WebSocketServer.js:77:20)
[app-scripts]     at Object.createNotificationServer (D:\important\important\hbload\node_modules\@ionic\app-scripts\dist\dev-server\notification-server.js:66:15)
[app-scripts]     at D:\important\important\hbload\node_modules\@ionic\app-scripts\dist\serve.js:47:31
[app-scripts]     at process._tickCallback (internal/process/next_tick.js:68:7)
[app-scripts]     at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
[app-scripts]     at startup (internal/bootstrap/node.js:279:19)
[app-scripts]     at bootstrapNodeJSCore (internal/bootstrap/node.js:696:3)
[app-scripts] Emitted 'error' event at:
[app-scripts]     at Server.WebSocketServer._ultron.on (D:\important\important\hbload\node_modules\ws\lib\WebSocketServer.js:85:46)
[app-scripts]     at Server.emit (events.js:182:13)
[app-scripts]     at emitErrorNT (net.js:1313:8)
[app-scripts]     at process._tickCallback (internal/process/next_tick.js:63:19)
[app-scripts]     at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
[app-scripts]     at startup (internal/bootstrap/node.js:279:19)
[app-scripts]     at bootstrapNodeJSCore (internal/bootstrap/node.js:696:3)

[INFO] Looks like @ionic/app-scripts isn't installed in this project.

       This package is required for this command to work properly.

? Install @ionic/app-scripts? Yes
> npm i -D -E @ionic/app-scripts
npm WARN deprecated browserslist@2.11.3: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated hoek@2.16.3: The major version is no longer supported. Please update to 4.x or newer
npm WARN @ionic-native/android-permissions@4.14.0 requires a peer of @ionic-native/core@^4.11.0 but none is installed. You must install peer dependencies yourself.
npm WARN @ionic-native/android-permissions@4.14.0 requires a peer of rxjs@^5.5.11 but none is installed. You must install peer dependencies yourself.
npm WARN @ionic-native/device@4.15.0 requires a peer of @ionic-native/core@^4.11.0 but none is installed. You must install peer dependencies yourself.
npm WARN @ionic-native/device@4.15.0 requires a peer of rxjs@^5.5.11 but none is installed. You must install peer dependencies yourself.
npm WARN @ionic-native/uid@4.14.0 requires a peer of @ionic-native/core@^4.11.0 but none is installed. You must install peer dependencies yourself.
npm WARN @ionic-native/uid@4.14.0 requires a peer of rxjs@^5.5.11 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ @ionic/app-scripts@3.1.8
updated 1 package and audited 3918 packages in 21.49s
found 8 vulnerabilities (3 low, 5 moderate)
  run `npm audit fix` to fix them, or `npm audit` for details
> ionic-app-scripts serve --address 0.0.0.0 --port 8101 --livereload-port 35730 --dev-logger-port 53703 --nobrowser
[app-scripts] [12:36:38]  ionic-app-scripts 3.1.8
[app-scripts] [12:36:38]  watch started ...
[app-scripts] [12:36:38]  build dev started ...
[app-scripts] events.js:167
[app-scripts]       throw er; // Unhandled 'error' event
[app-scripts]       ^
[app-scripts] Error: listen EADDRINUSE :::53703
[app-scripts]     at Server.setupListenHandle [as _listen2] (net.js:1286:14)
[app-scripts]     at listenInCluster (net.js:1334:12)
[app-scripts]     at Server.listen (net.js:1421:7)
[app-scripts]     at new WebSocketServer (D:\important\important\hbload\node_modules\ws\lib\WebSocketServer.js:77:20)
[app-scripts]     at Object.createNotificationServer (D:\important\important\hbload\node_modules\@ionic\app-scripts\dist\dev-server\notification-server.js:66:15)
[app-scripts]     at D:\important\important\hbload\node_modules\@ionic\app-scripts\dist\serve.js:47:31
[app-scripts]     at process._tickCallback (internal/process/next_tick.js:68:7)
[app-scripts]     at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
[app-scripts]     at startup (internal/bootstrap/node.js:279:19)
[app-scripts]     at bootstrapNodeJSCore (internal/bootstrap/node.js:696:3)
[app-scripts] Emitted 'error' event at:
[app-scripts]     at Server.WebSocketServer._ultron.on (D:\important\important\hbload\node_modules\ws\lib\WebSocketServer.js:85:46)
[app-scripts]     at Server.emit (events.js:182:13)
[app-scripts]     at emitErrorNT (net.js:1313:8)
[app-scripts]     at process._tickCallback (internal/process/next_tick.js:63:19)
[app-scripts]     at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
[app-scripts]     at startup (internal/bootstrap/node.js:279:19)
[app-scripts]     at bootstrapNodeJSCore (internal/bootstrap/node.js:696:3)
[ERROR] ionic-app-scripts command not found.

Ответы [ 2 ]

0 голосов
/ 28 января 2019

Установка:

@ ionic-native / core @ ionic-native / device

введите описание ссылки здесь

ionic cordova plugin add cordova-plugin-device
npm install --save @ionic-native/device

Добавить этоПлагин для модуля вашего приложения

 // app.module.ts
import { Device } from '@ionic-native/device';

...

@NgModule({
  ...

  providers: [
    ...
    Device
    ...
  ]
  ...
})
export class AppModule { }

Использование

import { Device } from '@ionic-native/device';

constructor(private device: Device) { }

...

console.log('Device Model is: ' + this.device.model+
  '\n Device UUID is: ' + this.device.uuid+
  '\n Device serial is: ' + this.device.serial+
  '\n Device platform is: ' + this.device.platform+
  '\n Device version is: ' + this.device.version+
  '\n Device manufacturer is: ' + this.device.manufacturer);

Если не запустится, измените "import { Device } from '@ionic-native/device';" для "import { Device } from '@ionic-native/device/ngx';"

И "this.device.uuid" для "Расследовать""

Используйте эти команды для запуска в браузере

    ionic build

    ionic cordova platform add browser

    cordova run browser

И работает!в этих версиях

enter image description here

в браузере

enter image description here

в реальном устройстве

enter image description here

0 голосов
/ 03 октября 2018

Не волнуйтесь.Похоже, вы запускаете ваше приложение по ionic serve --lab, а не на реальном устройстве или эмуляторе.

Вот почему вы получаете сообщение об ошибке.Ваш код в порядке.

Просто попробуйте запустить на эмуляторе или на реальном устройстве.

Если вы работаете на реальном устройстве, вы можете использовать средства отладки USB

и проверить по chrome://inspect/decvices

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...