你如何获得iPhone的设备名称

时间:2009-07-08 19:38:05

标签: ios uikit

如果您打开Settings -> General -> About,它会在屏幕顶部显示 Bob的iPhone 。你如何以编程方式获取该名称?

9 个答案:

答案 0 :(得分:179)

除上述答案外,这是实际代码:

[[UIDevice currentDevice] name];

答案 1 :(得分:167)

来自 UIDevice 类:

例如:[[UIDevice currentDevice] name];

  

UIDevice是一个提供的类   有关iPhone或iPod的信息   触摸设备。

     

提供的一些信息   UIDevice是静态的,例如设备   名称或系统版本。

来源:http://servin.com/iphone/uidevice/iPhone-UIDevice.html

官方文档: Apple Developer Documentation > UIDevice Class Reference

答案 2 :(得分:73)

夫特:

UIDevice.currentDevice().name

斯威夫特3:

UIDevice.current.name

答案 3 :(得分:11)

这是UIDevice的类结构

+ (UIDevice *)currentDevice;

@property(nonatomic,readonly,strong) NSString    *name;              // e.g. "My iPhone"
@property(nonatomic,readonly,strong) NSString    *model;             // e.g. @"iPhone", @"iPod touch"
@property(nonatomic,readonly,strong) NSString    *localizedModel;    // localized version of model
@property(nonatomic,readonly,strong) NSString    *systemName;        // e.g. @"iOS"
@property(nonatomic,readonly,strong) NSString    *systemVersion;

答案 4 :(得分:6)

对于xamarin用户,请使用此

UIKit.UIDevice.CurrentDevice.Name

答案 5 :(得分:4)

以编程方式获取iPhone的设备名称

 UIDevice *deviceInfo = [UIDevice currentDevice];

 NSLog(@"Device name:  %@", deviceInfo.name); 
  

// Device name: my iPod

答案 6 :(得分:2)

在Unity中,使用C#:

SystemInfo.deviceName;

答案 7 :(得分:0)

对于Swift 4+版本,请使用以下代码:

UIDevice.current.name

答案 8 :(得分:0)

对于swift4.0及更高版本,请使用以下代码:

    let udid = UIDevice.current.identifierForVendor?.uuidString
    let name = UIDevice.current.name
    let version = UIDevice.current.systemVersion
    let modelName = UIDevice.current.model
    let osName = UIDevice.current.systemName
    let localized = UIDevice.current.localizedModel
    
    print(udid ?? "")
    print(name)
    print(version)
    print(modelName)
    print(osName)
    print(localized)
相关问题