TimOliver/TOWebViewController

Crash when running UI Tests that close TOWebViewController while page still loading

agarbowitzOmadaHealth opened this issue · 1 comments

We have a UI Test that quickly opens a TOWebViewController and then closes it before the page has a chance to finish loading. However, this causes a crash in our UI Test sometimes because the TOWebViewController no longer exists in memory but callbacks on the delegate (for progress) appear to still be happening. We were able to solve this crash from happening by setting the delegate to property to nil in the deinit method. Something like this (we subclassed TOWebViewController here in Swift rather than modify the TOWebViewController.m file directly):

class OmadaWebViewController: TOWebViewController {
    deinit {
        webView.delegate = nil
    }
}

Normally delegates are weak to prevent having to do this sort of thing yourself, but when glancing at UIWebView.h, you can see that surprisingly this delegate is not weak:

@property (nullable, nonatomic, assign) id <UIWebViewDelegate> delegate;

Suggestion:

Add in a Dealloc method and set the delegate to nil in TOWebViewController.m

Oh awesome! Thank you so much for the suggestion. I just added it to the library. :D