UIDevice+SpeedCategory.m 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // UIDevice+SpeedCategory.m
  3. // VLC for iOS
  4. //
  5. // Created by Felix Paul Kühne on 22.06.13.
  6. // Copyright (c) 2013 VideoLAN. All rights reserved.
  7. //
  8. // Refer to the COPYING file of the official project for license.
  9. //
  10. #import "UIDevice+SpeedCategory.h"
  11. #import <sys/sysctl.h> // for sysctlbyname
  12. @implementation UIDevice (SpeedCategory)
  13. - (int)speedCategory
  14. {
  15. size_t size;
  16. sysctlbyname("hw.machine", NULL, &size, NULL, 0);
  17. char *answer = malloc(size);
  18. sysctlbyname("hw.machine", answer, &size, NULL, 0);
  19. NSString *currentMachine = @(answer);
  20. free(answer);
  21. if ([currentMachine hasPrefix:@"iPhone2"] || [currentMachine hasPrefix:@"iPhone3"] || [currentMachine hasPrefix:@"iPad1"] || [currentMachine hasPrefix:@"iPod3"] || [currentMachine hasPrefix:@"iPod4"]) {
  22. // iPhone 3GS, iPhone 4, first gen. iPad, 3rd and 4th generation iPod touch
  23. APLog(@"this is a cat one device");
  24. return 1;
  25. } 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"]) {
  26. // iPhone 4S, iPad 2 and 3, iPod 4 and 5
  27. APLog(@"this is a cat two device");
  28. return 2;
  29. } else {
  30. // iPhone 5, iPad 4
  31. APLog(@"this is a cat three device");
  32. return 3;
  33. }
  34. }
  35. @end