你的位置:首页 > 信息动态 > 新闻中心
信息动态
联系我们

多任务笔记

2022/6/26 0:58:37

多任务笔记  

2010-08-17 23:44:39|  分类: cocoa |  标签:cocoa  iphone  objective-c   |字号 订阅

检测是否支持多任务
UIDevice* device = [UIDevice currentDevice];
BOOL backgroundSupported = NO;
if ([device respondsToSelector:@selector(isMultitaskingSupported)])
   backgroundSupported = device.multitaskingSupported;

后台运行的类别有3种
audio - The application plays audible content to the user while in the background.
location - The application keeps users informed of their location, even while running in the background.
voip - The application provides the ability for the user to make phone calls using an Internet connection.

还有另外的两种方法
Applications can ask the system for extra time to complete a given task.
Applications can schedule local notifications to be delivered at a predetermined time.

在plist文件中的key
UIBackgroundModes key in its Info.plist

几个状态的切换
application:didFinishLaunchingWithOptions:
applicationDidBecomeActive:
applicationWillResignActive:
applicationDidEnterBackground:
applicationWillEnterForeground:
applicationWillTerminate:



在程序暂停之前.应用程序可以使用这个方法请求系统一些额外的时间完成 长期运行的任务
beginBackgroundTaskWithExpirationHandler
假如请求被同意,app进入后台,这个任务可以继续执行
UIApplication 的 backgroundTimeRemaining 属性表示还剩下多少运行时间
这个可以用在下载文件的时候,不会应为用户突然退出而中断