设置

时间:2016-04-15 05:22:37

标签: ios iphone

我已经检查过我的应用中是否启用了运动和健身功能。我检查了下面的代码来检查这个。

if([CMMotionActivityManager isActivityAvailable])
    {
    }

如果在设置中禁用了运动和健身,则返回FALSE。但iPhone 5及更低版本中没有运动和健身选项。所以我想知道设备型号是iPhone 5s还是更高版本。有没有办法检查这个?

1 个答案:

答案 0 :(得分:1)

如果要查看动作,请使用

https://developer.apple.com/library/prerelease/ios/documentation/CoreMotion/Reference/CMSensorRecorder_class/index.html#//apple_ref/occ/clm/CMSensorRecorder/isAuthorizedForRecording

iOS 9及更高版本,CMSensorRecorder类,其中介绍了检查您的应用是否获得Motion&健身:

如果您正在使用Swift,请使用以下

class`func isAuthorizedForRecording() - >布尔

如果目标C那么

+ (BOOL)isAuthorizedForRecording

如果您只是想检查设备型号,请使用以下方法

[[UIDevice currentDevice] platformType]   // ex: UIDevice4GiPhone
[[UIDevice currentDevice] platformString] // ex: @"iPhone 4G"

获取模型的完整列表

#import <sys/utsname.h> // import it in your header or implementation file.

NSString* deviceName()
{
    struct utsname systemInfo;
    uname(&systemInfo);

    return [NSString stringWithCString:systemInfo.machine
                              encoding:NSUTF8StringEncoding];
}

打印设备名称后,您将获得以下输出之一

@"i386"      on 32-bit Simulator
@"x86_64"    on 64-bit 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
@"iPod7,1"   on iPod Touch 6th 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
@"iPhone3,1" on iPhone 4 (GSM)
@"iPhone3,3" on iPhone 4 (CDMA/Verizon/Sprint)
@"iPhone4,1" on iPhone 4S
@"iPhone5,1" on iPhone 5 (model A1428, AT&T/Canada)
@"iPhone5,2" on iPhone 5 (model A1429, everything else)
@"iPad3,4" on 4th Generation iPad
@"iPad2,5" on iPad Mini
@"iPhone5,3" on iPhone 5c (model A1456, A1532 | GSM)
@"iPhone5,4" on iPhone 5c (model A1507, A1516, A1526 (China), A1529 | Global)
@"iPhone6,1" on iPhone 5s (model A1433, A1533 | GSM)
@"iPhone6,2" on iPhone 5s (model A1457, A1518, A1528 (China), A1530 | Global)
@"iPad4,1" on 5th Generation iPad (iPad Air) - Wifi
@"iPad4,2" on 5th Generation iPad (iPad Air) - Cellular
@"iPad4,4" on 2nd Generation iPad Mini - Wifi
@"iPad4,5" on 2nd Generation iPad Mini - Cellular
@"iPad4,7" on 3rd Generation iPad Mini - Wifi (model A1599)
@"iPhone7,1" on iPhone 6 Plus
@"iPhone7,2" on iPhone 6
@"iPhone8,1" on iPhone 6S
@"iPhone8,2" on iPhone 6S Plus
@"iPhone8,4" on iPhone SE

如果你想在Swift中使用以下链接

iOS: How to determine the current iPhone/device model in Swift?