在iPhone上执行后台任务
来源:互联网 发布:域名就是ip地址 编辑:程序博客网 时间:2024/04/29 14:44
当App进入到后台时,可以有一段时间做处理工作。
或者,对于某些服务,可以长时间运行,比如播放音乐。
对于长时间运行的任务,需要在Info.plist添加一行,键为UIBackgroundModes,值为一个数组,可以包含如下几个字符串:
- audio
- location
- voip
- newsstand-content
- external-accessory
- bluetooth-central
然后,在后台就可以做一些事情了:
- (void)applicationDidEnterBackground:(UIApplication *)application{ // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. UIDevice *device = [UIDevicecurrentDevice]; BOOL backgroundSupported = NO; if ([device respondsToSelector:@selector(isMultitaskingSupported)]) { backgroundSupported = YES; } __blockUIBackgroundTaskIdentifier bgTaskId = [application beginBackgroundTaskWithExpirationHandler:^{ [application endBackgroundTask:bgTaskId]; bgTaskId = UIBackgroundTaskInvalid; }]; if (backgroundSupported) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // }); }}
原文地址:http://blog.csdn.net/jasonblog/article/details/7794886
Jason Lee @ Hangzhou- 在iPhone上执行后台任务
- 在iPhone上执行后台任务
- 在iPhone上执行后台任务
- iPhone的后台执行任务
- ios iphone 详解在IOS后台执行
- ios iphone 详解在IOS后台执行
- ios iphone 详解在IOS后台执行
- iphone后台功能执行
- Rails后台执行任务
- 执行后台任务
- receiver执行后台任务
- 执行转为后台执行任务
- 在程序后台执行一个短时间的任务
- 在程序后台执行一个短时间的任务
- 无限后台任务 iOS iPhone
- iphone OS 4.0操作系统中多任务~禁止后台执行的方法
- iphone OS 4.0操作系统中多任务~禁止后台执行的方法
- 关于php执行后台任务
- NSIS——宏使用方法(!macro和!insertmacro)
- box2d 碰撞筛选
- Hibernate执行save方法 注意
- dd if=/dev/zero of=的含义是什么?Linux 下的dd命令使用详解
- java操作oracle数据库
- 在iPhone上执行后台任务
- 写给计算机软件专业的大学生
- Linux 信号signal处理机制
- javascript DOM——初学2
- Linux 信号signal处理函数
- Plone中用户、组和权限管理
- SSI整合--搭建Struts2+Spring+Ibatis框架
- poj 1088滑雪 (动态规划)
- 实习总结(十四)---S2SH整合开发