UIDevice+VLC.m 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. @implementation UIDevice (VLC)
  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. NSString *totalSize = [NSByteCountFormatter stringFromByteCount:[totalSpace longLongValue] countStyle:NSByteCountFormatterCountStyleFile];
  52. NSString *totalFreeSize = [NSByteCountFormatter stringFromByteCount:[totalFreeSpace longLongValue] countStyle:NSByteCountFormatterCountStyleFile];
  53. APLog(@"Memory Capacity of %@ with %@ Free memory available.", totalSize, totalFreeSize);
  54. } else
  55. APLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %ld", [error domain], (long)[error code]);
  56. return totalFreeSpace;
  57. }
  58. - (BOOL)hasExternalDisplay
  59. {
  60. return ([[UIScreen screens] count] > 1);
  61. }
  62. @end