检测设备是否为iPhone 5s。

5

我遇到了一个问题,需要找出设备的类型以进行分析。

因此,我需要找到一种方法来检查设备是否为iPhone 5s!

有什么想法吗? 谢谢


1
可能是重复的问题:使用iPhone SDK确定设备(iPhone,iPod Touch) - Martin R
这个回答 https://dev59.com/onRB5IYBdhLWcg3w-8A9#3950748 包含了一个最新的设备列表,是对于重复问题的一个很好的回答。 - Martin R
我实际上是在寻找与处理器相关的答案,比如“CPU_TYPE_ARM64”,就像这里的答案一样https://dev59.com/wmIj5IYBdhLWcg3wzIJo#19859698。 - M.Othman
那么为什么你会接受并不解决你问题的答案呢? - Martin R
它用另一种方式解决了问题,实际上更好 :) 代码更少..我的最后一条评论是为了回答为什么我没有看到你提到的重复项!! - M.Othman
1个回答

21

通过使用GBDeviceInfo

将其添加到您的Pod文件中,并运行pod install命令

pod GBDeviceInfo

确定是否为 iPhone 5s:

if (deviceInfo.model == GBDeviceModeliPhone5s) {
   NSLog(@"It's a 5s");   //It's an iPhone 5s
}

通过代码:

#import <sys/utsname.h>
/*
    @"i386"      on the simulator
    @"iPod1,1"   on iPod Touch
    @"iPod2,1"   on iPod Touch Second Generation
    @"iPod3,1"   on iPod Touch Third Generation
    @"iPod4,1"   on iPod Touch Fourth Generation
    @"iPod5,1"   on iPod Touch Fifth Generation
    @"iPhone1,1" on iPhone
    @"iPhone1,2" on iPhone 3G
    @"iPhone2,1" on iPhone 3GS
    @"iPad1,1"   on iPad
    @"iPad2,1"   on iPad 2
    @"iPad3,1"   on 3rd Generation iPad
    @"iPad3,2":  on iPad 3(GSM+CDMA)
    @"iPad3,3":  on iPad 3(GSM)
    @"iPad3,4":  on iPad 4(WiFi)
    @"iPad3,5":  on iPad 4(GSM)
    @"iPad3,6":  on iPad 4(GSM+CDMA)
    @"iPhone3,1" on iPhone 4
    @"iPhone4,1" on iPhone 4S
    @"iPhone5,1" on iPhone 5
    @"iPad3,4"   on 4th Generation iPad
    @"iPad2,5"   on iPad Mini
    @"iPhone5,1" on iPhone 5(GSM)
    @"iPhone5,2" on iPhone 5(GSM+CDMA)
    @"iPhone5,3  on iPhone 5c(GSM)
    @"iPhone5,4" on iPhone 5c(GSM+CDMA)
    @"iPhone6,1" on iPhone 5s(GSM)
    @"iPhone6,2" on iPhone 5s(GSM+CDMA)
    @"iPhone7,1" on iPhone 6 Plus
    @"iPhone7,2" on iPhone 6
*/

- (NSString*) machineName{
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *result = [NSString stringWithCString:systemInfo.machine
                                          encoding:NSUTF8StringEncoding];
    return result;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接