iosios8widgetios8-extensionios8-today-widget

Is it possible to determine when iOS widget hides?


Is there any way to catch the moment when a user hides the notification panel with a widget? I want to save some information into the database at that moment (I want it to be similar to applicationDidEnterBackground:). Any other ideas about how to save data at the last moment would also be appreciated.


Solution

  • Usually, your widget would be a UIViewController instance, conforming to the NCWidgetProviding protocol. That means, that you can take advantage of UIViewController's functionality and execute your code in

    - (void)viewWillDisappear:(BOOL)animated;

    or

    - (void)viewDidDisappear:(BOOL)animated;
    

    I tested it and it worked.