0
votes

I'm trying to get the device's User-Agent String - the ones listed here: http://www.enterpriseios.com/wiki/Complete_List_of_iOS_User_Agent_Strings

Here's the code I'm using:

UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectZero];
    NSString *uaString = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];

The result I'm getting is:

Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D201

What I want go get is:

Apple-iPhone4C1

How can I do that?

2

2 Answers

2
votes

You need to write a function which can generate this string like bellow:

#include sys/sysctl.h
#include sys/utsname.h

size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *model =  (char*) malloc(sizeof(size_t));
sysctlbyname("hw.machine", model, &size, NULL, 0);
NSString *deviceModel = [NSString stringWithCString:model encoding:NSUTF8StringEncoding];
NSLog(@"%@", deviceModel);

// or

struct utsname systemInfo;
uname(&systemInfo);
NSLog(@"%@", [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding]);
0
votes

For that you need to access methods of UIDevice class. model property of UIDevice class can give you such kind of information.