Objective c 未在固定时间间隔调用performFetchWithCompletionHandler
我正在尝试使用ios7的后台获取功能调用performFecthWithCompletionHandler。 为此,我设置了180秒的时间间隔Objective c 未在固定时间间隔调用performFetchWithCompletionHandler,objective-c,iphone,ios7,background,Objective C,Iphone,Ios7,Background,我正在尝试使用ios7的后台获取功能调用performFecthWithCompletionHandler。 为此,我设置了180秒的时间间隔 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch.
- (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;
}
我已经经历了许多线程,其中建议使用Xcode->Debug->Simulate Background fetch。这很好用
但我希望应用程序在时间间隔结束后自动调用此方法。
我尝试过在不连接Xcode的情况下运行应用程序。
但它在180秒后不会呼叫。打电话需要更多的时间
-(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);
}
}
我有什么遗漏吗?或者是什么原因使它不能被调用您无法控制操作系统何时允许应用程序在后台“唤醒”并执行后台提取。操作系统根据许多不同的因素决定应用程序执行抓取的频率。我已经看到,有时使用相同应用程序时数的不同设备之间会有所不同,这取决于应用程序在设备上的时间长短、它完成了多少次后台抓取以及完成它们的速度/效率等 当您设置最小后台提取时间间隔时,它不会告诉操作系统执行提取的频率,而是告诉操作系统它执行后台提取的频率不应超过该时间间隔。最小后台提取时间间隔: 指定两个时间间隔必须经过的最小时间量 后台提取操作 : 我强烈建议您阅读文档以及与iOS7多任务相关的任何内容,以便更好地了解它的工作原理