开发者

How do I detect Grand Central Dispatch feature support on an iPhone?

开发者 https://www.devze.com 2023-04-11 06:33 出处:网络
I started out thinking I wanted to test or detect if iOS was version 4.x so I would know I could use Grand Central Dispatch to run a concurrent thread. If it was less than iOS 4 I would run the code b

I started out thinking I wanted to test or detect if iOS was version 4.x so I would know I could use Grand Central Dispatch to run a concurrent thread. If it was less than iOS 4 I would run the code but not as a thread and take the hit. But in reading at stack overflow I read -

---- "You should probably avoid asking about the system version altogether. A better design would ask about a specific feature. For instance: if (NSClassFromString(@"UIPrintInfo")) would tell you if the current device supports the printing API,availab开发者_JS百科le in 4.2 or higher. That way you can plan your code to use a feature if it's available, on not based on the OS version."

That makes sense. So instead of testing for iOS 4, what code-safe method would I use to detect Grand Central Dispatch support ?


You can check to see if a function exists at runtime by comparing it to NULL like this:

if (dispatch_async != NULL) {
    NSLog(@"We have GCD");
}
else {
    NSLog(@"We don't have GCD");
}

Note: I haven't actually tested this.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号