#import <foundation/foundation.h> #import <uikit/uikit.h>typedef NS _options (nsinteger,devicetype) {iphonefivepointfiveinch = 1 << 0, Iphonefourpointseveninch = 1 << 1, Iphonefourinch = 1 << 2, Iphonethreepointfiveinch = 1 << 3, Ipadpro = 1 << 4, Ipadohter = 1 << 5}; @interface checkdevice:nsobject+ (DeviceType) getcurrentdevice; @end
#import"CheckDevice.h"#import"Sys/utsname.h"@implementationCheckdevice+ (DeviceType) Getcurrentdevice {Size of the modelIpadpro and IPhone6 Public {375, 667},ipad other models and iphone4s public {320, 480}Nsarray *iphonesize = @[@ "{414, 736}",@ "{375, 667}",@ "{320, 568}",@ "{320, 480}"];Judging screen SizeNSString *type =Nsstringfromcgsize ([UIScreen Mainscreen]. Bounds. size);struct Utsname systemInfo; Uname (&systeminfo);NSString *platform = [nsstring stringwithcstring:systeminfo.machine encoding:< Span class= "hljs-built_in" >nsutf8stringencoding]; if ([Platform Hasprefix:@ "IPhone"]) { return [iphonesize Indexofobject:type];} else if ([Platform Hasprefix:@ " IPad "]) {//ipad if ([iphonesize indexofobject:type] = = Iphonefourpointseveninch) return Ipadpro; else return Ipadohter;} else//simulator return [iPhoneSize Indexofobject:type];} @end
iOS Judging Models