您的位置:首页 > 移动开发 > IOS开发

IOS后台运行

2014-04-01 09:44 155 查看
一、首先。在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秒来一次!!!!!");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: