@implem...">
美文网首页iOS
iOS获取设备 电池-内存-磁盘信息

iOS获取设备 电池-内存-磁盘信息

作者: NieFeng1024 | 来源:发表于2017-02-06 15:02 被阅读47次

    import "UIDevice+Category.h"

    import <sys/mount.h>

    @implementation UIDevice (Category)

    • (CGFloat)deviceGetBatteryQuantity {

      [UIDevice currentDevice].batteryMonitoringEnabled = YES;

      return ([[UIDevice currentDevice] batteryLevel]) * 100;
      }

    • (long long)deviceGetTotalMemorySize {

      return [NSProcessInfo processInfo].physicalMemory;
      }

    • (long long)deviceGetTotalDiskSize {
      struct statfs buf;
      unsigned long long freeSpace = -1;
      if (statfs("/var", &buf) >= 0)
      {
      freeSpace = (unsigned long long)(buf.f_bsize * buf.f_blocks);
      }
      return freeSpace;
      }

    • (long long)deviceGetAvailableDiskSize {
      struct statfs buf;
      unsigned long long freeSpace = -1;
      if (statfs("/var", &buf) >= 0)
      {
      freeSpace = (unsigned long long)(buf.f_bsize * buf.f_bavail);
      }
      return freeSpace;
      }

    /******************************/

    import "ViewController.h"

    import "UIDevice+Category.h"

    @interface ViewController ()

    @end

    @implementation ViewController

    • (void)viewDidLoad {
      [super viewDidLoad];

      CGFloat battery = [UIDevice deviceGetBatteryQuantity];

      long long memorySize = [UIDevice deviceGetTotalMemorySize];

      long long diskSize = [UIDevice deviceGetTotalDiskSize];

      long long availableDiskSize = [UIDevice deviceGetAvailableDiskSize];

      NSLog(@"\n battery:%f \n memorySize:%lld \n diskSize:%lld \n availableDiskSize:%lld ",battery,memorySize,diskSize,availableDiskSize);
      /**
      battery:100.000000
      memorySize:1048576000
      diskSize:12075704320
      availableDiskSize:3585474560
      */
      }

    Demo https://github.com/550872569/UIDeviceCategory.git

    相关文章

      网友评论

        本文标题:iOS获取设备 电池-内存-磁盘信息

        本文链接:https://www.haomeiwen.com/subject/mnfuittx.html