2014-01-15 104 views
2

我目前正在使用一个iOS应用程序,其中我正在使用[[UIApplication sharedApplication] setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];。根据我以这种方式实施的文档。iOS 7后台抓取

- (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"); 
} 

我的问题是我试图调试它知道这种方法调用的频率。我没有得到任何澄清。我用60秒的时间间隔进行了测试,但那也不起作用。请给我任何想法或建议。提前致谢 。

回答

1

只是为了澄清,你也设置在Info.plist中的UIBackgroundModes按照Apple的文档......

此属性的应用程序没有任何影响不具有与获取价值UIBackgroundModes关键在Info.plist文件中。