163

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?

Ali Abbas
  • 4,175
  • 1
  • 20
  • 40
Brandon O'Rourke
  • 23,405
  • 15
  • 53
  • 58

9 Answers9

210

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

Nikandr Marhal
  • 552
  • 1
  • 6
  • 9
Frank V
  • 24,427
  • 32
  • 102
  • 143
  • 2
    Be careful: the tutorial at that link, while quite useful, is aimed at OS 2.2, and uses some methods that are deprecated in 3.0. – Tim Jul 08 '09 at 19:49
  • @Tim: You are absolutely right. I didn't think of that. Though, I wasn't suggesting the tutorial; I was simply providing my source of information plus a source for more information. – Frank V Jul 08 '09 at 19:58
  • @FrankV What permissions should I request from the user in order to get myMusicAppName to change his Iphone name? How do I do that in Swift? Thank you – bibscy Jul 10 '19 at 10:01
182

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

[[UIDevice currentDevice] name];

Andreas Ley
  • 8,894
  • 1
  • 46
  • 55
Stickley
  • 4,382
  • 2
  • 29
  • 28
106

Remember: import UIKit

Swift:

UIDevice.currentDevice().name

Swift 3, 4, 5:

UIDevice.current.name
Byron Coetsee
  • 3,455
  • 4
  • 18
  • 30
14

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;
mfaani
  • 28,843
  • 15
  • 145
  • 252
Usman Nisar
  • 2,901
  • 32
  • 41
6

For xamarin user, use this

UIKit.UIDevice.CurrentDevice.Name
Tushar patel
  • 3,066
  • 2
  • 24
  • 28
6

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

UIDevice.current.name
Paul Roub
  • 35,848
  • 27
  • 79
  • 88
Neeraj Shukla
  • 295
  • 3
  • 9
5

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
Horacio
  • 1,523
  • 1
  • 15
  • 22
Kiran Patil
  • 360
  • 6
  • 13
4

To get an iPhone's device name programmatically

 UIDevice *deviceInfo = [UIDevice currentDevice];

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

// Device name: my iPod

pkamb
  • 30,595
  • 22
  • 143
  • 179
Teja Kumar Bethina
  • 3,376
  • 25
  • 33
1

In Unity, using C#:

SystemInfo.deviceName;
Ian
  • 27
  • 1