Home > other >  How to wait until navigator.notification.prompt() input has been given
How to wait until navigator.notification.prompt() input has been given

Time:03-07

I am using a Cordova app to embed a React app. In a certain point, the user connects to the camera and a notification appears when a QR code is detected. I want that the code execution waits until user has entered his/her answer "Yes/No", but I can't get it to work. Notification prompt message works as expected though.

I need it to pause somehow, as in an async function (like prompt would, for instance). How could I pause the code execution until the user has chosen Yes/No in screen? I guess with some async/await but don't see where... I have tried unsuccessfully so far:

let test = null;
let input2 = null;
notification = navigator.notification.prompt("Do you know this QR code?",
     async function(input) {
     input2 = input;
     test = await NotificationFunction(input, Camera_content);
     console.log(test)
     console.log('input2')
     return [test, input2]
     });

let test2= await notification
console.log(test2)
console.log(notification)
console.log(await test)

Thanks a lot in advance!

CodePudding user response:

Maybe you can use something like this:

const promise = new Promise((resolve, reject) => {
  navigator.notification.prompt(
    'Do you know this QR code?',
    async function (input) {
      test = await NotificationFunction(input, Camera_content);
      resolve([test, input]);
    },
  );
});

const [test, input] = await promise

Also maybe this can help https://javascript.info/promisify

  • Related