1

After looking on SO in to how to detect users device here: iOS - How to get device make and model?

I made a quick test app to display an alert depending on device. I get no alert from this code. What am I missing/doing wrong here?

#import "ViewController.h"
#import <sys/utsname.h>

 NSString* machineName()
{
struct utsname systemInfo;
uname(&systemInfo);

return [NSString stringWithCString:systemInfo.machine
                          encoding:NSUTF8StringEncoding];
}



@interface ViewController ()


@end




- (IBAction)btn:(id)sender {

if ([machineName() isEqualToString:@"iPhone5,1"]){


    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Checking device iphone5" delegate:nil cancelButtonTitle: @"Ok" otherButtonTitles: nil];

    [alert show];




    } else  if ([machineName() isEqualToString:@"iPhone4,1"]){



    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Checking device iphone4" delegate:nil cancelButtonTitle: @"Ok" otherButtonTitles: nil];

    [alert show];

     }


  }
Community
  • 1
  • 1
JSA986
  • 5,870
  • 9
  • 45
  • 91

1 Answers1

1

The machine field of struct utsname is the machine hardware platform and that is "x86_64" if the program is running in the iOS Simulator.

Only on a real device you will get strings like "iPhone5,1".

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382