我目前正在使用一个iOS应用,我正在使用[[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
。根据我以这种方式实施的文档。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
NSLog(@"Launched in background %d", UIApplicationStateBackground == application.applicationState);
[[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
i =0;
return YES;
}
-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSLog(@"Fetch started");
++i;
// Set up Local Notifications
[[UIApplication sharedApplication] cancelAllLocalNotifications];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
NSDate *now = [NSDate date];
localNotification.fireDate = now;
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.alertBody = @"BG Mode";
localNotification.applicationIconBadgeNumber = i;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
completionHandler(UIBackgroundFetchResultNewData);
NSLog(@"Fetch completed");
}
我的问题是我试图调试它以了解此方法调用的频率。我没有得到任何澄清。我已经测试了timeinterval 60秒,但这也无法正常工作。请给我任何想法或建议。提前谢谢。
答案 0 :(得分:1)
为了澄清,您还根据Apple的文档在Info.plist中设置了UIBackgroundModes ......
此属性对于没有UIBackgroundModes键且其Info.plist文件中具有fetch值的应用程序无效。