Get iPhone/iPad/iPod Touch hardware generation


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.