UIDevice+VLC.m 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*****************************************************************************
  2. * UIDevice+VLC
  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+VLC.h"
  13. #import <sys/sysctl.h> // for sysctlbyname
  14. int _currentSpeedCategory;
  15. @implementation UIDevice (VLC)
  16. - (int)VLCSpeedCategory
  17. {
  18. if (_currentSpeedCategory != 0) {
  19. return _currentSpeedCategory;
  20. }
  21. size_t size;
  22. sysctlbyname("hw.machine", NULL, &size, NULL, 0);
  23. char *answer = malloc(size);
  24. sysctlbyname("hw.machine", answer, &size, NULL, 0);
  25. NSString *currentMachine = @(answer);
  26. free(answer);
  27. if ([currentMachine hasPrefix:@"iPhone2"] || [currentMachine hasPrefix:@"iPhone3"] || [currentMachine hasPrefix:@"iPad1"] || [currentMachine hasPrefix:@"iPod3"] || [currentMachine hasPrefix:@"iPod4"]) {
  28. // iPhone 4, 4th generation iPod touch
  29. APLog(@"this is a cat one device");
  30. _currentSpeedCategory = 1;
  31. } 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"]) {
  32. // iPhone 4S, iPad 2 and 3, iPod 4 and 5
  33. APLog(@"this is a cat two device");
  34. _currentSpeedCategory = 2;
  35. } else if ([currentMachine hasPrefix:@"iPhone5"] || [currentMachine hasPrefix:@"iPhone6"] || [currentMachine hasPrefix:@"iPad4"]) {
  36. // iPhone 5 + 5S, iPad 4, iPad Air, iPad mini 2G
  37. APLog(@"this is a cat three device");
  38. _currentSpeedCategory = 3;
  39. } else {
  40. // iPhone 6 + 6S, 2014+2015 iPads
  41. APLog(@"this is a cat four device");
  42. _currentSpeedCategory = 4;
  43. }
  44. return _currentSpeedCategory;
  45. }
  46. - (NSNumber *)VLCFreeDiskSpace
  47. {
  48. NSNumber *totalSpace;
  49. NSNumber *totalFreeSpace;
  50. NSError *error = nil;
  51. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  52. NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
  53. if (!error) {
  54. totalSpace = [dictionary objectForKey:NSFileSystemSize];
  55. totalFreeSpace = [dictionary objectForKey:NSFileSystemFreeSize];
  56. NSString *totalSize = [NSByteCountFormatter stringFromByteCount:[totalSpace longLongValue] countStyle:NSByteCountFormatterCountStyleFile];
  57. NSString *totalFreeSize = [NSByteCountFormatter stringFromByteCount:[totalFreeSpace longLongValue] countStyle:NSByteCountFormatterCountStyleFile];
  58. APLog(@"Memory Capacity of %@ with %@ Free memory available.", totalSize, totalFreeSize);
  59. } else
  60. APLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %ld", [error domain], (long)[error code]);
  61. return totalFreeSpace;
  62. }
  63. - (BOOL)VLCHasExternalDisplay
  64. {
  65. return ([[UIScreen screens] count] > 1);
  66. }
  67. @end