【发布时间】:2013-11-23 16:25:07
【问题描述】:
我想在我的 iOS 应用程序中集成 Background Fetch,我已经在项目的功能中启用了 Background Fetch,然后我插入了这个:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
以最小间隔启用后台提取,然后在 App 委托中插入委托方法:
-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
NSLog(@"Call fetch iCloud");
[[MySingleton sharedManager] startCheckOnCloud];
}
我的问题是这个,我知道我必须这样称呼:
completionHandler(UIBackgroundFetchResultNewData);
在某处,我看到了很多在 performFetchWithCompletionHandler 委托方法中插入该完成处理程序的示例,但在该方法中,我在 Singleton 中调用 NSOperation,该操作检查 iCloud 文件夹并进行一些更改在Sqlite DB,如果我这样做:
-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
NSLog(@"Call fetch iCloud");
[[MySingleton sharedManager] startCheckOnCloud];
completionHandler(UIBackgroundFetchResultNewData);
}
操作开始并执行任何操作,可能是因为系统使其立即休眠,而不是如果我删除了 completionHandler 给我这个警告:
Warning: Application delegate received call to -application:performFetchWithCompletionHandler: but the completion handler was never called.
所以我的问题是,我如何处理 completionHandler 和 NSOperation?
【问题讨论】:
标签: objective-c ios7