WKWebView crashes if user answers an incoming iMessage WKWebView crashes if user answers an incoming iMessage swift swift

WKWebView crashes if user answers an incoming iMessage


Not sure if it helps you. I have also faced the NAN issue and it happens if any value is corrupted or invalid. So if you can find out where your value is getting corrupted means it is printing NAN then on that you can put the guard statement.


(1) First Double check your layout is correct, use "Autolayout" and make sure yourconstraints are correct and you are setting the subviews correct.

Try to visually debug the layout to see if there are any strange things happening.

Debug->View Debugging->Capture View Hierarchy.

(2) From the stack trace I notice that the keyboard gets presented, and because of this, the views need to be adjusted to make place for the keyboard. It is noticeable this happens as soon as an message arrives in the stack trace.

I would also attempt to resignFirstResponder, maybe in your AppDelegate

- (void)applicationWillResignActive:(UIApplication *)application {   [_wkWebView resignFirstResponder];}

(3) I have also found that there is a bug, where the WKWEbView will not resignFirstResponder.. this might be related:

Bug 167898 - [iOS] -[WKWebView becomeFirstResponder] and -[WKWebView resignFirstResponder] don’t get called when non-programmatic first responder changes happen

Maybe a workaround then would be to present another view as soon as yourapplication will resign.

- (void)applicationWillResignActive:(UIApplication *)application {    // if _wkWebView is showing then hide and show other view}


set the CG_NUMERICS_SHOW_BACKTRACE environmental variable in the Xcode run scheme and it will dump the stacktrace that caused the non-numeric value to occur.