IOS获取设备信息 - 新闻资讯 - 云南小程序开发|云南软件开发|云南网站建设-昆明葵宇信息科技有限公司

159-8711-8523

云南网建设/小程序开发/软件开发

知识

不管是网站,软件还是小程序,都要直接或间接能为您产生价值,我们在追求其视觉表现的同时,更侧重于功能的便捷,营销的便利,运营的高效,让网站成为营销工具,让软件能切实提升企业内部管理水平和效率。优秀的程序为后期升级提供便捷的支持!

您当前位置>首页 » 新闻资讯 » 技术分享 >

IOS获取设备信息

发表时间:2020-10-19

发布人:葵宇科技

浏览次数:60

概要


IOS获取设备信息一般是经由过程UIDevice,UIScreen,NSBundle,NSLocal等方法,如不雅说要获取设备的内存、处理器信息,似乎可以按照Unix获取类似信息方法。
UIDevice供给了多种属性、类函数及状况通知,包含检测电池电量和定位设备与邻近感应,UIDevice所做的工作就是为应用法度榜样供给用户及设备的一些信息。UIDevice类还可以或许收集关于设备的各类具体细节,例如机型及iOS版本等。个中大年夜部分属性都对开辟工作具有积极的帮助感化

代码示例

- (void) getDeviceInfo
{
    UIDevice* curDev = [UIDevice currentDevice];
    
    /** 设备体系信息*/
    
    // 设备名称
    NSLog(@"\tname        : %@", curDev.name);
    // 设备模式
    NSLog(@"\tmodel       : %@", curDev.model);
    // 设备本地模式
    NSLog(@"\tlocalize    : %@", curDev.localizedModel);
    // 体系名称
    NSLog(@"\tos name     : %@", curDev.systemName);
    // 体系版本号
    NSLog(@"\tos version  : %@", curDev.systemVersion);
    // 设备类别:手机,平板电脑
    switch (curDev.userInterfaceIdiom)
    {
        case UIUserInterfaceIdiomPhone:
            NSLog(@"\tIdiom       : iPhone");
            break;
        case UIUserInterfaceIdiomPad:
            NSLog(@"\tIdiom       : iPad");
            break;
            
        default:
            NSLog(@"\tIdiom       : Unknow");
            break;
    }
    // 设备独一标识
    NSLog(@"\tUUID        : %@", curDev.identifierForVendor.UUIDString);
    
    /** 设备偏向 */
    // 设备朝向
    switch (curDev.orientation)
    {
        case UIDeviceOrientationPortrait:
            NSLog(@"\torientation : Portrait");
            break;
        case UIDeviceOrientationPortraitUpsideDown:
            NSLog(@"\torientation : upside down");
            break;
        case UIDeviceOrientationLandscapeLeft:
            NSLog(@"\torientation : left");
            break;
        case UIDeviceOrientationLandscapeRight:
            NSLog(@"\torientation : right");
            break;
        case UIDeviceOrientationFaceUp:
            NSLog(@"\torientation : face up");
            break;
        case UIDeviceOrientationFaceDown:
            NSLog(@"\torientation : face down");
            break;
        default:
            NSLog(@"\torientation : Unknow");
            break;
    }
    
    UIScreen* mainScreen = [UIScreen mainScreen];
    // 屏幕尺寸
    NSLog(@"screen size : %.0fx%.0f", mainScreen.bounds.size.width, mainScreen.bounds.size.height);
    
    /** 设备电池 */
    NSLog(@"Battery infomation");
    
    // 电量
    NSLog(@"\tlevel       : %.2f%%", curDev.batteryLevel*100);
    switch (curDev.batteryState)
    {
        case UIDeviceBatteryStateUnplugged:
            NSLog(@"\tstate       : Unplugged");
            break;
        case UIDeviceBatteryStateCharging:
            NSLog(@"\tstate       : Charging");
            break;
        case UIDeviceBatteryStateFull:
            NSLog(@"\tstate       : Full");
            break;
        default:
            NSLog(@"\tstate       : Unknow");
            break;
    }
    
    // 电池监督器是否开启
    if( curDev.isBatteryMonitoringEnabled )
    {
        NSLog(@"\tmonitor on  : YES");
    }
    else
    {
        NSLog(@"\tmonitor on  : NO");
    }
    
    /** 体感器 */
    NSLog(@"Proximity Sensor infomation");
    if( curDev.proximityState )
    {
        NSLog(@"\tsensor on   : YES");
    }
    else
    {
        NSLog(@"\tsensor on   : NO");
    }
    if(curDev.proximityMonitoringEnabled)
    {
        NSLog(@"\tmonitor on  : YES");
    }
    else
    {
        NSLog(@"\tmonitor on  : NO");
    }
}

- (void) getBundleInfo
{
    NSBundle* bundle = [NSBundle mainBundle];
    NSDictionary* bundleInfo = [bundle infoDictionary];
    
    // 应用信息
    NSLog(@"%@", bundleInfo);
    
    /*
    CFBundleDevelopmentRegion = en;
    CFBundleExecutable = DeviceInfo;
    CFBundleIdentifier = "arbboter.com.DeviceInfo";
    CFBundleInfoDictionaryVersion = "6.0";
    CFBundleInfoPlistURL = "Info.plist -- file:///../DeviceInfo.app/";
    CFBundleName = DeviceInfo;
    CFBundleNumericVersion = 16809984;
    CFBundlePackageType = APPL;
    CFBundleShortVersionString = "1.0";
    CFBundleSignature = "????";
    CFBundleSupportedPlatforms =     (
                                      iPhoneSimulator
                                      );
    CFBundleVersion = 1;
    DTPlatformName = iphonesimulator;
    DTSDKName = "iphonesimulator8.1";
    LSRequiresIPhoneOS = 1;
    UIDeviceFamily =     (
                          1
                          );
    UILaunchStoryboardName = LaunchScreen;
    UIMainStoryboardFile = Main;
    UIRequiredDeviceCapabilities =     (
                                        armv7
                                        );
    UISupportedInterfaceOrientations =     (
                                            UIInterfaceOrientationPortrait,
                                            UIInterfaceOrientationLandscapeLeft,
                                            UIInterfaceOrientationLandscapeRight
                                            );
    */
}


相关案例查看更多