UIDevice+SpeedCategory.m 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*****************************************************************************
  2. * UIDevice+SpeedCategory.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. #import "UIDevice+SpeedCategory.h"
  13. #import <sys/sysctl.h> // for sysctlbyname
  14. @implementation UIDevice (SpeedCategory)
  15. - (int)speedCategory
  16. {
  17. size_t size;
  18. sysctlbyname("hw.machine", NULL, &size, NULL, 0);
  19. char *answer = malloc(size);
  20. sysctlbyname("hw.machine", answer, &size, NULL, 0);
  21. NSString *currentMachine = @(answer);
  22. free(answer);
  23. if ([currentMachine hasPrefix:@"iPhone2"] || [currentMachine hasPrefix:@"iPhone3"] || [currentMachine hasPrefix:@"iPad1"] || [currentMachine hasPrefix:@"iPod3"] || [currentMachine hasPrefix:@"iPod4"]) {
  24. // iPhone 3GS, iPhone 4, first gen. iPad, 3rd and 4th generation iPod touch
  25. APLog(@"this is a cat one device");
  26. return 1;
  27. } else if ([currentMachine hasPrefix:@"iPhone4"] || [currentMachine hasPrefix:@"iPad3,1"] || [currentMachine hasPrefix:@"iPad3,2"] || [currentMachine hasPrefix:@"iPad3,3"] || [currentMachine hasPrefix:@"iPod4"] || [currentMachine hasPrefix:@"iPad2"] || [currentMachine hasPrefix:@"iPod5"]) {
  28. // iPhone 4S, iPad 2 and 3, iPod 4 and 5
  29. APLog(@"this is a cat two device");
  30. return 2;
  31. } else if ([currentMachine hasPrefix:@"iPhone5"] || [currentMachine hasPrefix:@"iPhone6"] || [currentMachine hasPrefix:@"iPad4"]) {
  32. // iPhone 5 + 5S, iPad 4, iPad Air, iPad mini 2G
  33. APLog(@"this is a cat three device");
  34. return 3;
  35. } else {
  36. // iPhone 6, 2014 iPads
  37. APLog(@"this is a cat four device");
  38. return 4;
  39. }
  40. }
  41. - (NSNumber *)freeDiskspace
  42. {
  43. NSNumber *totalSpace;
  44. NSNumber *totalFreeSpace;
  45. NSError *error = nil;
  46. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  47. NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
  48. if (!error) {
  49. totalSpace = [dictionary objectForKey: NSFileSystemSize];
  50. totalFreeSpace = [dictionary objectForKey:NSFileSystemFreeSize];
  51. APLog(@"Memory Capacity of %llu MiB with %llu MiB Free memory available.", (([totalSpace unsignedLongLongValue]/1024ll)/1024ll), (([totalFreeSpace unsignedLongLongValue]/1024ll)/1024ll));
  52. } else
  53. APLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %i", [error domain], [error code]);
  54. return totalFreeSpace;
  55. }
  56. @end