现在的位置: 首页 > 综合 > 正文

ios后台运行

2013年04月08日 ⁄ 综合 ⁄ 共 535字 ⁄ 字号 评论关闭

- (void)run

{

    UIApplication *application = [UIApplication
sharedApplication];

    __block
UIBackgroundTaskIdentifier background_task;

    background_task = [application
beginBackgroundTaskWithExpirationHandler: ^ {

        [self
hold];

        [application
endBackgroundTask: background_task];

        background_task =
UIBackgroundTaskInvalid;

    }];

    

}

- (void)hold

{

   
_holding = YES;

   
while (_holding) {

        [NSThread
sleepForTimeInterval:1];

        CFRunLoopRunInMode(kCFRunLoopDefaultMode,
0, TRUE);

    }

}

- (void)stop

{

   
_holding = NO;

   
DLog(@"end");

}

在applicationDidEnterBackground里面调用run方法

抱歉!评论已关闭.