Skip to content

Commit

Permalink
Fix ✔️
Browse files Browse the repository at this point in the history
  • Loading branch information
floki1250 committed Oct 7, 2024
1 parent edcc381 commit 1e53fb3
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 59 deletions.
59 changes: 0 additions & 59 deletions components/NfcTest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,66 +18,7 @@ if (!cordova) {
status.value = 'cordova available'
console.log('cordova available')
}
document.addEventListener('deviceready', function () {
var permissions = cordova.plugins.permissions;
// Define the permissions you want to request (e.g., CAMERA and LOCATION)
var requiredPermissions = [
permissions.VIBRATE,
permissions.NFC
];
// Function to request permissions
function requestPermissions () {
permissions.requestPermissions(
requiredPermissions,
function (status) {
if (status.hasPermission) {
console.log("All permissions granted!");
// You can now access the features that require these permissions
} else {
console.warn("Some permissions are denied.");
// Handle the case where permissions are denied
}
},
function (error) {
console.error("Permission request error:", error);
}
);
}
// Function to check if permissions are already granted
function checkPermissions () {
permissions.hasPermission(
requiredPermissions[0], // Check one of the permissions
function (status) {
if (status.hasPermission) {
console.log("Permission already granted.");
// Proceed with functionality that requires the permission
} else {
console.log("Permission not granted, requesting...");
requestPermissions();
}
},
function (error) {
console.error("Error checking permission:", error);
}
);
}
function enableNFC () {
nfc.enabled(() => {
console.log('NFC is enabled')
}, error => {
console.log('NFC error: ' + error)
})
}
// Check and request permissions when the app starts
checkPermissions();
enableNFC();
}, false);
// Trigger permission requests when button is clicked
const shareMessage = () => {
const message = [
Expand Down
71 changes: 71 additions & 0 deletions plugins/cordova.client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
export default defineNuxtPlugin((nuxtApp) => {
const cordovaApp = {
// Application Constructor
initialize() {
document.addEventListener(
"deviceready",
function () {
var permissions = cordova.plugins.permissions;

// Define the permissions you want to request (e.g., CAMERA and LOCATION)
var requiredPermissions = [permissions.VIBRATE, permissions.NFC];

// Function to request permissions
function requestPermissions() {
permissions.requestPermissions(
requiredPermissions,
function (status) {
if (status.hasPermission) {
console.log("All permissions granted!");
// You can now access the features that require these permissions
} else {
console.warn("Some permissions are denied.");
// Handle the case where permissions are denied
}
},
function (error) {
console.error("Permission request error:", error);
}
);
}

// Function to check if permissions are already granted
function checkPermissions() {
permissions.hasPermission(
requiredPermissions[0], // Check one of the permissions
function (status) {
if (status.hasPermission) {
console.log("Permission already granted.");
// Proceed with functionality that requires the permission
} else {
console.log("Permission not granted, requesting...");
requestPermissions();
}
},
function (error) {
console.error("Error checking permission:", error);
}
);
}

function enableNFC() {
nfc.enabled(
() => {
console.log("NFC is enabled");
},
(error) => {
console.log("NFC error: " + error);
}
);
}

// Check and request permissions when the app starts
checkPermissions();
enableNFC();
},
false
);
},
};
cordovaApp.initialize();
});

0 comments on commit 1e53fb3

Please sign in to comment.