【问题标题】:How to detect and display device info on iOS如何在 iOS 上检测和显示设备信息
【发布时间】:2014-07-18 13:24:15
【问题描述】:

我是 obj-c 编程的初学者,我需要知道如何显示设备信息(名称、设备类型、ios 版本)

我知道答案,请告诉我并记住我是 xcode 的初学者;)

【问题讨论】:

标签: ios cocoa-touch


【解决方案1】:

我在我开发的应用程序中使用了这些信息,因此我编写了以下代码。我想这可能会对你有所帮助。我只是不明白你说的设备类型是什么意思。

获取设备型号:

// 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;
}

【讨论】:

  • 设备类型是 Ipod touch、ipad、iphone,非常感谢! :)
  • 我需要在 appdelegate.h 或 .m 上插入此代码?
  • 您可以创建一个类来使用此代码,也可以将其插入您需要的地方。然后只需调用该方法即可获取您想要的信息。
【解决方案2】:

您可以尝试这样的事情:我将其用于来自用户的应用内支持电子邮件。

#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];
}

【讨论】:

    【解决方案3】:
        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])
    
    ;
    

    【讨论】:

      【解决方案4】:

      请参考 UIDevice 类。它具有所有可访问的系统信息属性。这是一个单例类。你可以像这样访问这个类实例:[UIDevice currentDevice]

      例如如果你想访问设备型号,你可以这样访问:

      [UIDevice currentDevice]. model
      

      请参阅此链接以获取有关所有属性的信息:https://developer.apple.com/library/ios/documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-08-10
        • 1970-01-01
        • 2013-07-12
        • 2011-01-13
        • 2022-08-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多