你可以检查这样的systemVersion
属性UIDevice
:
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0f) {
// Do something
}
Run Code Online (Sandbox Code Playgroud)
但我个人不喜欢那种方法,因为我不喜欢从中返回的字符串的解析systemVersion
和这样的比较.
最好的方法是检查你想要使用的类/方法是否存在.例如:
如果你想TWRequest
在Twitter框架中使用:
Class twRequestClass = NSClassFromString(@"TWRequest");
if (twRequestClass != nil) {
// The class exists, so we can use it
} else {
// The class doesn't exist
}
Run Code Online (Sandbox Code Playgroud)
或者,如果你想使用startMonitoringForRegion:
从CLLocationManager
该被带到iOS中5.0:
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
...
if ([locationManager respondsToSelector:@selector(startMonitoringForRegion:)]) {
// Yep, it responds
} else {
// Nope, doesn't respond
}
Run Code Online (Sandbox Code Playgroud)
一般来说,做这样的检查比查看系统版本更好.
归档时间: |
|
查看次数: |
855 次 |
最近记录: |