UIDevice+SpeedCategory.m 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*****************************************************************************
  2. * UIDevice+SpeedCategory.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013 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 {
  32. // iPhone 5, iPad 4
  33. APLog(@"this is a cat three device");
  34. return 3;
  35. }
  36. }
  37. @end