Swift IOS app won't start after idle for over 1 day

622 Views Asked by At

I have a simple app in Swift with just a few views:

  • A UIWebView
  • some TableViews
  • and another view with some data I download from my server

It all works well until when using the app I press the home button, leave there for a while then the iPad goes on sleep mode. A few days later I tap on the app icon and it won't start:

  • first tap on the icon will select the icon (goes a little darker) and deselect it a few seconds later
  • second tap will launch the LaunchScreen and crash a few seconds later
  • double tap the home button and quit the app will sometimes work

I'm just wondering if there is something I need to set on my code to handle idle/long periods of inactivity in something like viewWillDisappear or other methods?

If so I already have this in all my controllers:

override func viewWillDisappear(animated: Bool) {
    timer.invalidate()
    webView.removeFromSuperview()
}

Maybe I need to call super. in there too? or something else I'm missing?

2

There are 2 best solutions below

0
On

You probably have some null pointer exception and crash. Maybe you are calling some variable that is not set (and checked if not null). Try disabling app funcionality (like downloading, storing and using data from server) and see where you app starts working normal again and then procede from there.

Sorry for vague answer but withouth code and maybe some log it is really hard to give specific answer.

And NO, you dont have to do anything special to handle idle/long periods of inactivity.

3
On

You should definitely call super in your viewWillDisappear(animated:) method. See UIViewController Class Reference documentation. Also you might want to confirm why you are removing your webView from the view controller's hierarchy.

Discussion

This method is called in response to a view being removed from a view hierarchy. This method is called before the view is actually removed and before any animations are configured.

Subclasses can override this method and use it to commit editing changes, resign the first responder status of the view, or perform other relevant tasks. For example, you might use this method to revert changes to the orientation or style of the status bar that were made in the viewDidDisappear: method when the view was first presented. If you override this method, you must call super at some point in your implementation.