如果您打开Settings -> General -> About
,则会在屏幕顶部显示Bob的iPhone。您如何以编程方式获取该名称?
来自UIDevice
类:
例如:[[UIDevice currentDevice] name];
UIDevice是一个提供以下内容的类有关iPhone或iPod的信息触摸设备。
[某些信息由UIDevice是静态的,例如设备名称或系统版本。
来源:http://servin.com/iphone/uidevice/iPhone-UIDevice.html
官方文档: Apple Developer Documentation > UIDevice
Class Reference
除了上面的答案,这是实际的代码:
UIDevice
记住:[[UIDevice currentDevice] name];
Swift:
import UIKit
[快速3、4、5:
UIDevice.currentDevice().name
这里是UIDevice的类结构
UIDevice.current.name
对于xamarin用户,请使用此
+ (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;
以编程方式获取iPhone的设备名称
UIKit.UIDevice.CurrentDevice.Name
UIDevice *deviceInfo = [UIDevice currentDevice]; NSLog(@"Device name: %@", deviceInfo.name);
在Unity中,使用C#:
// Device name: my iPod
对于Swift 4+版本,请使用以下代码:
SystemInfo.deviceName;