I am comparing face using azure services in my mobile app. Code given below :
$(document).on("click", "#btnCompareFace", function (evt) {
//GM20200512
$("#loadingFace").show();
$("#btnStaffIn").prop("disabled", true);
$("#btnStaffOut").prop("disabled", true);
var EMP_UNQ_ID = localStorage.getItem("bEMP_UNQ_ID");
var USR_UNQ_ID = localStorage.getItem("USR_UNQ_ID");
var StaffLat = localStorage.getItem("StaffLat");
var StaffLong = localStorage.getItem("StaffLong");
var FaceDetected = localStorage.getItem("FaceDetected");
var uriBase = FaceDetectURL;
var Face2Id = "";
//URL Parameters
var params = {
"returnFaceId": "true",
"returnFaceLandmarks": "false"
};
var ImageData = "data:image/jpeg;base64," + $("#hdnFaceImageData").val();
$.ajax({
async: false,
url: uriBase + "?" + $.param(params),
// Request headers.
beforeSend: function (xhrObj) {
xhrObj.setRequestHeader("Content-Type", "application/octet-stream");
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key", subscriptionKey);
},
type: "POST",
processData: false,
contentType: "application/octet-stream",
// Request body.
data: MakeBLOB(ImageData),
headers: {
"cache-control": "no-cache"
},
})
.done(function (data) {
$("#loadingFace").show();
if (data.length != 0) {
Face2Id = data[0].faceId;
}
})
.fail(function (jqXHR, textStatus, errorThrown) {
// Display error message.
var errorString = (errorThrown === "") ? "Error. " : errorThrown + " (" + jqXHR.status + "): ";
errorString += (jqXHR.responseText === "") ? "" : (jQuery.parseJSON(jqXHR.responseText).message) ?
jQuery.parseJSON(jqXHR.responseText).message : jQuery.parseJSON(jqXHR.responseText).error.message;
$("#loadingFace").hide();
var soc_name = localStorage.getItem("soc_name");
$("#divSocNamealert").html(soc_name);
$("#lblVisitorMsg").html(errorString);
$('#lblVisitorMsg').css("color", "red");
$("#imgTick").hide();
$("#imgCross").show();
$("#tblalertStaff").hide();
activate_page("#visitoralert");
});
if (Face2Id != "" && $("#hdnPersonGroupId").val() != "" && $("#hdnPersonId").val() != "") {
var strFaceData = '{"faceId": ' + '"' + Face2Id + '","personGroupId": ' + '"' + $("#hdnPersonGroupId").val() + '","personId": ' + '"' + $("#hdnPersonId").val() + '"}';
$.ajax({
async: false,
url: "https://southeastasia.api.cognitive.microsoft.com/face/v1.0/verify",
// Request headers.
beforeSend: function (xhrObj) {
xhrObj.setRequestHeader("Content-Type", "application/json");
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key", subscriptionKey);
},
type: "POST",
// Request body.
data: strFaceData,
headers: {
"cache-control": "no-cache"
},
})
.done(function (data1) {
$("#loadingFace").show();
if (data1 != undefined) {
if (data1.isIdentical == true) {
//var strURL = ApiLocation + "/fmaregisterstaffinoutwithlog?VSM_UNQ_ID=" + VSM_UNQ_ID + "&VSA_Status=" + localStorage.getItem("InOut") + "&VSA_ADD_USR_UNQ_ID=" + USR_UNQ_ID + "&VSA_Shift=" + localStorage.getItem("SelectedShift") + "&VSL_UNQ_ID=" + $("#hdnVSL_UNQ_ID").val() + "&VSL_Latitude=" + StaffLat + "&VSL_Longitude=" + StaffLong + "&VSL_FaceDetected=" + FaceDetected;
//$.getJSON(strURL, function (data) {
$.post(ApiLocation + '/LAPRegisterStaffInOutWithLog', { EMP_UNQ_ID: EMP_UNQ_ID, SA_Status: localStorage.getItem("InOut"), SA_ADD_USR_UNQ_ID: USR_UNQ_ID, SA_Shift: localStorage.getItem("SelectedShift"), SL_UNQ_ID: $("#hdnSL_UNQ_ID").val(), SL_Latitude: StaffLat, SL_Longitude: StaffLong, SL_FaceDetected: FaceDetected },
function (data) {
$("#loadingFace").show();
if (data.length > 0) {
localStorage.setItem("InOut", "");
localStorage.setItem("SelectedShift", "");
var soc_name = localStorage.getItem("soc_name");
$("#divSocNamealert").html(soc_name);
$("#lblVisitorMsg").html(data[0].StaffStatus);
$('#lblVisitorMsg').css("color", "green");
$("#lblStaffNamealert").html(localStorage.getItem("bEMP_Name"));
$("#lblStaffIdalert").html(localStorage.getItem("bEMP_EmpCode"));
$("#lblRolealert").html(localStorage.getItem("bStaffRole"));
var CurDate = formatDate();
var sAlertStatus = "";
if (data[0].StaffStatus.includes("IN Time")) {
sAlertStatus = "IN (" + CurDate + ")";
}
else if (data[0].StaffStatus.includes("OUT Time")) {
sAlertStatus = "OUT (" + CurDate + ")";
}
$("#lblCurrentStatusalert").html(sAlertStatus);
$("#imgTick").show();
$("#imgCross").hide();
$("#tblalertStaff").show();
navigator.notification.beep(1);
activate_page("#visitoralert");
$("#loadingFace").hide();
}
});
}
else {
$("#loadingFace").show();
var soc_name = localStorage.getItem("soc_name");
$("#divSocNamealert").html(soc_name);
$("#lblVisitorMsg").html("(13) The face in the clicked photo Does Not Match the saved photo of the staff.");
$('#lblVisitorMsg').css("color", "red");
$("#imgTick").hide();
$("#imgCross").show();
$("#tblalertStaff").hide();
activate_page("#visitoralert");
$("#loadingFace").hide();
}
}
else {
$("#loadingFace").show();
var soc_name = localStorage.getItem("soc_name");
$("#divSocNamealert").html(soc_name);
$("#lblVisitorMsg").html("(14) An Error occurred during face recognition. Please try again.");
$('#lblVisitorMsg').css("color", "red");
$("#imgTick").hide();
$("#imgCross").show();
$("#tblalertStaff").hide();
activate_page("#visitoralert");
$("#loadingFace").hide();
}
$("#loadingFace").hide();
})
.fail(function (jqXHR, textStatus, errorThrown) {
$("#loadingFace").show();
//Display error message.
var errorString = (errorThrown === "") ? "Error. " : errorThrown + " (" + jqXHR.status + "): ";
errorString += (jqXHR.responseText === "") ? "" : (jQuery.parseJSON(jqXHR.responseText).message) ?
jQuery.parseJSON(jqXHR.responseText).message : jQuery.parseJSON(jqXHR.responseText).error.message;
$("#loadingFace").hide();
var soc_name = localStorage.getItem("soc_name");
$("#divSocNamealert").html(soc_name);
$("#lblVisitorMsg").html(errorString);
$('#lblVisitorMsg').css("color", "red");
$("#imgTick").hide();
$("#imgCross").show();
$("#tblalertStaff").hide();
activate_page("#visitoralert");
$("#loadingFace").hide();
});
}
else {
$("#loadingFace").show();
var soc_name = localStorage.getItem("soc_name");
$("#divSocNamealert").html(soc_name);
$("#lblVisitorMsg").html("(15) The clicked photo cannot be used for face recognition. Please try again.");
$('#lblVisitorMsg').css("color", "red");
$("#imgTick").hide();
$("#imgCross").show();
$("#tblalertStaff").hide();
activate_page("#visitoralert");
$("#loadingFace").hide();
}
//End GM20200512
$("#btnStaffIn").prop("disabled", false);
$("#btnStaffOut").prop("disabled", false);
});
$(document).on("click", "#btnalertOk", function (evt) {
//GM20200512
if ($("#btnalertOk").html() != "Turn on location services") {
$("#loading").hide();
$("#lblStaffNamealert").val("");
$("#lblStaffIdalert").html("");
$("#lblStaffNamealert").html("");
$("#lblRolealert").html("");
$("#lblStaffNamealert").html("");
$("#lblCurrentStatusalert").html("");
localStorage.setItem("FaceRec", ""); //GM20200512
localStorage.setItem("StaffLat", "");
localStorage.setItem("StaffLong", "");
activate_page("#homepage");
}
else {
cordova.plugins.diagnostic.switchToLocationSettings();
activate_page("#homepage");
}
//End GM20200512
});
This particular code works on Android, but not on IOS. I think there is some problem with $.ajax call since another call like this is also not working. Please help. Thanks in Advance.