Mar*_*ark 2 iphone model ipod-touch detection
这是检测用户正在运行的设备的正确方法吗?
NSString *currentModel = [[UIDevice currentDevice] model];
if ([currentModel isEqualToString:@"iPhone"]) {
// The user is running on iPhone so allow Call, Camera, etc.
} else {
// The user is running on a different device (iPod / iPad / iPhone Simulator) disallow Call.
}
Run Code Online (Sandbox Code Playgroud)
它不是一般解决方案,但Apple在许多情况下提供API调用以检查是否支持特定功能.例子可能是:
+isSourceTypeAvailable:并+availableMediaTypesForSourceType:在UIImagePickerController允许你检查相机可用于当前设备.
+canSendMail在MFMailComposeViewController检查设备被配置为发送邮件.
-canOpenURL在UIApplication课堂上检查是否可以打开URL.例如,它可用于检查是否可以拨打电话:
if (![[UIApplication sharedApplication] canOpenURL:
[NSURL URLWithString:@"tel://"]])
//We cannot make a call - hide call button here
Run Code Online (Sandbox Code Playgroud)如果此类API调用可用于您的目的,我会使用它们而不是依赖于硬编码的字符串标识符.
| 归档时间: |
|
| 查看次数: |
2338 次 |
| 最近记录: |