ios 如何获取 iPhone 的设备名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1100127/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you get an iPhone's device name
提问by Brandon O'Rourke
If you open Settings -> General -> About
, it'll say Bob's iPhoneat the top of the screen. How do you programmatically grab that name?
如果您打开Settings -> General -> About
,它会在屏幕顶部显示Bob 的 iPhone。您如何以编程方式获取该名称?
回答by Stickley
In addition to the above answer, this is the actual code:
除了上面的答案,这是实际的代码:
[[UIDevice currentDevice] name];
[[UIDevice currentDevice] name];
回答by Frank V
From the UIDevice
class:
从UIDevice
班级:
As an example: [[UIDevice currentDevice] name];
举个例子: [[UIDevice currentDevice] name];
The UIDevice is a class that provides information about the iPhone or iPod Touch device.
Some of the information provided by UIDevice is static, such as device name or system version.
UIDevice 是一个提供有关 iPhone 或 iPod Touch 设备信息的类。
UIDevice 提供的一些信息是静态的,例如设备名称或系统版本。
source: http://servin.com/iphone/uidevice/iPhone-UIDevice.html
来源:http: //servin.com/iphone/uidevice/iPhone-UIDevice.html
Offical Documentation:Apple Developer Documentation > UIDevice
Class Reference
回答by Byron Coetsee
Remember: import UIKit
记住: import UIKit
Swift:
迅速:
UIDevice.currentDevice().name
Swift 3, 4, 5:
斯威夫特 3、4、5:
UIDevice.current.name
回答by Usman Nisar
Here is class structure of UIDevice
这是 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;
回答by Tushar patel
For xamarin user, use this
对于 xamarin 用户,请使用此
UIKit.UIDevice.CurrentDevice.Name
回答by Teja Kumar Bethina
To get an iPhone's device name programmatically
以编程方式获取 iPhone 的设备名称
UIDevice *deviceInfo = [UIDevice currentDevice];
NSLog(@"Device name: %@", deviceInfo.name);
// Device name: my iPod
// Device name: my iPod
回答by Ian
In Unity, using C#:
在 Unity 中,使用 C#:
SystemInfo.deviceName;
回答by Neeraj Shukla
For Swift 4+ versions,please use the below code:
对于 Swift 4+ 版本,请使用以下代码:
UIDevice.current.name