How do you get an iPhone's device name

前端 未结 9 1559
我在风中等你
我在风中等你 2020-11-29 22:26

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?

相关标签:
9条回答
  • 2020-11-29 23:05

    For xamarin user, use this

    UIKit.UIDevice.CurrentDevice.Name
    
    0 讨论(0)
  • 2020-11-29 23:09

    From the UIDevice class:

    As an example: [[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

    0 讨论(0)
  • 2020-11-29 23:10

    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;
    
    0 讨论(0)
  • 2020-11-29 23:21

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

    [[UIDevice currentDevice] name];

    0 讨论(0)
  • 2020-11-29 23:21

    To get an iPhone's device name programmatically

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

    // Device name: my iPod

    0 讨论(0)
  • 2020-11-29 23:23

    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)
    
    0 讨论(0)
提交回复
热议问题