apache / cordova-ios

Apache Cordova iOS
https://cordova.apache.org/
Apache License 2.0
2.15k stars 986 forks source link

Presenting with JS Alert() dead lock #1120

Open Luo-Kuang opened 2 years ago

Luo-Kuang commented 2 years ago

Bug Report

Problem

What is expected to happen?

alert normaly

What does actually happen?

When I call JS alert in the present controller, the interface will be stuck

Information

[Presentation] Attempt to present <UIAlertController: 0x15201c200> on <MainViewController: 0x151e09ab0> (from <MainViewController: 0x151e09ab0>) whose view is not in the window hierarchy.

Command or Code

index.html
function success(msg){
    console.log(msg)
    alert(msg)
}
function failed(){}
function pl() {
    cordova.exec(success,failed,"testPlugin","method",["msg"]);
}
testPlugin
- (void)method:(CDVInvokedUrlCommand *)command {
    ViewController *tempC = [[ViewController alloc] init];
    [[TestPlugin topViewController] presentViewController:tempC animated:YES completion:nil];
}

when I back to MainViewController, the interface will be stuck

Environment, Platform, Device

iOS

Version information

Apache Cordova native platform version 6.2.0

Checklist

spoxies commented 1 year ago

This is indeed quite an issue as Lou-Kuang says, and I'd like to chip in with some extra context to replicate the issue (and show its urgency).

So in short if webKit or the underlaying iOS presents a UIAlertController and whilst that is open, a alert(..), confirm(...) is called, the app will be stuck.

This commonly happens if a user is prompted for some native permission, or shake the device to trigger "Shake to Undo".

As far as the javascript goes nothing is halted, so some event might trigger an alert() or confirm().

An alternative/easy way to replicate this issue is execute:

setTimeout(function(){
        alert('This will mess up');
    }, 5000);

// Now shake the device (e.g. like a Polaroid picture), 
// to trigger native Undo dialog....app wil be dead