iOS中检测是否支持多任务

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    

    // Override point for customization after application launch.

    RootViewController *rootController=[[RootViewControllerallocinit];

    rootController.title = @"Root";

    

    navController = [[UINavigationControllerallocinitWithRootViewController:rootController];


    [rootController release];

    [self.windowaddSubview:navController.view];

    [self.windowmakeKeyAndVisible];

    

    //检测是否支持多任务.

    UIDevice* device = [UIDevicecurrentDevice];

    BOOL backgroundSupported =NO;

    if ([devicerespondsToSelector:@selector(isMultitaskingSupported)]) {

        backgroundSupported = device.multitaskingSupported;

        NSLog(@"background supported:%d", backgroundSupported);

    }

    

    return YES;

}

如果支持,则会打印1,否则打印0. 

iOS4以前的版本操作系统不支持多任务,因而应用一旦离开前台foreground,即被终止。

iOS4及以后的版本支持多任务,但也有某些运行iOS4版本系统但是不支持多任务的设备的情况。支持多任务的系统,当应用离开前台时,会短暂切入inactive状态,然后切入后台background状态。在后台时若不处理事件,则稍后不久便被挂起,即进入suspended状态。

之所以不退出是为了方便下次再次启动应用时能很快速的启动。

之所以要挂起是为了减少功耗。

posted @ 2012-02-22 15:36  Piosa  阅读(808)  评论(0编辑  收藏  举报