/libs/ObjectAL/Support/IOSVersion.m

http://github.com/kstenerud/ObjectAL-for-iPhone · Objective C · 53 lines · 36 code · 11 blank · 6 comment · 12 complexity · a8e3f8463b3ef2fb5bf7ed40ab746bad MD5 · raw file

  1. //
  2. // IOSVersion.m
  3. // ObjectiveGems
  4. //
  5. // Created by Karl Stenerud on 10-11-07.
  6. //
  7. #import "IOSVersion.h"
  8. #import <UIKit/UIKit.h>
  9. SYNTHESIZE_SINGLETON_FOR_CLASS_PROTOTYPE(IOSVersion);
  10. @implementation IOSVersion
  11. SYNTHESIZE_SINGLETON_FOR_CLASS(IOSVersion);
  12. - (id) init
  13. {
  14. if(nil != (self = [super init]))
  15. {
  16. NSString* versionStr = [[UIDevice currentDevice] systemVersion];
  17. unichar ch = [versionStr characterAtIndex:0];
  18. if(ch < '0' || ch > '9' || [versionStr characterAtIndex:1] != '.')
  19. {
  20. NSLog(@"Error: %s: Cannot parse iOS version string \"%@\"", __PRETTY_FUNCTION__, versionStr);
  21. }
  22. version = (float)(ch - '0');
  23. float multiplier = 0.1f;
  24. unsigned int vLength = [versionStr length];
  25. for(unsigned int i = 2; i < vLength; i++)
  26. {
  27. ch = [versionStr characterAtIndex:i];
  28. if(ch >= '0' && ch <= '9')
  29. {
  30. version += (ch - '0') * multiplier;
  31. multiplier /= 10;
  32. }
  33. else if('.' != ch)
  34. {
  35. break;
  36. }
  37. }
  38. }
  39. return self;
  40. }
  41. @synthesize version;
  42. @end