I am trying to call performFecthWithCompletionHandler
using background fetch feature of ios7.
For that I have set 180seconds of time interval.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
NSLog(@"Did finish launching");
NSTimeInterval timeInterval = 180;
[[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:timeInterval];
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
return YES;
}
I have gone through many threads where it suggests for Xcode -> Debug -> Simulate Background fetch. Which is working fine.
But I want the app to call this method automatically after timeInterval finishes. I have tried with running the app without connecting to Xcode. But it does not call after 180seconds. It takes some more time to getting it called.
-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSLog(@"########### Received Backgroudn Fetch ###########");
//Increase Badge Number
[UIApplication sharedApplication].applicationIconBadgeNumber++;
UINavigationController *navigationController = (UINavigationController*)self.window.rootViewController;
NSLog(@"fetch");
id topViewController = navigationController.topViewController;
if ([topViewController isKindOfClass:[ViewController class]]) {
[(ViewController*)topViewController insertNewObjectForFetchWithCompletionHandler:completionHandler];
} else {
NSLog(@"Not the right class %@.", [topViewController class]);
completionHandler(UIBackgroundFetchResultFailed);
}
}
Anything I am missing here? Or what makes it not get called