Guest User

Untitled

a guest
Oct 22nd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. import { Component } from '@angular/core';
  2. import { IonicPage, NavController, NavParams } from 'ionic-angular';
  3. import { QRScanner, QRScannerStatus } from '@ionic-native/qr-scanner';
  4.  
  5. @IonicPage()
  6. @Component({
  7. selector: 'page-qrcode',
  8. templateUrl: 'qrcode.html',
  9. })
  10. export class QrcodePage {
  11.  
  12. constructor(
  13. public navCtrl: NavController,
  14. public navParams: NavParams,
  15. private qrScanner: QRScanner){}
  16.  
  17. ionViewDidLoad() {
  18. console.log('ionViewDidLoad QrcodePage');
  19. }
  20.  
  21. this.qrScanner.prepare()
  22. .then((status: QRScannerStatus) => {
  23. if (status.authorized) {
  24. // camera permission was granted
  25.  
  26.  
  27. // start scanning
  28. let scanSub = this.qrScanner.scan().subscribe((text: string) => {
  29. console.log('Scanned something', text);
  30.  
  31. this.qrScanner.hide(); // hide camera preview
  32. scanSub.unsubscribe(); // stop scanning
  33. });
  34.  
  35. // show camera preview
  36. this.qrScanner.show();
  37.  
  38. // wait for user to scan something, then the observable callback will be called
  39.  
  40. } else if (status.denied) {
  41. // camera permission was permanently denied
  42. // you must use QRScanner.openSettings() method to guide the user to the settings page
  43. // then they can grant the permission from there
  44. } else {
  45. // permission was denied, but not permanently. You can ask for permission again at a later time.
  46. }
  47. })
  48. .catch((e: any) => console.log('Error is', e));
  49. }
Add Comment
Please, Sign In to add comment