title: How to tell if iOS Today Widget is being updated in the background?
body: <p>I have an iOS Today Widget that makes an expensive API call (expensive as in the more it is called, the more I pay money). If I implement widgetPerformUpdateWithCompletionHandler in my widget, then the widget can be updated in the background several times a day without the user ever looking at their Notification Center.</p>
  
  <p>In an app, there is a key-value-pair in the options dictionary of application:didFinishLaunchingWithOptions that tells you if the app is launching the background or not, but there isn't anything similar in a widget that I can find. There is also the call to get the applicationState in UIApplication, which also isn't available in a widget.</p>
  
  <p>So, is there any <em>reliable</em> way in my widget to know that the system is updating my widget in the background and the user isn't looking at their Notification Center to save myself from unnecessary API calls? I'm fine with the content not being completely up to date when the user does look at the widget because I can update it pretty quickly after it loads.</p>
  
  <p>I've been trying to find a hacky solution like something different with the view or window that is different when the widget is being updated in the background, but haven't found anything yet. I've noticed the occasionally when the widget is initialized in the background that the window frame has a height of zero, but that doesn't seem to always be the case. </p>
  
  <p>I'm also aware that if I don't implement widgetPerformUpdateWithCompletionHandler, then my widget isn't updated in the background which is a possible solution, but I'm looking for a way that I can have my cake and eat it too.</p>
  
  <p>If anyone has any other ideas, I'm all ears. Thanks.</p>