samedi 1 août 2015

Disable UIWebView automatic refresh when app is not active

I have an iOS8 Swift app that uses UIWebViews for loading certain web pages that triggers automatic refresh of the page frequently. I have three different UIWebviews included in UIViewControllers connected to a UITabBarController.

When the app is active, the automatic refresh is what I want but according to logs, the UIWebviews continue to auto refresh in the background and this may be harmful for battery life and use of Internet bandwidth.

Haven't been able to propagate app state from AppDelegate to UIViewControllers connected to the UITabbarController but have been experimenting with notifications in the UIViewControllers that contains the UIWebviews, using code similar to

NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("didBecomeActive"), name:UIApplicationDidBecomeActiveNotification , object: nil)

I don't get the notifications I expect, maybe this has to do with the use of the UITabBarController.

The app also has a WatchKit extension and I want the WatchKit part to work even if I manage to stop the automatic refresh in the UIWebViews.

The app is not listed in the Settings app regarding turning off background updates of content. Any ideas on how to solve this?

Aucun commentaire:

Enregistrer un commentaire