ios后台申请运行一定的时间
2013-05-06 09:52
281 查看
在 应用的appdelegate里面的- (void)applicationDidEnterBackground:(UIApplication *)application代理方法中加上:
UIApplication *app = [UIApplication sharedApplication];
__block UIBackgroundTaskIdentifier taskId;
taskId = [app beginBackgroundTaskWithExpirationHandler:^{
NSLog(@"后台任务超时被退出");
[app endBackgroundTask:taskId];
}];
if(taskId == UIBackgroundTaskInvalid)
{
return;
}
//队列中等待(类似于等待线程,个人理解)
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
{
NSLog(@"后台任务据最长时限还有 %f 秒",app.backgroundTimeRemaining);
[NSThread sleepForTimeInterval:32]; //等待32秒
NSLog(@"后台任务据最长时限还有 %f 秒",app.backgroundTimeRemaining);
[app endBackgroundTask:taskId];//通知系统后台任务已处理完毕
});
}
UIApplication *app = [UIApplication sharedApplication];
__block UIBackgroundTaskIdentifier taskId;
taskId = [app beginBackgroundTaskWithExpirationHandler:^{
NSLog(@"后台任务超时被退出");
[app endBackgroundTask:taskId];
}];
if(taskId == UIBackgroundTaskInvalid)
{
return;
}
//队列中等待(类似于等待线程,个人理解)
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
{
NSLog(@"后台任务据最长时限还有 %f 秒",app.backgroundTimeRemaining);
[NSThread sleepForTimeInterval:32]; //等待32秒
NSLog(@"后台任务据最长时限还有 %f 秒",app.backgroundTimeRemaining);
[app endBackgroundTask:taskId];//通知系统后台任务已处理完毕
});
}
相关文章推荐
- IOS 后台运行申请更多的时间
- iOS后台运行延长时间
- 对iOS后台模式最多10分钟运行时间的进一步理解
- IOS实现在后台执行一定时间的任务
- iOS申请持续的后台时间
- iOS App进入后台获取更多的运行时间
- 后台申请3分钟运行时间
- (最新)iOS后台运行时间
- iOS App进入后台获取更多的运行时间
- iOS-app进入后台申请10分钟活跃时间
- ios应用在后台运行时间讨论
- iOS-app进入后台申请10分钟活跃时间S
- ios应用在后台运行时间讨论
- iOS App进入后台获取10min的运行时间
- iOS App进入后台获取更多的运行时间
- iOS App进入后台获取更多的运行时间
- iOS App进入后台获取更多的运行时间
- IOS 后台挂起,向IOS申请后台无限时间
- iOS App进入后台获取更多的运行时间
- ios开发教程之申请更多后台时间