你如何获得iPhone的设备名称

Bra*_*rke 127 uikit ios

如果你打开Settings -> General -> About,它会说Bob的iPhone位于屏幕顶部.你如何以编程方式获取该名称?

Sti*_*ley 181

除了上面的答案,这是实际的代码:

[[UIDevice currentDevice] name];


Fra*_*k V 173

来自UIDevice班级:

举个例子: [[UIDevice currentDevice] name];

UIDevice是一个提供有关iPhone或iPod Touch设备的信息的类.

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

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

官方文档: Apple开发人员文档> UIDevice类参考

  • 注意:该链接上的教程虽然非常有用,但它针对的是OS 2.2,并使用了3.0中不推荐使用的一些方法. (2认同)

Byr*_*see 83

迅速:

UIDevice.currentDevice().name
Run Code Online (Sandbox Code Playgroud)

斯威夫特3:

UIDevice.current.name
Run Code Online (Sandbox Code Playgroud)

  • 必须有导入UIKit (2认同)

Usm*_*sar 12

这是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;
Run Code Online (Sandbox Code Playgroud)


paw*_*oon 12

不幸的是,从 iOS 16 开始,您需要特殊的权利。您可以在此处请求:https ://developer.apple.com/contact/request/user-signed-device-name/ 我


小智 10

对于 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 ?? "") // ABCDEF01-0123-ABCD-0123-ABCDEF012345
    print(name)       // Name's iPhone
    print(version)    // 14.5
    print(modelName)  // iPhone
    print(osName)     // iOS
    print(localized)  // iPhone
Run Code Online (Sandbox Code Playgroud)

  • UIDevice.current.name在iOS16(beta3)下不起作用,Apple再次更改。 (2认同)

Tus*_*tel 6

对于xamarin用户,请使用此选项

UIKit.UIDevice.CurrentDevice.Name
Run Code Online (Sandbox Code Playgroud)


Nee*_*kla 6

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

UIDevice.current.name
Run Code Online (Sandbox Code Playgroud)