For Swift 4+ versions, please use the below code:
UIDevice.current.name
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 ?? "")
print(name)
print(version)
print(modelName)
print(osName)
print(localized)
Remember: import UIKit
Swift:
UIDevice.currentDevice().name
Swift 3, 4, 5:
UIDevice.current.name
In Unity, using C#:
SystemInfo.deviceName;
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;
In addition to the above answer, this is the actual code:
[[UIDevice currentDevice] name];
For xamarin user, use this
UIKit.UIDevice.CurrentDevice.Name
To get an iPhone's device name programmatically
UIDevice *deviceInfo = [UIDevice currentDevice];
NSLog(@"Device name: %@", deviceInfo.name);
// Device name: my iPod
Source: Stackoverflow.com