NSString * nsStrIphone=@”iPhone”;
NSString * nsStrIpod=@”iPod”;
NSString * nsStrIpad=@”iPad”;
bool bIsiPhone=false;
bool bIsiPod=false;
bool bIsiPad=false;
bIsiPhone=[self checkDevice:nsStrIphone];
bIsiPod=[self checkDevice:nsStrIpod];
bIsiPad=[self checkDevice:nsStrIpad];
-(bool)checkDevice:(NSString*)name
{
NSString* deviceType = [UIDevice currentDevice].model;
NSLog(@”deviceType = %@”, deviceType);
NSRange range = [deviceType rangeOfString:name];
return range.location != NSNotFound;
}
本文介绍了一种使用Objective-C检查当前设备是否为iPhone、iPod或iPad的方法。通过比对UIDevice.currentDevice.model与预设字符串来实现设备类型的识别。
1571

被折叠的 条评论
为什么被折叠?



