UIDevice+VLC.m 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*****************************************************************************
  2. * UIDevice+VLC
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013-2017 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. * Carola Nitz <caro # videolan.org>
  10. *
  11. * Refer to the COPYING file of the official project for license.
  12. *****************************************************************************/
  13. #import "UIDevice+VLC.h"
  14. #import <sys/sysctl.h> // for sysctlbyname
  15. @implementation UIDevice (VLC)
  16. VLCSpeedCategory _currentSpeedCategory;
  17. - (VLCSpeedCategory)vlcSpeedCategory
  18. {
  19. if (_currentSpeedCategory == VLCSpeedCategoryNotSet) {
  20. size_t size;
  21. sysctlbyname("hw.machine", NULL, &size, NULL, 0);
  22. char *answer = malloc(size);
  23. sysctlbyname("hw.machine", answer, &size, NULL, 0);
  24. NSString *currentMachine = @(answer);
  25. free(answer);
  26. 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"]) {
  27. APLog(@"this is a cat two device");
  28. _currentSpeedCategory = VLCSpeedCategoryTwoDevices;
  29. } else if ([currentMachine hasPrefix:@"iPhone5"] || [currentMachine hasPrefix:@"iPhone6"] || [currentMachine hasPrefix:@"iPad4"]) {
  30. APLog(@"this is a cat three device");
  31. _currentSpeedCategory = VLCSpeedCategoryThreeDevices;
  32. } else {
  33. APLog(@"this is a cat four device");
  34. _currentSpeedCategory = VLCSpeedCategoryFourDevices;
  35. }
  36. }
  37. return _currentSpeedCategory;
  38. }
  39. - (NSNumber *)VLCFreeDiskSpace
  40. {
  41. NSNumber *totalSpace;
  42. NSNumber *totalFreeSpace;
  43. NSError *error = nil;
  44. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  45. NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
  46. if (!error) {
  47. totalSpace = [dictionary objectForKey:NSFileSystemSize];
  48. totalFreeSpace = [dictionary objectForKey:NSFileSystemFreeSize];
  49. NSString *totalSize = [NSByteCountFormatter stringFromByteCount:[totalSpace longLongValue] countStyle:NSByteCountFormatterCountStyleFile];
  50. NSString *totalFreeSize = [NSByteCountFormatter stringFromByteCount:[totalFreeSpace longLongValue] countStyle:NSByteCountFormatterCountStyleFile];
  51. APLog(@"Memory Capacity of %@ with %@ Free memory available.", totalSize, totalFreeSize);
  52. } else
  53. APLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %ld", [error domain], (long)[error code]);
  54. return totalFreeSpace;
  55. }
  56. - (BOOL)VLCHasExternalDisplay
  57. {
  58. return ([[UIScreen screens] count] > 1);
  59. }
  60. @end