2016-04-15 42 views
0

我已檢查是否運動&健身已啓用在我的應用程序。我檢查了下面的代碼來檢查這個。檢查運動和健身選項是可用的設置

if([CMMotionActivityManager isActivityAvailable]) 
    { 
    } 

當運動&健身在設置中被禁用時返回FALSE。但運動&健身選項是不存在於iPhone 5及更低版本。所以我想知道設備型號是iPhone 5s還是更高。有什麼方法可以檢查嗎?

回答

1

如果你想查詢的運動,然後使用

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

的iOS 9以上,CMSensorRecorder類,在他們介紹的方法來檢查,如果您的應用程序被授權爲運動&健身:

如果您使用的是Swift,請使用以下代碼

class`func isAuthorizedForRecording() - > Bool

如果目標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 

如果您在斯威夫特想請使用以下鏈接

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