IOS后台运行

   一、首先。在Info.plist里面添加
Key:Required background modes
Value:App registers for location updates

- (void)scheduledTimer
{
    UIApplication* app = [UIApplication sharedApplication];
    self.backgroundTask = [app beginBackgroundTaskWithExpirationHandler:^{
        NSLog(@"applicationD in Background");
    }];
    
    
    //加入定时器,用来控制后台运行时间
    NSTimer *runTimer = [NSTimer scheduledTimerWithTimeInterval:10
                                                             target:self
                                                           selector:@selector(startLocation)
                                                           userInfo:nil
                                                            repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:runTimer forMode:NSRunLoopCommonModes];
}

- (void)startLocation
{
    NSLog(@"每隔10秒来一次!!!!!");
}

 

posted @ 2014-04-01 09:44  菜鸟程序猿  阅读(193)  评论(0编辑  收藏  举报