Search code examples
iosobjective-cios10today-extensionios10-today-widget

iOS 10 Today View Widget: How to tell if it's *actually* on screen / visible?


I have a widget which retrieves updates from a server at regular intervals throughout the day, but want it to immediately update again if the user actually looks at it. This always worked fine in iOS 8/9... viewWillAppear fired specifically when, well, the view was about to appear.

But in iOS 10, it seems to happen at other times as well. Not sure when. But suddenly I'm getting about 5x as many hits on the update service, which is a paid service, so this is a real problem.

Is there a way, on a Today widget, to be guaranteed that the widget is actually visible? Or, at the very least, that the Today View is actually visible?


Solution

  • I'd bet that the 5x as many hits is because of how users unlock their devices on iOS 10 now. Swiping from the lock screen shows the users widgets instead of unlocking their device. If you're requesting in your viewWillAppear then every time a users muscle memory tries to unlock the device the old way, by swiping, your widget is sending a server request. You might want to setup a timer for the request, or add a refresh button.