Skip to content

Commit cd7abea

Browse files
committed
Initial commit.
0 parents  commit cd7abea

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

Diff for: LICENCE.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2012 Paul Williamson
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Diff for: README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Description
2+
UIDeviceHardware is a class originally created in a [gist](https://gist.github.com/1323251) by [Jaybles](https://github.com/Jaybles). It allows querying of the current users device, and returns a human formatted string.
3+
4+
It is written as a class method, to allow use without direct instantiation.
5+
6+
## Usage
7+
To use this class, copy the class header files, or include the class in your Cocoapods Podfile. Then when you are ready to query the device, simply import the header file and use:
8+
9+
```
10+
NSString *currentDevice = [UIDeviceHardware platformString];
11+
```
12+
13+
## Licence
14+
UIDeviceHardware is available under the MIT license. See the LICENSE file for more info.

Diff for: UIDeviceIdentifier/UIDeviceHardware.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// UIDeviceHardware.h
3+
//
4+
// Created by Paul Williamson on 9/12/2012
5+
// https://github.com/squarefrog/UIDeviceIdentifier
6+
//
7+
8+
#import <Foundation/Foundation.h>
9+
10+
@interface UIDeviceHardware : NSObject
11+
12+
+ (NSString *) platform;
13+
+ (NSString *) platformString;
14+
15+
@end

Diff for: UIDeviceIdentifier/UIDeviceHardware.m

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// UIDeviceHardware.m
3+
//
4+
// Created by Paul Williamson on 9/12/2012
5+
// https://github.com/squarefrog/UIDeviceIdentifier
6+
//
7+
8+
#import "UIDeviceHardware.h"
9+
#include <sys/types.h>
10+
#include <sys/sysctl.h>
11+
12+
@implementation UIDeviceHardware
13+
14+
+ (NSString *) platform{
15+
size_t size;
16+
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
17+
char *machine = malloc(size);
18+
sysctlbyname("hw.machine", machine, &size, NULL, 0);
19+
NSString *platform = [NSString stringWithUTF8String:machine];
20+
free(machine);
21+
return platform;
22+
}
23+
24+
+ (NSString *) platformString{
25+
NSString *platform = [self platform];
26+
if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 1G";
27+
if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
28+
if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
29+
if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4 (GSM)";
30+
if ([platform isEqualToString:@"iPhone3,3"]) return @"iPhone 4 (CDMA)";
31+
if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone 4S";
32+
if ([platform isEqualToString:@"iPhone5,1"]) return @"iPhone 5 (GSM)";
33+
if ([platform isEqualToString:@"iPhone5,2"]) return @"iPhone 5 (CDMA)";
34+
if ([platform isEqualToString:@"iPod1,1"]) return @"iPod Touch 1G";
35+
if ([platform isEqualToString:@"iPod2,1"]) return @"iPod Touch 2G";
36+
if ([platform isEqualToString:@"iPod3,1"]) return @"iPod Touch 3G";
37+
if ([platform isEqualToString:@"iPod4,1"]) return @"iPod Touch 4G";
38+
if ([platform isEqualToString:@"iPod5,1"]) return @"iPod Touch 5G";
39+
if ([platform isEqualToString:@"iPad1,1"]) return @"iPad";
40+
if ([platform isEqualToString:@"iPad2,1"]) return @"iPad 2 (WiFi)";
41+
if ([platform isEqualToString:@"iPad2,2"]) return @"iPad 2 (GSM)";
42+
if ([platform isEqualToString:@"iPad2,3"]) return @"iPad 2 (CDMA)";
43+
if ([platform isEqualToString:@"iPad2,5"]) return @"iPad Mini (WiFi)";
44+
if ([platform isEqualToString:@"iPad2,6"]) return @"iPad Mini (GSM)";
45+
if ([platform isEqualToString:@"iPad2,7"]) return @"iPad Mini (CDMA)";
46+
if ([platform isEqualToString:@"iPad3,1"]) return @"iPad 3 (WiFi)";
47+
if ([platform isEqualToString:@"iPad3,2"]) return @"iPad 3 (CDMA)";
48+
if ([platform isEqualToString:@"iPad3,3"]) return @"iPad 3 (GSM)";
49+
if ([platform isEqualToString:@"iPad3,4"]) return @"iPad 4 (WiFi)";
50+
if ([platform isEqualToString:@"iPad3,5"]) return @"iPad 4 (GSM)";
51+
if ([platform isEqualToString:@"iPad3,6"]) return @"iPad 4 (CDMA)";
52+
if ([platform isEqualToString:@"i386"]) return @"Simulator";
53+
if ([platform isEqualToString:@"x86_64"]) return @"Simulator";
54+
return platform;
55+
}
56+
57+
@end

0 commit comments

Comments
 (0)