Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated Hardware quite a bit. Got rid of platform code, added new dev…

…ices (including presumed ones), cleaned things up. If you have any UIDevice requests, pulls, suggestions, now is the time to get them to me. Working on this chapter right now.
  • Loading branch information...
commit 8f40fe56321d0c097df774a20221c48a0bd01278 1 parent a4910bd
Erica Sadun authored
6 HelloWorld.xcodeproj/project.pbxproj
View
@@ -34,8 +34,7 @@
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
32CA4F630368D1EE00C91783 /* HelloWorld_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HelloWorld_Prefix.pch; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
- 8E03075212382206000616A0 /* 40frameworks */ = {isa = PBXFileReference; lastKnownFileType = text; name = 40frameworks; path = /Users/ericasadun/40frameworks; sourceTree = "<absolute>"; };
- 8E03075412382230000616A0 /* GraphicsServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GraphicsServices.framework; path = /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.1.sdk/System/Library/PrivateFrameworks/GraphicsServices.framework; sourceTree = "<absolute>"; };
+ 8E03075412382230000616A0 /* GraphicsServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GraphicsServices.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.1.sdk/System/Library/PrivateFrameworks/GraphicsServices.framework; sourceTree = DEVELOPER_DIR; };
8E278431101E6BCE002772F5 /* wwanconnect.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = wwanconnect.c; path = "Apple Sample Code/wwanconnect.c"; sourceTree = "<group>"; };
8E278432101E6BCE002772F5 /* wwanconnect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = wwanconnect.h; path = "Apple Sample Code/wwanconnect.h"; sourceTree = "<group>"; };
8E3A1F080FAA199F009B0518 /* cover320x416.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = cover320x416.png; sourceTree = "<group>"; };
@@ -101,8 +100,6 @@
8EB688610FA64AD100489E4B /* Support */,
29B97323FDCFA39411CA2CEA /* Frameworks */,
19C28FACFE9D520D11CA2CBB /* Products */,
- 8E03075212382206000616A0 /* 40frameworks */,
- 8E03075412382230000616A0 /* GraphicsServices.framework */,
);
name = CustomTemplate;
sourceTree = "<group>";
@@ -110,6 +107,7 @@
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
isa = PBXGroup;
children = (
+ 8E03075412382230000616A0 /* GraphicsServices.framework */,
8E7EA6621028A1A7004DB9E8 /* IOKit.framework */,
8E9B2372101E2D3A005DB65B /* SystemConfiguration.framework */,
1D3623EB0D0F72F000981E51 /* CoreGraphics.framework */,
100 UIDevice-Hardware.h
View
@@ -1,66 +1,69 @@
/*
Erica Sadun, http://ericasadun.com
- iPhone Developer's Cookbook, 3.0 Edition
+ iPhone Developer's Cookbook, 5.0 Edition
BSD License, Use at your own risk
*/
#import <UIKit/UIKit.h>
-#define IFPGA_NAMESTRING @"iFPGA"
+#define IFPGA_NAMESTRING @"iFPGA"
-#define IPHONE_1G_NAMESTRING @"iPhone 1G"
-#define IPHONE_3G_NAMESTRING @"iPhone 3G"
-#define IPHONE_3GS_NAMESTRING @"iPhone 3GS"
-#define IPHONE_4_NAMESTRING @"iPhone 4"
-#define IPHONE_5_NAMESTRING @"iPhone 5"
-#define IPHONE_UNKNOWN_NAMESTRING @"Unknown iPhone"
+#define IPHONE_1G_NAMESTRING @"iPhone 1G"
+#define IPHONE_3G_NAMESTRING @"iPhone 3G"
+#define IPHONE_3GS_NAMESTRING @"iPhone 3GS"
+#define IPHONE_4_NAMESTRING @"iPhone 4"
+#define IPHONE_5_NAMESTRING @"iPhone 5"
+#define IPHONE_UNKNOWN_NAMESTRING @"Unknown iPhone"
-#define IPOD_1G_NAMESTRING @"iPod touch 1G"
-#define IPOD_2G_NAMESTRING @"iPod touch 2G"
-#define IPOD_3G_NAMESTRING @"iPod touch 3G"
-#define IPOD_4G_NAMESTRING @"iPod touch 4G"
-#define IPOD_UNKNOWN_NAMESTRING @"Unknown iPod"
+#define IPOD_1G_NAMESTRING @"iPod touch 1G"
+#define IPOD_2G_NAMESTRING @"iPod touch 2G"
+#define IPOD_3G_NAMESTRING @"iPod touch 3G"
+#define IPOD_4G_NAMESTRING @"iPod touch 4G"
+#define IPOD_UNKNOWN_NAMESTRING @"Unknown iPod"
-#define IPAD_1G_NAMESTRING @"iPad 1G"
-#define IPAD_2G_NAMESTRING @"iPad 2G"
-#define IPAD_UNKNOWN_NAMESTRING @"Unknown iPad"
+#define IPAD_1G_NAMESTRING @"iPad 1G"
+#define IPAD_2G_NAMESTRING @"iPad 2G"
+#define IPAD_3G_NAMESTRING @"iPad 3G"
+#define IPAD_UNKNOWN_NAMESTRING @"Unknown iPad"
-// Nano? Apple TV?
-#define APPLETV_2G_NAMESTRING @"Apple TV 2G"
+#define APPLETV_2G_NAMESTRING @"Apple TV 2G"
+#define APPLETV_UNKNOWN_NAMESTRING @"Unknown Apple TV"
-#define IPOD_FAMILY_UNKNOWN_DEVICE @"Unknown iOS device"
+#define IOS_FAMILY_UNKNOWN_DEVICE @"Unknown iOS device"
-#define IPHONE_SIMULATOR_NAMESTRING @"iPhone Simulator"
-#define IPHONE_SIMULATOR_IPHONE_NAMESTRING @"iPhone Simulator"
-#define IPHONE_SIMULATOR_IPAD_NAMESTRING @"iPad Simulator"
+#define IPHONE_SIMULATOR_NAMESTRING @"iPhone Simulator"
+#define IPHONE_SIMULATOR_IPHONE_NAMESTRING @"iPhone Simulator"
+#define IPHONE_SIMULATOR_IPAD_NAMESTRING @"iPad Simulator"
typedef enum {
- UIDeviceUnknown,
-
- UIDeviceiPhoneSimulator,
- UIDeviceiPhoneSimulatoriPhone, // both regular and iPhone 4 devices
- UIDeviceiPhoneSimulatoriPad,
-
- UIDevice1GiPhone,
- UIDevice3GiPhone,
- UIDevice3GSiPhone,
- UIDevice4iPhone,
- UIDevice5iPhone,
-
- UIDevice1GiPod,
- UIDevice2GiPod,
- UIDevice3GiPod,
- UIDevice4GiPod,
-
- UIDevice1GiPad, // both regular and 3G
- UIDevice2GiPad,
-
- UIDeviceAppleTV2,
-
- UIDeviceUnknowniPhone,
- UIDeviceUnknowniPod,
- UIDeviceUnknowniPad,
- UIDeviceIFPGA,
+ UIDeviceUnknown,
+
+ UIDeviceiPhoneSimulator,
+ UIDeviceiPhoneSimulatoriPhone, // both regular and iPhone 4 devices
+ UIDeviceiPhoneSimulatoriPad,
+
+ UIDevice1GiPhone,
+ UIDevice3GiPhone,
+ UIDevice3GSiPhone,
+ UIDevice4iPhone,
+ UIDevice5iPhone,
+
+ UIDevice1GiPod,
+ UIDevice2GiPod,
+ UIDevice3GiPod,
+ UIDevice4GiPod,
+
+ UIDevice1GiPad,
+ UIDevice2GiPad,
+ UIDevice3GiPad,
+
+ UIDeviceAppleTV2,
+ UIDeviceUnknownAppleTV,
+
+ UIDeviceUnknowniPhone,
+ UIDeviceUnknowniPod,
+ UIDeviceUnknowniPad,
+ UIDeviceIFPGA,
} UIDevicePlatform;
@@ -69,7 +72,6 @@ typedef enum {
- (NSString *) hwmodel;
- (NSUInteger) platformType;
- (NSString *) platformString;
-- (NSString *) platformCode;
- (NSUInteger) cpuFrequency;
- (NSUInteger) busFrequency;
349 UIDevice-Hardware.m
View
@@ -1,6 +1,6 @@
/*
Erica Sadun, http://ericasadun.com
- iPhone Developer's Cookbook, 3.0 Edition
+ iPhone Developer's Cookbook, 5.0 Edition
BSD License, Use at your own risk
*/
@@ -14,32 +14,35 @@
#import "UIDevice-Hardware.h"
@implementation UIDevice (Hardware)
-
/*
Platforms
- iFPGA -> ??
-
- iPhone1,1 -> iPhone 1G
- iPhone1,2 -> iPhone 3G
- iPhone2,1 -> iPhone 3GS
- iPhone3,1 -> iPhone 4/AT&T
- iPhone3,2 -> iPhone 4/Other Carrier?
- iPhone3,3 -> iPhone 4/Other Carrier?
- iPhone4,1 -> ??iPhone 5
-
- iPod1,1 -> iPod touch 1G
- iPod2,1 -> iPod touch 2G
- iPod2,2 -> ??iPod touch 2.5G
- iPod3,1 -> iPod touch 3G
- iPod4,1 -> iPod touch 4G
- iPod5,1 -> ??iPod touch 5G
-
- iPad1,1 -> iPad 1G, WiFi
- iPad1,? -> iPad 1G, 3G <- needs 3G owner to test
- iPad2,1 -> iPad 2G (iProd 2,1)
+ iFPGA -> ??
+
+ iPhone1,1 -> iPhone 1G, M68
+ iPhone1,2 -> iPhone 3G, N82
+ iPhone2,1 -> iPhone 3GS, N88
+ iPhone3,1 -> iPhone 4/AT&T, N89
+ iPhone3,2 -> iPhone 4/Other Carrier?, ??
+ iPhone3,3 -> iPhone 4/Verizon, TBD
+ iPhone4,1 -> (iPhone 5/AT&T), TBD
+ iPhone4,2 -> (iPhone 5/Verizon), TBD
+
+ iPod1,1 -> iPod touch 1G, N45
+ iPod2,1 -> iPod touch 2G, N72
+ iPod2,2 -> Unknown, ??
+ iPod3,1 -> iPod touch 3G, N18
+ iPod4,1 -> iPod touch 4G, N80
- AppleTV2,1 -> AppleTV 2
+ // Thanks NSForge
+ iPad1,1 -> iPad 1G, WiFi and 3G, K48
+ iPad2,1 -> iPad 2G, WiFi, K93
+ iPad2,2 -> iPad 2G, GSM 3G, K94
+ iPad2,3 -> iPad 2G, CDMA 3G, K95
+ iPad3,1 -> (iPad 3G, GSM)
+ iPad3,2 -> (iPad 3G, CDMA)
+
+ AppleTV2,1 -> AppleTV 2, K66
i386, x86_64 -> iPhone Simulator
*/
@@ -48,149 +51,154 @@ @implementation UIDevice (Hardware)
#pragma mark sysctlbyname utils
- (NSString *) getSysInfoByName:(char *)typeSpecifier
{
- size_t size;
+ size_t size;
sysctlbyname(typeSpecifier, NULL, &size, NULL, 0);
+
char *answer = malloc(size);
- sysctlbyname(typeSpecifier, answer, &size, NULL, 0);
- NSString *results = [NSString stringWithCString:answer encoding: NSUTF8StringEncoding];
- free(answer);
- return results;
+ sysctlbyname(typeSpecifier, answer, &size, NULL, 0);
+
+ NSString *results = [NSString stringWithCString:answer encoding: NSUTF8StringEncoding];
+
+ free(answer);
+ return results;
}
- (NSString *) platform
{
- return [self getSysInfoByName:"hw.machine"];
+ return [self getSysInfoByName:"hw.machine"];
}
-// Thanks, Atomicbird
+// Thanks, Tom Harrington (Atomicbird)
- (NSString *) hwmodel
{
- return [self getSysInfoByName:"hw.model"];
+ return [self getSysInfoByName:"hw.model"];
}
#pragma mark sysctl utils
- (NSUInteger) getSysInfo: (uint) typeSpecifier
{
- size_t size = sizeof(int);
- int results;
- int mib[2] = {CTL_HW, typeSpecifier};
- sysctl(mib, 2, &results, &size, NULL, 0);
- return (NSUInteger) results;
+ size_t size = sizeof(int);
+ int results;
+ int mib[2] = {CTL_HW, typeSpecifier};
+ sysctl(mib, 2, &results, &size, NULL, 0);
+ return (NSUInteger) results;
}
- (NSUInteger) cpuFrequency
{
- return [self getSysInfo:HW_CPU_FREQ];
+ return [self getSysInfo:HW_CPU_FREQ];
}
- (NSUInteger) busFrequency
{
- return [self getSysInfo:HW_BUS_FREQ];
+ return [self getSysInfo:HW_BUS_FREQ];
}
- (NSUInteger) totalMemory
{
- return [self getSysInfo:HW_PHYSMEM];
+ return [self getSysInfo:HW_PHYSMEM];
}
- (NSUInteger) userMemory
{
- return [self getSysInfo:HW_USERMEM];
+ return [self getSysInfo:HW_USERMEM];
}
- (NSUInteger) maxSocketBufferSize
{
- return [self getSysInfo:KIPC_MAXSOCKBUF];
+ return [self getSysInfo:KIPC_MAXSOCKBUF];
}
#pragma mark file system -- Thanks Joachim Bean!
- (NSNumber *) totalDiskSpace
{
- NSDictionary *fattributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil];
- return [fattributes objectForKey:NSFileSystemSize];
+ NSDictionary *fattributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil];
+ return [fattributes objectForKey:NSFileSystemSize];
}
- (NSNumber *) freeDiskSpace
{
- NSDictionary *fattributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil];
- return [fattributes objectForKey:NSFileSystemFreeSize];
+ NSDictionary *fattributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil];
+ return [fattributes objectForKey:NSFileSystemFreeSize];
}
#pragma mark platform type and name utils
- (NSUInteger) platformType
{
- NSString *platform = [self platform];
- // if ([platform isEqualToString:@"XX"]) return UIDeviceUnknown;
-
- if ([platform isEqualToString:@"iFPGA"]) return UIDeviceIFPGA;
-
- if ([platform isEqualToString:@"iPhone1,1"]) return UIDevice1GiPhone;
- if ([platform isEqualToString:@"iPhone1,2"]) return UIDevice3GiPhone;
- if ([platform hasPrefix:@"iPhone2"]) return UIDevice3GSiPhone;
- if ([platform hasPrefix:@"iPhone3"]) return UIDevice4iPhone;
- if ([platform hasPrefix:@"iPhone4"]) return UIDevice5iPhone;
-
- if ([platform isEqualToString:@"iPod1,1"]) return UIDevice1GiPod;
- if ([platform isEqualToString:@"iPod2,1"]) return UIDevice2GiPod;
- if ([platform isEqualToString:@"iPod3,1"]) return UIDevice3GiPod;
- if ([platform isEqualToString:@"iPod4,1"]) return UIDevice4GiPod;
-
- if ([platform isEqualToString:@"iPad1,1"]) return UIDevice1GiPad;
- if ([platform isEqualToString:@"iPad2,1"]) return UIDevice2GiPad;
-
- if ([platform isEqualToString:@"AppleTV2,1"]) return UIDeviceAppleTV2;
-
- /*
- MISSING A SOLUTION HERE TO DATE TO DIFFERENTIATE iPAD and iPAD 3G.... SORRY!
- */
-
- if ([platform hasPrefix:@"iPhone"]) return UIDeviceUnknowniPhone;
- if ([platform hasPrefix:@"iPod"]) return UIDeviceUnknowniPod;
- if ([platform hasPrefix:@"iPad"]) return UIDeviceUnknowniPad;
-
- if ([platform hasSuffix:@"86"] || [platform isEqual:@"x86_64"]) // thanks Jordan Breeding
- {
- if ([[UIScreen mainScreen] bounds].size.width < 768)
- return UIDeviceiPhoneSimulatoriPhone;
- else
- return UIDeviceiPhoneSimulatoriPad;
-
- return UIDeviceiPhoneSimulator;
- }
- return UIDeviceUnknown;
+ NSString *platform = [self platform];
+
+ // The ever mysterious iFPGA
+ if ([platform isEqualToString:@"iFPGA"]) return UIDeviceIFPGA;
+
+ // iPhone
+ if ([platform isEqualToString:@"iPhone1,1"]) return UIDevice1GiPhone;
+ if ([platform isEqualToString:@"iPhone1,2"]) return UIDevice3GiPhone;
+ if ([platform hasPrefix:@"iPhone2"]) return UIDevice3GSiPhone;
+ if ([platform hasPrefix:@"iPhone3"]) return UIDevice4iPhone;
+ if ([platform hasPrefix:@"iPhone4"]) return UIDevice5iPhone;
+
+ // iPod
+ if ([platform hasPrefix:@"iPod1"]) return UIDevice1GiPod;
+ if ([platform hasPrefix:@"iPod2"]) return UIDevice2GiPod;
+ if ([platform hasPrefix:@"iPod3"]) return UIDevice3GiPod;
+ if ([platform hasPrefix:@"iPod4"]) return UIDevice4GiPod;
+
+ // iPad
+ if ([platform hasPrefix:@"iPad1"]) return UIDevice1GiPad;
+ if ([platform hasPrefix:@"iPad2"]) return UIDevice2GiPad;
+ if ([platform hasPrefix:@"iPad3"]) return UIDevice3GiPad;
+
+ // Apple TV
+ if ([platform hasPrefix:@"AppleTV2"]) return UIDeviceAppleTV2;
+
+ if ([platform hasPrefix:@"iPhone"]) return UIDeviceUnknowniPhone;
+ if ([platform hasPrefix:@"iPod"]) return UIDeviceUnknowniPod;
+ if ([platform hasPrefix:@"iPad"]) return UIDeviceUnknowniPad;
+
+ // Simulator thanks Jordan Breeding
+ if ([platform hasSuffix:@"86"] || [platform isEqual:@"x86_64"])
+ {
+ BOOL smallerScreen = [[UIScreen mainScreen] bounds].size.width < 768;
+ return smallerScreen ? UIDeviceiPhoneSimulatoriPhone : UIDeviceiPhoneSimulatoriPad;
+ }
+
+ return UIDeviceUnknown;
}
- (NSString *) platformString
{
- switch ([self platformType])
- {
- case UIDevice1GiPhone: return IPHONE_1G_NAMESTRING;
- case UIDevice3GiPhone: return IPHONE_3G_NAMESTRING;
- case UIDevice3GSiPhone: return IPHONE_3GS_NAMESTRING;
- case UIDevice4iPhone: return IPHONE_4_NAMESTRING;
- case UIDevice5iPhone: return IPHONE_5_NAMESTRING;
- case UIDeviceUnknowniPhone: return IPHONE_UNKNOWN_NAMESTRING;
-
- case UIDevice1GiPod: return IPOD_1G_NAMESTRING;
- case UIDevice2GiPod: return IPOD_2G_NAMESTRING;
- case UIDevice3GiPod: return IPOD_3G_NAMESTRING;
- case UIDevice4GiPod: return IPOD_4G_NAMESTRING;
- case UIDeviceUnknowniPod: return IPOD_UNKNOWN_NAMESTRING;
-
- case UIDevice1GiPad : return IPAD_1G_NAMESTRING;
- case UIDevice2GiPad : return IPAD_2G_NAMESTRING;
-
- case UIDeviceAppleTV2 : return APPLETV_2G_NAMESTRING;
-
- case UIDeviceiPhoneSimulator: return IPHONE_SIMULATOR_NAMESTRING;
- case UIDeviceiPhoneSimulatoriPhone: return IPHONE_SIMULATOR_IPHONE_NAMESTRING;
- case UIDeviceiPhoneSimulatoriPad: return IPHONE_SIMULATOR_IPAD_NAMESTRING;
-
- case UIDeviceIFPGA: return IFPGA_NAMESTRING;
-
- default: return IPOD_FAMILY_UNKNOWN_DEVICE;
- }
+ switch ([self platformType])
+ {
+ case UIDevice1GiPhone: return IPHONE_1G_NAMESTRING;
+ case UIDevice3GiPhone: return IPHONE_3G_NAMESTRING;
+ case UIDevice3GSiPhone: return IPHONE_3GS_NAMESTRING;
+ case UIDevice4iPhone: return IPHONE_4_NAMESTRING;
+ case UIDevice5iPhone: return IPHONE_5_NAMESTRING;
+ case UIDeviceUnknowniPhone: return IPHONE_UNKNOWN_NAMESTRING;
+
+ case UIDevice1GiPod: return IPOD_1G_NAMESTRING;
+ case UIDevice2GiPod: return IPOD_2G_NAMESTRING;
+ case UIDevice3GiPod: return IPOD_3G_NAMESTRING;
+ case UIDevice4GiPod: return IPOD_4G_NAMESTRING;
+ case UIDeviceUnknowniPod: return IPOD_UNKNOWN_NAMESTRING;
+
+ case UIDevice1GiPad : return IPAD_1G_NAMESTRING;
+ case UIDevice2GiPad : return IPAD_2G_NAMESTRING;
+ case UIDevice3GiPad : return IPAD_3G_NAMESTRING;
+ case UIDeviceUnknowniPad : return IPAD_UNKNOWN_NAMESTRING;
+
+ case UIDeviceAppleTV2 : return APPLETV_2G_NAMESTRING;
+ case UIDeviceUnknownAppleTV: return APPLETV_UNKNOWN_NAMESTRING;
+
+ case UIDeviceiPhoneSimulator: return IPHONE_SIMULATOR_NAMESTRING;
+ case UIDeviceiPhoneSimulatoriPhone: return IPHONE_SIMULATOR_IPHONE_NAMESTRING;
+ case UIDeviceiPhoneSimulatoriPad: return IPHONE_SIMULATOR_IPAD_NAMESTRING;
+
+ case UIDeviceIFPGA: return IFPGA_NAMESTRING;
+
+ default: return IOS_FAMILY_UNKNOWN_DEVICE;
+ }
}
#pragma mark MAC addy
@@ -199,75 +207,49 @@ - (NSString *) platformString
// Accidentally munged during previous update. Fixed thanks to mlamb.
- (NSString *) macaddress
{
- int mib[6];
- size_t len;
- char *buf;
- unsigned char *ptr;
- struct if_msghdr *ifm;
- struct sockaddr_dl *sdl;
-
- mib[0] = CTL_NET;
- mib[1] = AF_ROUTE;
- mib[2] = 0;
- mib[3] = AF_LINK;
- mib[4] = NET_RT_IFLIST;
-
- if ((mib[5] = if_nametoindex("en0")) == 0) {
- printf("Error: if_nametoindex error\n");
- return NULL;
- }
-
- if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) {
- printf("Error: sysctl, take 1\n");
- return NULL;
- }
-
- if ((buf = malloc(len)) == NULL) {
- printf("Could not allocate memory. error!\n");
- return NULL;
- }
-
- if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
- printf("Error: sysctl, take 2");
- return NULL;
- }
-
- ifm = (struct if_msghdr *)buf;
- sdl = (struct sockaddr_dl *)(ifm + 1);
- ptr = (unsigned char *)LLADDR(sdl);
- // NSString *outstring = [NSString stringWithFormat:@"%02x:%02x:%02x:%02x:%02x:%02x", *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
- NSString *outstring = [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x", *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
- free(buf);
- return [outstring uppercaseString];
-}
+ int mib[6];
+ size_t len;
+ char *buf;
+ unsigned char *ptr;
+ struct if_msghdr *ifm;
+ struct sockaddr_dl *sdl;
+
+ mib[0] = CTL_NET;
+ mib[1] = AF_ROUTE;
+ mib[2] = 0;
+ mib[3] = AF_LINK;
+ mib[4] = NET_RT_IFLIST;
+
+ if ((mib[5] = if_nametoindex("en0")) == 0) {
+ printf("Error: if_nametoindex error\n");
+ return NULL;
+ }
+
+ if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) {
+ printf("Error: sysctl, take 1\n");
+ return NULL;
+ }
+
+ if ((buf = malloc(len)) == NULL) {
+ printf("Could not allocate memory. error!\n");
+ return NULL;
+ }
+
+ if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
+ printf("Error: sysctl, take 2");
+ return NULL;
+ }
+
+ ifm = (struct if_msghdr *)buf;
+ sdl = (struct sockaddr_dl *)(ifm + 1);
+ ptr = (unsigned char *)LLADDR(sdl);
+ NSString *outstring = [NSString stringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X",
+ *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
+ // NSString *outstring = [NSString stringWithFormat:@"%02X%02X%02X%02X%02X%02X",
+ // *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
+ free(buf);
-- (NSString *) platformCode
-{
- switch ([self platformType])
- {
- case UIDevice1GiPhone: return @"M68";
- case UIDevice3GiPhone: return @"N82";
- case UIDevice3GSiPhone: return @"N88";
- case UIDevice4iPhone: return @"N89";
- case UIDevice5iPhone: return IPHONE_UNKNOWN_NAMESTRING;
- case UIDeviceUnknowniPhone: return IPHONE_UNKNOWN_NAMESTRING;
-
- case UIDevice1GiPod: return @"N45";
- case UIDevice2GiPod: return @"N72";
- case UIDevice3GiPod: return @"N18";
- case UIDevice4GiPod: return @"N80";
- case UIDeviceUnknowniPod: return IPOD_UNKNOWN_NAMESTRING;
-
- case UIDevice1GiPad: return @"K48";
- case UIDevice2GiPad: return IPAD_UNKNOWN_NAMESTRING;
- case UIDeviceUnknowniPad: return IPAD_UNKNOWN_NAMESTRING;
-
- case UIDeviceAppleTV2: return @"K66";
-
- case UIDeviceiPhoneSimulator: return IPHONE_SIMULATOR_NAMESTRING;
-
- default: return IPOD_FAMILY_UNKNOWN_DEVICE;
- }
+ return outstring;
}
// Illicit Bluetooth check -- cannot be used in App Store
@@ -275,10 +257,9 @@ - (NSString *) platformCode
Class btclass = NSClassFromString(@"GKBluetoothSupport");
if ([btclass respondsToSelector:@selector(bluetoothStatus)])
{
- printf("BTStatus %d\n", ((int)[btclass performSelector:@selector(bluetoothStatus)] & 1) != 0);
- bluetooth = ((int)[btclass performSelector:@selector(bluetoothStatus)] & 1) != 0;
- printf("Bluetooth %s enabled\n", bluetooth ? "is" : "isn't");
+ printf("BTStatus %d\n", ((int)[btclass performSelector:@selector(bluetoothStatus)] & 1) != 0);
+ bluetooth = ((int)[btclass performSelector:@selector(bluetoothStatus)] & 1) != 0;
+ printf("Bluetooth %s enabled\n", bluetooth ? "is" : "isn't");
}
*/
-
@end
1  main.m
View
@@ -76,6 +76,7 @@ - (void) action: (UIBarButtonItem *) bbi
// TESTING DEVICE HARDWARE
[self doLog:@"Platform: %@", [[UIDevice currentDevice] platform]];
[self doLog:@"Platform String: %@", [[UIDevice currentDevice] platformString]];
+ [self doLog:@"Mac: %@", [[UIDevice currentDevice] macaddress]];
/*
[self doLog:@"Device is%@ portrait", [UIDevice currentDevice].isPortrait ? @"" : @" not"];
Please sign in to comment.
Something went wrong with that request. Please try again.