1

I have the following:

In Settings, Capabilities I have background fetch checked.

In appDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    [application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];

    return YES;
}

    - (void) application:(UIApplication*) application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
    NSLog(@"A fetch got called");
    completionHandler(UIBackgroundFetchResultNoData);
}

BUT, when I debug the code on the iPhone the performFetch doesn't fire except when I hit "Simulate Background Fetch" in the debug menu. Isn't the phone supposed to periodically fire this on its own? What am I missing?

SchroedingersCat
  • 487
  • 8
  • 21
  • I'm getting the same symptoms, with what seems like functionally equivalent code. I'm curious if something in iOS somehow requires your handler to actually make an HTTP request. Have you tried that yet? – John Walthour Oct 31 '14 at 16:45
  • This might help you: I went through about two dozen cycles of opening the app, then returning to the home screen. Apparently this iPhone's heuristics needed to be trained that the user was using this app during this particular time of day. On the plus side, it worked with no HTTP requests. This was also with the debugger detached (used an internal counter to see how many fetches were called) – John Walthour Oct 31 '14 at 16:55
  • This works for me. I use Safari, phone app, some other apps that use Wifi/mobile data and lock the phone. The notification does fire in 5-10 mins ..... – Manali Oct 06 '16 at 09:34

1 Answers1

0

Ok. They worked. I just wasn't patient enough. They seem to fire rather infrequently and usually when I am doing something else with the phone (making a call, entering passcode, etc). How often do they typically fire? I know I can indicate a desired fire rate by setting a background minimum fetch interval, but I am just curious how often they fire with the default?

SchroedingersCat
  • 487
  • 8
  • 21
  • Were you able to identify the time interval? I am facing the same issue. I gave the time interval as '20' as opposed to UIApplicationBackgroundFetchIntervalMinimum. It hasn't fired yet. It has been two hours since I launched the app. – Hells Guardian Aug 25 '16 at 09:35
  • This works for me. I use Safari, phone app, some other apps that use Wifi/mobile data and lock the phone. The notification does fire in 5-10 mins ..... – Manali Oct 06 '16 at 09:34