您如何获得iPhone的设备名称

问题描述 投票:128回答:8

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

ios uikit
8个回答
173
投票

来自UIDevice类:

例如:[[UIDevice currentDevice] name];

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

[某些信息由UIDevice是静态的,例如设备名称或系统版本。

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

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


181
投票

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

UIDevice


84
投票

记住:[[UIDevice currentDevice] name];

Swift:

import UIKit

[快速3、4、5:

UIDevice.currentDevice().name

12
投票

这里是UIDevice的类结构

UIDevice.current.name

6
投票

对于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;

4
投票

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

UIKit.UIDevice.CurrentDevice.Name

UIDevice *deviceInfo = [UIDevice currentDevice]; NSLog(@"Device name: %@", deviceInfo.name);


3
投票

在Unity中,使用C#:

// Device name:  my iPod

2
投票

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

SystemInfo.deviceName;
© www.soinside.com 2019 - 2024. All rights reserved.