title: Scheduling an ersatz background fetch in iOS
body: <p>I'm trying to get my app to perform a background fetch at a specific, scheduled time.  I had the idea of letting iOS sort this out for itself, so (in AppDelegate):</p>
  
  <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  
      if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) {
          [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeSound categories:nil]];
      }
  
      [[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
      return YES;
  }
  </code></pre>
  
  <p>and then (also in AppDelegate)</p>
  
  <pre><code>-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  
      NSDate *now = [NSDate date];
  
      if ((([now timeIntervalSinceDate:lastCheckTime]/60) &gt; 60)||(!lastCheckTime)) { //don't update more than once every hour
          lastCheckTime = now;
          [notificationUpdate getStatusUpdateWithCompletionHandler:completionHandler];
      } else {
          completionHandler(UIBackgroundFetchResultNewData);
      }    
  }
  </code></pre>
  
  <p>If I fire the background check manually, in Xcode, this works perfectly.  Sadly, it doesn't work perfectly if I just leave it to its own devices.</p>
  
  <p>How can I schedule a time for my getStatusUpdate function to be executed or cause a background fetch to occur at a specific time (the real life use-case will be that the app will check at around a user defined time, like an alarm clock - this isn't something that will be running all the time and chewing up the battery)</p>
  
  <p>I've found lots on the internet about scheduling an alarm (including here - I found one example here which suggested using CoreLocation to cause the background fetch to fire - I don't know if this would work but, for reasons of power conservation, I don't like the idea.) - but this just causes an alert to be displayed on the screen, and I don't want to display an alert - at least, not before I've checked for status updates.</p>
  
  <p>As always, any help will be very gratefully received (but I fear the answer is that I can't do what I want!).</p>