Ios 你如何获得iPhone';s设备名
如果打开Ios 你如何获得iPhone';s设备名,ios,uikit,Ios,Uikit,如果打开Settings->General->About,屏幕顶部会显示鲍勃的iPhone。如何以编程方式获取该名称?来自UIDevice类: 例如:[[UIDevice currentDevice]名称] UIDevice是一个提供 有关iPhone或iPod的信息 触摸装置 由 UIDevice是静态的,例如device 名称或系统版本 资料来源: 官方文档:除了上述答案,这是实际代码: [[UIDevice currentDevice]名称]以编程方式获取iPhone的设备名称 UIDe
Settings->General->About
,屏幕顶部会显示鲍勃的iPhone。如何以编程方式获取该名称?来自UIDevice
类:
例如:[[UIDevice currentDevice]名称]代码>
UIDevice是一个提供
有关iPhone或iPod的信息
触摸装置
由
UIDevice是静态的,例如device
名称或系统版本
资料来源:
官方文档:除了上述答案,这是实际代码:
[[UIDevice currentDevice]名称]代码>以编程方式获取iPhone的设备名称
UIDevice *deviceInfo = [UIDevice currentDevice];
NSLog(@"Device name: %@", deviceInfo.name);
//设备名称:我的iPod
请记住:导入UIKit
斯威夫特:
UIDevice.currentDevice().name
Swift 3、4、5:
UIDevice.current.name
下面是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;
对于xamarin用户,请使用
UIKit.UIDevice.CurrentDevice.Name
在Unity中,使用C#:
对于Swift 4+版本,请使用以下代码:
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
UIDevice.current.name
对于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
请小心:该链接上的教程虽然非常有用,但它针对的是OS 2.2,并且使用了一些在3.0中不推荐使用的方法。@Tim:你完全正确。我没想到。尽管如此,我并不是在建议教程;我只是提供了我的信息来源和更多信息的来源。@FrankV为了让myMusicAppName更改他的Iphone名称,我应该向用户请求什么权限?我在斯威夫特怎么做?谢谢你必须导入UIKITSIFT 5.1:UIDevice.current.name是的,UIDevice.current.name在Swift 5中为我工作。同样地,我可以点击.model.batteryLevel等,谢谢!非常感谢。对于Swift 3:UIDevice.current.name