I want to integrate background selection in my iOS application, I turned on Background Fetch in the project features, then I insert this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
to enable background selection with the minimum interval, and then in the application deletion I insert the delegate method:
-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { NSLog(@"Call fetch iCloud"); [[MySingleton sharedManager] startCheckOnCloud]; }
My question is that I know what I should call it:
completionHandler(UIBackgroundFetchResultNewData);
somewhere, I see many examples that insert this performFetchWithCompletionHandler completion method into the performFetchWithCompletionHandler delegate performFetchWithCompletionHandler , but in this method I call NSOperation in Singleton , this operation checks the iCloud che folder and makes some changes to Sqlite DB if I do this:
-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { NSLog(@"Call fetch iCloud"); [[MySingleton sharedManager] startCheckOnCloud]; completionHandler(UIBackgroundFetchResultNewData); }
start work and do something, maybe because the system makes it sleep instantly, instead, if I remove checkHandler, give me this warning:
Warning: Application delegate received call to -application:performFetchWithCompletionHandler: but the completion handler was never called.
so my question is: how can I handle completionHandler using NSOperation ?