Showing a JavaScript alert hangs UIWebView
| Originator: | ben | ||
| Number: | rdar://13795347 | Date Originated: | 5/2/2013 |
| Status: | Open | Resolved: | |
| Product: | iOS SDK | Product Version: | 6.1 |
| Classification: | Crash/Hang/Data Loss | Reproducible: | Always |
02-May-2013 01:10 PM Benjamin Nham: Summary: If you execute alert() in -[UIWebView stringByEvaluatingJavaScriptFromString:], it sometimes hangs. Specifically, if you execute in the context of a dispatch_async or dispatch_after callout, the alert view does not respond to touch. This problem has been extensively reported on StackOverflow: http://stackoverflow.com/questions/11593900/uiwebview-stringbyevaluatingjavascriptfromstring-hangs-on-ios5-0-5-1-when-called Steps to Reproduce: Execute the sample project with USE_DISPATCH in ViewController.m set to 1. Notice the alert hangs and doesn't respond to the ok button. Then set USE_DISPATCH to 0. The alert now responds to the ok button. Expected Results: The alert should respond to the ok button. Actual Results: The alert does not respond to the ok button. Regression: Doesn't work as of at least iOS 6. Notes: I verified that the recursive modal runloop used by UIAlertView *is* receiving touches (by breaking on _UIApplicationHandleEvent). However, the touch is never delivered to the UIAlertButton inside the UIAlertView in the dispatch case. A possible clue is that in the dispatch case, the alert view seems to be stuck in an intermediate state. Notice that the UIAlertView has a scale transform of 1.1 in the USE_DISPATCH=1 case: <_UIAlertNormalizingOverlayWindow: 0xe05cb00; frame = (0 0; 320 480); opaque = NO; layer = <UIWindowLayer: 0xe05cc20>> | <UIImageView: 0x71809e0; frame = (0 0; 320 480); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7180800>> | <UIAlertView: 0xe053840; frame = (3.8 188.35; 312.4 124.3); transform = [1.1, 0, 0, 1.1, 0, 0]; opaque = NO; layer = <CALayer: 0xe053ae0>> | | <UIImageView: 0x71757f0; frame = (0 0; 284 113); opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x7165710>> | | <UIAlertButton: 0xe058fb0; frame = (11 54; 262 43); opaque = NO; tag = 1; layer = <CALayer: 0xe059110>> | | | <UIImageView: 0x7175ff0; frame = (0 0; 262 43); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7176050>> | | | <UIButtonLabel: 0xe059a50; frame = (117 10; 27 22); text = 'OK'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xe059b40>> | | <UILabel: 0xe05c0a0; frame = (12 15; 260 21); text = 'hello'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xe05c1b0>> but in the USE_DISPATCH=0 case, the UIAlertView has the identity transform on it, as expected: <_UIAlertNormalizingOverlayWindow: 0x8a80d60; frame = (0 0; 320 480); opaque = NO; layer = <UIWindowLayer: 0x8a80e80>> | <UIImageView: 0x8a83810; frame = (0 0; 320 480); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x8a839e0>> | <UIAlertView: 0x8a77df0; frame = (18 194; 284 113); opaque = NO; layer = <CALayer: 0x8a78090>> | | <UIImageView: 0x7187850; frame = (0 0; 284 113); opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x71878b0>> | | <UIAlertButton: 0x8a7d560; frame = (11 54; 262 43); opaque = NO; tag = 1; layer = <CALayer: 0x8a7d6c0>> | | | <UIImageView: 0x7187fa0; frame = (0 0; 262 43); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7188000>> | | | <UIButtonLabel: 0x8a7e000; frame = (117 10; 27 22); text = 'OK'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x8a7e0f0>> | | <UILabel: 0x8a80300; frame = (12 15; 260 21); text = 'hello'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x8a80410>> From my days working on UIAlertView back when I was at Apple, this perhaps indicates that the alert view is stuck in an intermediate state, possibly waiting for an animation finished callback to fire. Not sure if that would cause touches to not be processed in the alert button.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!