Four years later and I too encountered this problem after moving from WebView to WKWebView. Usually it worked, but sometimes it didn't.
In my case, when it didn't work, the problematic modal window run loop was being invoked (ultimately) from inside a dispatch_async block. Rearranging things to avoid doing that solved the problem for me.