【发布时间】:2014-07-18 13:24:15
【问题描述】:
我是 obj-c 编程的初学者,我需要知道如何显示设备信息(名称、设备类型、ios 版本)
我知道答案,请告诉我并记住我是 xcode 的初学者;)
【问题讨论】:
-
点击此链接进行设备检测stackoverflow.com/questions/8292246/…
标签: ios cocoa-touch
我是 obj-c 编程的初学者,我需要知道如何显示设备信息(名称、设备类型、ios 版本)
我知道答案,请告诉我并记住我是 xcode 的初学者;)
【问题讨论】:
标签: ios cocoa-touch
我在我开发的应用程序中使用了这些信息,因此我编写了以下代码。我想这可能会对你有所帮助。我只是不明白你说的设备类型是什么意思。
获取设备型号:
// get model from UIDevice
NSString *modelDevice = [UIDevice currentDevice].model;
获取 iOS 版本:
//get the iOS version
NSString *systemVersion = [[UIDevice currentDevice] systemVersion];
获取设备名称:
/** Method responsible to get the device name
*
* @return device Name
*/
+ (NSString *)deviceName
{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithUTF8String:machine];
free(machine);
return platform;
}
【讨论】:
您可以尝试这样的事情:我将其用于来自用户的应用内支持电子邮件。
#import <sys/utsname.h>
- (void)yourMethod
{
struct utsname systemInfo;
uname(&systemInfo);
NSString *appVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleVersion"];
NSString *osVersion = [[UIDevice currentDevice] systemVersion];
NSString *machine = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
}
【讨论】:
NSLog(@"uniqueIdentifier: %@", [[UIDevice currentDevice] uniqueIdentifier]);
NSLog(@"name: %@", [[UIDevice currentDevice] name]);
NSLog(@"systemName: %@", [[UIDevice currentDevice] systemName]);
NSLog(@"systemVersion: %@", [[UIDevice currentDevice] systemVersion]);
NSLog(@"model: %@", [[UIDevice currentDevice] model]);
NSLog(@"localizedModel: %@", [[UIDevice currentDevice] localizedModel])
;
【讨论】:
请参考 UIDevice 类。它具有所有可访问的系统信息属性。这是一个单例类。你可以像这样访问这个类实例:[UIDevice currentDevice]
例如如果你想访问设备型号,你可以这样访问:
[UIDevice currentDevice]. model
请参阅此链接以获取有关所有属性的信息:https://developer.apple.com/library/ios/documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html
【讨论】: