fixed ios issue for nfc

mohemm-issues-18-jan
haroon amjad 5 years ago
parent b7fc960ce7
commit 1f3fd3d032

@ -1,43 +1,56 @@
<app-generic-header <app-generic-header
showBack="true" showBack="true"
backLink="/home" backLink="/home"
[headerText]="'general,option-attendance' | translate"> [headerText]="'general,option-attendance' | translate"
>
</app-generic-header> </app-generic-header>
<ion-content> <ion-content>
<ion-grid *ngIf="!nfcIOSSuccess" class="attendance-grid"> <ion-grid *ngIf="!nfcIOSSuccess" class="attendance-grid">
<ion-row> <ion-row>
<ion-col size='12' class="nfc-clock"> <ion-col size="12" class="nfc-clock">
<img src="../assets/imgs/nfc_clock.png" /> <img src="../assets/imgs/nfc_clock.png" />
</ion-col> </ion-col>
</ion-row> </ion-row>
<ion-row> <ion-row>
<ion-col padding> <ion-col padding>
<h4>{{'general, select-attendance' | translate}}</h4> <h4>{{ "general, select-attendance" | translate }}</h4>
</ion-col> </ion-col>
</ion-row> </ion-row>
<ion-row padding> <ion-row padding>
<ion-col <ion-col
size='5' size="5"
[ngClass]="{'margin-col': direction === 'en', 'disable-attendance': !serviceEnableNFC }" [ngClass]="{
class='buttonStyle'> 'margin-col': direction === 'en',
'disable-attendance': !serviceEnableNFC
}"
class="buttonStyle"
>
<div class="textAndIcon" (click)="checkNFCStatus('two')"> <div class="textAndIcon" (click)="checkNFCStatus('two')">
<img src="../assets/imgs/nfc_icon.png" /> <img src="../assets/imgs/nfc_icon.png" />
<p>{{'general, nfc-text' | translate}}</p> <p>{{ "general, nfc-text" | translate }}</p>
</div> </div>
</ion-col> </ion-col>
<ion-col <ion-col
[ngClass]="{'margin-col-right': direction === 'ar', 'disable-attendance': !serviceEnableQR }" [ngClass]="{
size='5' offset='1' 'margin-col-right': direction === 'ar',
class='buttonStyle'> 'disable-attendance': !serviceEnableQR
}"
size="5"
offset="1"
class="buttonStyle"
>
<div class="textAndIcon" (click)="startQRCode()"> <div class="textAndIcon" (click)="startQRCode()">
<img src="../assets/imgs/nfc_QR.png" /> <img src="../assets/imgs/nfc_QR.png" />
<p>{{'general, qr-text' | translate}}</p> <p>{{ "general, qr-text" | translate }}</p>
</div> </div>
</ion-col> </ion-col>
</ion-row> </ion-row>
</ion-grid> </ion-grid>
<div *ngIf="nfcIOSSuccess" style="display: block; text-align: center;margin-top: 50%;"> <div
*ngIf="nfcIOSSuccess"
style="display: block; text-align: center; margin-top: 50%"
>
<img src="../assets/imgs/check.png" /> <img src="../assets/imgs/check.png" />
</div> </div>
</ion-content> </ion-content>

@ -1,22 +1,22 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from "@angular/core";
import { NFC } from "@ionic-native/nfc/ngx" import { NFC } from "@ionic-native/nfc/ngx";
import { CommonService } from 'src/app/hmg-common/services/common/common.service'; import { CommonService } from "src/app/hmg-common/services/common/common.service";
import { Platform } from '@ionic/angular'; import { Platform } from "@ionic/angular";
import {AttendScanService} from '../../hmg-common/services/attend-services/attend-scan.service'; import { AttendScanService } from "../../hmg-common/services/attend-services/attend-scan.service";
import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service'; import { TranslatorService } from "src/app/hmg-common/services/translator/translator.service";
import { ModalController } from '@ionic/angular'; import { ModalController } from "@ionic/angular";
import { NfcModalComponent } from '../nfc-modal/nfc-modal.component'; import { NfcModalComponent } from "../nfc-modal/nfc-modal.component";
import { AuthenticatedUser } from '../../hmg-common/services/authentication/models/authenticated-user'; import { AuthenticatedUser } from "../../hmg-common/services/authentication/models/authenticated-user";
import { AuthenticationService } from 'src/app/hmg-common/services/authentication/authentication.service'; import { AuthenticationService } from "src/app/hmg-common/services/authentication/authentication.service";
import { attendanceSwipeScannerRequest } from 'src/app/home/models/attendanceSwipe.Request'; import { attendanceSwipeScannerRequest } from "src/app/home/models/attendanceSwipe.Request";
import { Device } from '@ionic-native/device/ngx'; import { Device } from "@ionic-native/device/ngx";
import { AttendanceService } from 'src/app/home/services/attendance.services'; import { AttendanceService } from "src/app/home/services/attendance.services";
import { Response } from 'src/app/hmg-common/services/models/response'; import { Response } from "src/app/hmg-common/services/models/response";
@Component({ @Component({
selector: 'app-attendance-options', selector: "app-attendance-options",
templateUrl: './attendance-options.component.html', templateUrl: "./attendance-options.component.html",
styleUrls: ['./attendance-options.component.scss'], styleUrls: ["./attendance-options.component.scss"],
}) })
export class AttendanceOptionsComponent implements OnInit { export class AttendanceOptionsComponent implements OnInit {
public location: boolean; public location: boolean;
@ -27,7 +27,7 @@ export class AttendanceOptionsComponent implements OnInit {
public serviceEnableQR = false; public serviceEnableQR = false;
public deviceNFC = false; public deviceNFC = false;
public nfcIOSSuccess = false; public nfcIOSSuccess = false;
constructor( constructor(
private nfc: NFC, private nfc: NFC,
public common: CommonService, public common: CommonService,
@ -37,45 +37,59 @@ export class AttendanceOptionsComponent implements OnInit {
public modalController: ModalController, public modalController: ModalController,
private device: Device, private device: Device,
private attendance_service: AttendanceService private attendance_service: AttendanceService
) { } ) {}
ngOnInit() { ngOnInit() {
this.direction = TranslatorService.getCurrentLanguageName(); this.direction = TranslatorService.getCurrentLanguageName();
this.userData = this.common.sharedService.getSharedData(AuthenticatedUser.SHARED_DATA, false); this.userData = this.common.sharedService.getSharedData(
AuthenticatedUser.SHARED_DATA,
false
);
this.priviligeList = AuthenticationService.servicePrivilage; this.priviligeList = AuthenticationService.servicePrivilage;
this.setServicesPrivilage(); this.setServicesPrivilage();
this.checkNFCStatus('one'); this.checkNFCStatus("one");
} }
async checkNFCStatus(checkValue: string) { async checkNFCStatus(checkValue: string) {
try { try {
let nfcStatus = await this.nfc.enabled(); let nfcStatus = await this.nfc.enabled();
console.log(nfcStatus); console.log("nfc status >>>>>>>>>>" + nfcStatus);
if (nfcStatus === 'NFC_OK') { if (nfcStatus === "NFC_OK") {
this.deviceNFC = true; this.deviceNFC = true;
if (checkValue === 'two') { if (checkValue === "two") {
this.startNFC(); this.startNFC();
} }
} }
if (nfcStatus === null && checkValue === "two") {
this.startNFC();
}
} catch (err) { } catch (err) {
console.log("Error reading tag", err); console.log("Error reading tag", err);
if (err === 'NO_NFC') { if (err === "NO_NFC") {
this.deviceNFC = false; this.deviceNFC = false;
} else if (err === 'NFC_DISABLED') { } else if (err === "NFC_DISABLED") {
this.deviceNFC = true; this.deviceNFC = true;
if (checkValue === 'two') { if (checkValue === "two") {
this.common.presentAlert(this.ts.trPK('general', 'nfc-settings')); this.common.presentAlert(this.ts.trPK("general", "nfc-settings"));
} }
} else if (checkValue === "two") {
this.common.presentAlert(this.ts.trPK("general", "nfc-error"));
} }
} }
} }
public setServicesPrivilage() { public setServicesPrivilage() {
for (const servicePrivilage of AuthenticationService.servicePrivilage) { for (const servicePrivilage of AuthenticationService.servicePrivilage) {
if (servicePrivilage.Previlege && servicePrivilage.ServiceName === 'enableNFC') { if (
servicePrivilage.Previlege &&
servicePrivilage.ServiceName === "enableNFC"
) {
this.serviceEnableNFC = true; this.serviceEnableNFC = true;
} }
if (servicePrivilage.Previlege && servicePrivilage.ServiceName === 'enableQR') { if (
servicePrivilage.Previlege &&
servicePrivilage.ServiceName === "enableQR"
) {
this.serviceEnableQR = true; this.serviceEnableQR = true;
} }
} }
@ -88,22 +102,22 @@ export class AttendanceOptionsComponent implements OnInit {
const serialNumber = this.nfc.bytesToHexString(tag.id); const serialNumber = this.nfc.bytesToHexString(tag.id);
this.swipeAttendanceNFC(serialNumber); this.swipeAttendanceNFC(serialNumber);
} catch (err) { } catch (err) {
this.common.presentAlert(this.ts.trPK('general', 'nfc-error')); this.common.presentAlert(this.ts.trPK("general", "nfc-error"));
console.log("Error reading tag", err); console.log("Error reading tag", err);
} }
} }
public async nfcModal() { public async nfcModal() {
const modal = await this.modalController.create({ const modal = await this.modalController.create({
component: NfcModalComponent, component: NfcModalComponent,
showBackdrop: true, showBackdrop: true,
backdropDismiss: true backdropDismiss: true,
}); });
modal.cssClass = 'nfc-modal'; modal.cssClass = "nfc-modal";
await modal.present(); await modal.present();
} }
public swipeAttendanceNFC (nfcSerialCode: any) { public swipeAttendanceNFC(nfcSerialCode: any) {
const request: attendanceSwipeScannerRequest = new attendanceSwipeScannerRequest(); const request: attendanceSwipeScannerRequest = new attendanceSwipeScannerRequest();
request.PointType = 2; request.PointType = 2;
request.Latitude = 0; request.Latitude = 0;
@ -112,9 +126,11 @@ export class AttendanceOptionsComponent implements OnInit {
request.NFCValue = nfcSerialCode; request.NFCValue = nfcSerialCode;
request.UID = this.device.uuid; request.UID = this.device.uuid;
request.UserName = this.userData.EMPLOYEE_NUMBER; request.UserName = this.userData.EMPLOYEE_NUMBER;
this.attendance_service.attendanceSwipeScanner(request, () => { this.attendance_service
console.log('Error inside in swipe attendance'); .attendanceSwipeScanner(request, () => {
}).subscribe((result: Response) => { console.log("Error inside in swipe attendance");
})
.subscribe((result: Response) => {
if (this.common.validResponse(result)) { if (this.common.validResponse(result)) {
this.nfcIOSSuccess = true; this.nfcIOSSuccess = true;
setTimeout(() => { setTimeout(() => {
@ -125,17 +141,16 @@ export class AttendanceOptionsComponent implements OnInit {
} }
public startNFC() { public startNFC() {
const isAndroid = this.platform.is('android'); const isAndroid = this.platform.is("android");
const isIOS = this.platform.is('ios'); const isIOS = this.platform.is("ios");
if (isAndroid) { if (isAndroid) {
this.nfcModal(); this.nfcModal();
} else if (isIOS) { } else if (isIOS) {
this.startIOSNfc(); this.startIOSNfc();
} }
} }
public startQRCode() { public startQRCode() {
this.attendScanService.getDeviceLocation(); this.attendScanService.getDeviceLocation();
} }
} }

Loading…
Cancel
Save