ios调用Html内JS alert 不能点击关闭为甚?

本文探讨了iOS应用中使用WebView加载HTML页面时,遇到JS alert导致的死锁现象。通过分析发现,处理JS警报的线程与处理iOS警报视图的线程可能相互阻塞。为避免这一问题,文章提供了两种解决方案:一是使用JavaScript的setTimeout方法延时显示alert;二是让UIWebView触发UIAlertView而非依赖其处理JS警报。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ios调用Html内JS alert 不能点击关闭为甚?

This question gave me the most insight to the problem...

Deadlock with GCD and webView

The gist is that the thread handling the JS from the stringByEvaluatingJavaScriptFromString: method and the thread handling the iOS alert view are probably blocking each other, making the "Close" button unresponsive.

My workaround is to defer the JS alert with a setTimeout, something like this...

NSString *jsMyAlert = @"setTimeout(function(){alert('FOOBAR');}, 1);";

[myWebView stringByEvaluatingJavaScriptFromString:jsMyAlert];To avoid any risk of deadlock, it might be better to have the UIWebView trigger an UIAlertView rather than rely on UIWebView to handle the JS alert. The workaround above would be suitable for most debugging purposes though.

 

转载于:https://www.cnblogs.com/ecmasea/p/7093099.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值