Posted By

hafthor on 07/08/10


Tagged

iphone


Versions (?)

Who likes this?

7 people have marked this snippet as a favorite

umang_nine
bobbym245
rvachere
nsbuckner
Tintenklecks
gospaz
cnathan


Get iPhone/iPad/iPod Touch hardware generation


 / Published in: Objective C
 

  1. #include <sys/sysctl.h>
  2.  
  3. +(NSString *)getPlatform {
  4. size_t size=0;
  5. char *machine=NULL;
  6. for(;;) {
  7. sysctlbyname("hw.machine",machine,&size,NULL,0);
  8. if(!size) break;
  9. if(machine) {
  10. NSString *platform=[NSString stringWithUTF8String:machine];
  11. free(machine);
  12. return platform;
  13. }
  14. machine=malloc(size);
  15. if(!machine) break;
  16. }
  17. return nil;
  18. }
  19.  
  20. // optimistic version
  21.  
  22. +(NSString *)getPlatform {
  23. char machine[256];
  24. size_t size=sizeof(machine);
  25. sysctlbyname("hw.machine",machine,&size,NULL,0);
  26. return size>sizeof(machine) ? nil : [NSString stringWithUTF8String:machine];
  27. }

Report this snippet  

You need to login to post a comment.