![](/img/trans.png)
[英]Can't start iphone simulator; “not responding”. Xcode 7, simulator version 9 (for iOS 9)
[英]Can't identify the difference between iPhone and iOS simulator in xcode 7 beta version?
我正在使用以下代码从应用程序拨打电话。在xcode 5中,它工作正常。 但是在xcode 7 beta版中,我在iOS Simulator上运行我的应用,并且if ([[device model] isEqualToString:@"iPhone"] )
对于模拟器来说是正确的。 怎么样 ?
if ([[device model] isEqualToString:@"iPhone"] )
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:130-032-2837"]]];
}
else
{
UIAlertView *notPermitted=[[UIAlertView alloc] initWithTitle:@"Error" message:@"Your device doesn't support this feature." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[notPermitted show];
}
设备或模拟器定义为基于所选目标的构建时间。 这是您应该通过在UIDevice
上添加类别来做到这一点的方法:
@implementation UIDevice (Addition)
- (BOOL)isSimulator {
#if TARGET_IPHONE_SIMULATOR
return true;
#else
return false;
#endif
}
+ (BOOL)isSimulator {
return [[self currentDevice] isSimulator];
}
然后只需调用:
[UIDevice isSimulator]
如果您只想检查您是否正在模拟器中或真实设备上运行,我强烈建议您使用TARGET_OS_SIMULATOR
define(包含在SDK
)
像这样使用它:
#if !(TARGET_IPHONE_SIMULATOR)
//use case for iPhone
#else
//use case for simulator
#endif
我在Xcode 7
和iOS9 SDK
当前项目中使用它
编辑:正如trojanfoe指出的,这是编译时检查,而不是运行时检查。
如果要对模拟器进行运行时特定检查,则可以使用以下命令:
if ([[[UIDevice currentDevice].model lowercaseString] rangeOfString:@"simulator"].location != NSNotFound) {
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.