How do you get an iPhone's device name

IosUikit

Ios Problem Overview


If you open Settings -> General -> About, it'll say Bob's iPhone at the top of the screen. How do you programmatically grab that name?

Ios Solutions


Solution 1 - Ios

From the UIDevice class:

Swift version:

UIDevice.current.name

Objective-C version:

[[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.

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

Offical Documentation: Apple Developer Documentation > UIDevice Class Reference

Solution 2 - Ios

In addition to the above answer, this is the actual code:

[[UIDevice currentDevice] name];

Solution 3 - Ios

Remember: import UIKit

Swift:

UIDevice.currentDevice().name

Swift 3, 4, 5:

UIDevice.current.name

Solution 4 - Ios

Here is class structure of 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;

Solution 5 - Ios

For xamarin user, use this

UIKit.UIDevice.CurrentDevice.Name

Solution 6 - Ios

For Swift 4+ versions, please use the below code:

UIDevice.current.name

Solution 7 - Ios

For swift4.0 and above used below code:

    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

Solution 8 - Ios

To get an iPhone's device name programmatically

 UIDevice *deviceInfo = [UIDevice currentDevice];

 NSLog(@"Device name:  %@", deviceInfo.name); 

> // Device name: my iPod

Solution 9 - Ios

In Unity, using C#:

SystemInfo.deviceName;

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBrandon O'RourkeView Question on Stackoverflow
Solution 1 - IosFrank VView Answer on Stackoverflow
Solution 2 - IosStickleyView Answer on Stackoverflow
Solution 3 - IosByron CoetseeView Answer on Stackoverflow
Solution 4 - IosUsman NisarView Answer on Stackoverflow
Solution 5 - IosTushar patelView Answer on Stackoverflow
Solution 6 - IosNeeraj ShuklaView Answer on Stackoverflow
Solution 7 - IosKiran PatilView Answer on Stackoverflow
Solution 8 - IosTeja Kumar BethinaView Answer on Stackoverflow
Solution 9 - IosIanView Answer on Stackoverflow