Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

One more time...

  • Loading branch information...
commit 2f93e222f48e92232c4f722274ffcec6f4e15ccb 1 parent 93e5ea6
Erica Sadun authored
View
90 UIDevice-Hardware.h
@@ -1,90 +0,0 @@
-/*
- Erica Sadun, http://ericasadun.com
- iPhone Developer's Cookbook, 3.0 Edition
- BSD License, Use at your own risk
- */
-
-#import <UIKit/UIKit.h>
-
-#define IPHONE_1G_NAMESTRING @"iPhone 1G"
-#define IPHONE_3G_NAMESTRING @"iPhone 3G"
-#define IPHONE_3GS_NAMESTRING @"iPhone 3GS"
-#define IPHONE_UNKNOWN_NAMESTRING @"Unknown iPhone"
-
-#define IPOD_1G_NAMESTRING @"iPod touch 1G"
-#define IPOD_2G_NAMESTRING @"iPod touch 2G"
-#define IPOD_UNKNOWN_NAMESTRING @"Unknown iPod"
-
-#define IPOD_FAMILY_UNKNOWN_DEVICE @"Unknown device in the iPhone/iPod family"
-
-#define IPHONE_SIMULATOR_NAMESTRING @"iPhone Simulator"
-
-typedef enum {
- UIDeviceUnknown,
- UIDeviceiPhoneSimulator,
- UIDevice1GiPhone,
- UIDevice1GiPod,
- UIDevice3GiPhone,
- UIDevice3GSiPhone,
- UIDevice2GiPod,
- UIDeviceUnknowniPhone,
- UIDeviceUnknowniPod,
-} UIDevicePlatform;
-
-typedef enum {
- UIDeviceFirmware2,
- UIDeviceFirmware3,
-} UIDeviceFirmware;
-
-enum {
- UIDeviceSupportsTelephony = 1 << 0,
- UIDeviceSupportsSMS = 1 << 1,
- UIDeviceSupportsStillCamera = 1 << 2,
- UIDeviceSupportsAutofocusCamera = 1 << 3,
- UIDeviceSupportsVideoCamera = 1 << 4,
- UIDeviceSupportsWifi = 1 << 5,
- UIDeviceSupportsAccelerometer = 1 << 6,
- UIDeviceSupportsLocationServices = 1 << 7,
- UIDeviceSupportsGPS = 1 << 8,
- UIDeviceSupportsMagnetometer = 1 << 9,
- UIDeviceSupportsBuiltInMicrophone = 1 << 10,
- UIDeviceSupportsExternalMicrophone = 1 << 11,
- UIDeviceSupportsOPENGLES1 = 1 << 12,
- UIDeviceSupportsOPENGLES2 = 1 << 13,
- UIDeviceBuiltInSpeaker = 1 << 14,
- UIDeviceSupportsVibration = 1 << 15,
- UIDeviceBuiltInProximitySensor = 1 << 16,
- UIDeviceSupportsAccessibility = 1 << 17,
- UIDeviceSupportsVoiceControl = 1 << 18,
- UIDeviceSupportsBrightnessSensor = 1 << 19,
-};
-
-@interface UIDevice (Hardware)
-
-+ (NSString *) platform;
-+ (NSUInteger) platformType;
-+ (NSUInteger) platformCapabilities;
-+ (NSString *) platformString;
-+ (NSString *) platformCode;
-
-+ (NSArray *) capabilityArray;
-
-+ (NSUInteger) cpuFrequency;
-+ (NSUInteger) busFrequency;
-+ (NSUInteger) totalMemory;
-+ (NSUInteger) userMemory;
-
-+ (NSNumber *) totalDiskSpace;
-+ (NSNumber *) freeDiskSpace;
-
-+ (NSString *) macaddress;
-@end
-
-@interface UIDevice (Orientation)
-- (BOOL) isLandscape;
-- (BOOL) isPortrait;
-- (NSString *) orientationString;
-@property (nonatomic, readonly) BOOL isLandscape;
-@property (nonatomic, readonly) BOOL isPortrait;
-@property (nonatomic, readonly) NSString *orientationString;
-@end
View
407 UIDevice-Hardware.m
@@ -1,407 +0,0 @@
-/*
- Erica Sadun, http://ericasadun.com
- iPhone Developer's Cookbook, 3.0 Edition
- BSD License, Use at your own risk
- */
-
-// Thanks to Emanuele Vulcano, Kevin Ballard/Eridius, Ryandjohnson, Matt Brown, etc.
-// TTD: - Bluetooth? Screen pixels? Dot pitch? Accelerometer? GPS enabled/disabled
-
-#include <sys/sysctl.h>
-#include <net/if.h>
-#include <net/if_dl.h>
-#import "UIDevice-Hardware.h"
-
-@implementation UIDevice (Hardware)
-
-/*
- Platforms
-
- iPhone1,1 -> iPhone 1G
- iPhone1,2 -> iPhone 3G
- iPhone2,1 -> iPhone 3GS
-
- iPod1,1 -> iPod touch 1G
- iPod2,1 -> iPod touch 2G
-
- i386 -> iPhone Simulator
-*/
-
-
-#pragma mark sysctlbyname utils
-+ (NSString *) getSysInfoByName:(char *)typeSpecifier
-{
- 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;
-}
-
-+ (NSString *) platform
-{
- return [self getSysInfoByName:"hw.machine"];
-}
-
-#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;
-}
-
-+ (NSUInteger) cpuFrequency
-{
- return [self getSysInfo:HW_CPU_FREQ];
-}
-
-+ (NSUInteger) busFrequency
-{
- return [self getSysInfo:HW_BUS_FREQ];
-}
-
-+ (NSUInteger) totalMemory
-{
- return [self getSysInfo:HW_PHYSMEM];
-}
-
-+ (NSUInteger) userMemory
-{
- return [self getSysInfo:HW_USERMEM];
-}
-
-+ (NSUInteger) maxSocketBufferSize
-{
- return [self getSysInfo:KIPC_MAXSOCKBUF];
-}
-
-#pragma mark file system -- Thanks Joachim Bean!
-
-+ (NSNumber *) totalDiskSpace
-{
- NSDictionary *fattributes = [[NSFileManager defaultManager] fileSystemAttributesAtPath:NSHomeDirectory()];
- return [fattributes objectForKey:NSFileSystemSize];
-}
-
-+ (NSNumber *) freeDiskSpace
-{
- NSDictionary *fattributes = [[NSFileManager defaultManager] fileSystemAttributesAtPath:NSHomeDirectory()];
- return [fattributes objectForKey:NSFileSystemFreeSize];
-}
-
-#pragma mark platform type and name utils
-+ (NSUInteger) platformType
-{
- NSString *platform = [self platform];
- if ([platform isEqualToString:@"iPhone1,1"]) return UIDevice1GiPhone;
- if ([platform isEqualToString:@"iPhone1,2"]) return UIDevice3GiPhone;
- if ([platform isEqualToString:@"iPhone2,1"]) return UIDevice3GSiPhone;
-
- if ([platform isEqualToString:@"iPod1,1"]) return UIDevice1GiPod;
- if ([platform isEqualToString:@"iPod2,1"]) return UIDevice2GiPod;
-
- if ([platform hasPrefix:@"iPhone"]) return UIDeviceUnknowniPhone;
- if ([platform hasPrefix:@"iPod"]) return UIDeviceUnknowniPod;
-
- if ([platform hasSuffix:@"86"]) return UIDeviceiPhoneSimulator;
- 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 UIDeviceUnknowniPhone: return IPHONE_UNKNOWN_NAMESTRING;
-
- case UIDevice1GiPod: return IPOD_1G_NAMESTRING;
- case UIDevice2GiPod: return IPOD_2G_NAMESTRING;
- case UIDeviceUnknowniPod: return IPOD_UNKNOWN_NAMESTRING;
-
- case UIDeviceiPhoneSimulator: return IPHONE_SIMULATOR_NAMESTRING;
-
- default: return IPOD_FAMILY_UNKNOWN_DEVICE;
- }
-}
-
-#pragma mark platform capabilities
-+ (NSUInteger) platformCapabilities
-{
- switch ([self platformType])
- {
- case UIDevice1GiPhone:
- return
- (UIDeviceSupportsTelephony |
- UIDeviceSupportsSMS |
- UIDeviceSupportsStillCamera |
- // UIDeviceSupportsAutofocusCamera |
- // UIDeviceSupportsVideoCamera |
- UIDeviceSupportsWifi |
- UIDeviceSupportsAccelerometer |
- UIDeviceSupportsLocationServices |
- // UIDeviceSupportsGPS |
- // UIDeviceSupportsMagnetometer |
- UIDeviceSupportsBuiltInMicrophone |
- UIDeviceSupportsExternalMicrophone |
- UIDeviceSupportsOPENGLES1 |
- // UIDeviceSupportsOPENGLES2 |
- UIDeviceBuiltInSpeaker |
- UIDeviceSupportsVibration |
- UIDeviceBuiltInProximitySensor |
- // UIDeviceSupportsAccessibility |
- // UIDeviceSupportsVoiceControl |
- UIDeviceSupportsBrightnessSensor);
-
- case UIDevice3GiPhone:
- return
- (UIDeviceSupportsTelephony |
- UIDeviceSupportsSMS |
- UIDeviceSupportsStillCamera |
- // UIDeviceSupportsAutofocusCamera |
- // UIDeviceSupportsVideoCamera |
- UIDeviceSupportsWifi |
- UIDeviceSupportsAccelerometer |
- UIDeviceSupportsLocationServices |
- UIDeviceSupportsGPS |
- // UIDeviceSupportsMagnetometer |
- UIDeviceSupportsBuiltInMicrophone |
- UIDeviceSupportsExternalMicrophone |
- UIDeviceSupportsOPENGLES1 |
- // UIDeviceSupportsOPENGLES2 |
- UIDeviceBuiltInSpeaker |
- UIDeviceSupportsVibration |
- UIDeviceBuiltInProximitySensor |
- // UIDeviceSupportsAccessibility |
- // UIDeviceSupportsVoiceControl |
- UIDeviceSupportsBrightnessSensor);
-
- case UIDevice3GSiPhone:
- return
- (UIDeviceSupportsTelephony |
- UIDeviceSupportsSMS |
- UIDeviceSupportsStillCamera |
- UIDeviceSupportsAutofocusCamera |
- UIDeviceSupportsVideoCamera |
- UIDeviceSupportsWifi |
- UIDeviceSupportsAccelerometer |
- UIDeviceSupportsLocationServices |
- UIDeviceSupportsGPS |
- UIDeviceSupportsMagnetometer |
- UIDeviceSupportsBuiltInMicrophone |
- UIDeviceSupportsExternalMicrophone |
- UIDeviceSupportsOPENGLES1 |
- UIDeviceSupportsOPENGLES2 |
- UIDeviceBuiltInSpeaker |
- UIDeviceSupportsVibration |
- UIDeviceBuiltInProximitySensor |
- UIDeviceSupportsAccessibility |
- UIDeviceSupportsVoiceControl |
- UIDeviceSupportsBrightnessSensor);
-
- case UIDeviceUnknowniPhone: return 0;
-
- case UIDevice1GiPod:
- return
- (// UIDeviceSupportsTelephony |
- // UIDeviceSupportsSMS |
- // UIDeviceSupportsStillCamera |
- // UIDeviceSupportsAutofocusCamera |
- // UIDeviceSupportsVideoCamera |
- UIDeviceSupportsWifi |
- UIDeviceSupportsAccelerometer |
- UIDeviceSupportsLocationServices |
- // UIDeviceSupportsGPS |
- // UIDeviceSupportsMagnetometer |
- // UIDeviceSupportsBuiltInMicrophone |
- UIDeviceSupportsExternalMicrophone |
- UIDeviceSupportsOPENGLES1 |
- // UIDeviceSupportsOPENGLES2 |
- // UIDeviceBuiltInSpeaker |
- // UIDeviceSupportsVibration |
- // UIDeviceBuiltInProximitySensor |
- // UIDeviceSupportsAccessibility |
- // UIDeviceSupportsVoiceControl |
- UIDeviceSupportsBrightnessSensor);
-
- case UIDevice2GiPod:
- return
- (// UIDeviceSupportsTelephony |
- // UIDeviceSupportsSMS |
- // UIDeviceSupportsStillCamera |
- // UIDeviceSupportsAutofocusCamera |
- // UIDeviceSupportsVideoCamera |
- UIDeviceSupportsWifi |
- UIDeviceSupportsAccelerometer |
- UIDeviceSupportsLocationServices |
- // UIDeviceSupportsGPS |
- // UIDeviceSupportsMagnetometer |
- // UIDeviceSupportsBuiltInMicrophone |
- UIDeviceSupportsExternalMicrophone |
- UIDeviceSupportsOPENGLES1 |
- // UIDeviceSupportsOPENGLES2 |
- UIDeviceBuiltInSpeaker |
- // UIDeviceSupportsVibration |
- // UIDeviceBuiltInProximitySensor |
- // UIDeviceSupportsAccessibility |
- // UIDeviceSupportsVoiceControl |
- UIDeviceSupportsBrightnessSensor);
-
- case UIDeviceUnknowniPod: return 0;
-
- case UIDeviceiPhoneSimulator:
- return
- (// UIDeviceSupportsTelephony |
- // UIDeviceSupportsSMS |
- // UIDeviceSupportsStillCamera |
- // UIDeviceSupportsAutofocusCamera |
- // UIDeviceSupportsVideoCamera |
- UIDeviceSupportsWifi |
- // UIDeviceSupportsAccelerometer |
- UIDeviceSupportsLocationServices |
- // UIDeviceSupportsGPS |
- // UIDeviceSupportsMagnetometer |
- // UIDeviceSupportsBuiltInMicrophone |
- // UIDeviceSupportsExternalMicrophone |
- UIDeviceSupportsOPENGLES1 |
- // UIDeviceSupportsOPENGLES2 |
- UIDeviceBuiltInSpeaker);
- // UIDeviceSupportsVibration |
- // UIDeviceBuiltInProximitySensor |
- // UIDeviceSupportsAccessibility |
- // UIDeviceSupportsVoiceControl |
- // UIDeviceSupportsBrightnessSensor;
-
- default: return 0;
- }
-}
-
-+ (NSArray *) capabilityArray
-{
- NSUInteger flags = [self platformCapabilities];
- NSMutableArray *array = [NSMutableArray array];
-
- if (flags & UIDeviceSupportsTelephony) [array addObject:@"Telephony"];
- if (flags & UIDeviceSupportsSMS) [array addObject:@"SMS"];
- if (flags & UIDeviceSupportsStillCamera) [array addObject:@"Still Camera"];
- if (flags & UIDeviceSupportsAutofocusCamera) [array addObject:@"AutoFocus Camera"];
- if (flags & UIDeviceSupportsVideoCamera) [array addObject:@"Video Camera"];
- if (flags & UIDeviceSupportsWifi) [array addObject:@"WiFi"];
- if (flags & UIDeviceSupportsAccelerometer) [array addObject:@"Accelerometer"];
- if (flags & UIDeviceSupportsLocationServices) [array addObject:@"Location Services"];
- if (flags & UIDeviceSupportsGPS) [array addObject:@"GPS"];
- if (flags & UIDeviceSupportsMagnetometer) [array addObject:@"Magnetometer"];
- if (flags & UIDeviceSupportsBuiltInMicrophone) [array addObject:@"Built-in Microphone"];
- if (flags & UIDeviceSupportsExternalMicrophone) [array addObject:@"External Microphone Support"];
- if (flags & UIDeviceSupportsOPENGLES1) [array addObject:@"OpenGL ES 1.x"];
- if (flags & UIDeviceSupportsOPENGLES2) [array addObject:@"OpenGL ES 2.x"];
- if (flags & UIDeviceBuiltInSpeaker) [array addObject:@"Built-in Speaker"];
- if (flags & UIDeviceSupportsVibration) [array addObject:@"Vibration"];
- if (flags & UIDeviceBuiltInProximitySensor) [array addObject:@"Proximity Sensor"];
- if (flags & UIDeviceSupportsAccessibility) [array addObject:@"Accessibility"];
- if (flags & UIDeviceSupportsVoiceControl) [array addObject:@"Voice Control"];
- if (flags & UIDeviceSupportsBrightnessSensor) [array addObject:@"Brightness Sensor"];
-
- return array;
-}
-
-#pragma mark MAC addy
-// Return the local MAC addy
-// Courtesy of FreeBSD hackers email list
-+ (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)];
- free(buf);
- return [outstring uppercaseString];
-}
-
-+ (NSString *) platformCode
-{
- switch ([self platformType])
- {
- case UIDevice1GiPhone: return @"M68";
- case UIDevice3GiPhone: return @"N82";
- case UIDevice3GSiPhone: return @"N88";
- case UIDeviceUnknowniPhone: return nil;
-
- case UIDevice1GiPod: return @"N45";
- case UIDevice2GiPod: return @"N72";
- // case UIDevice3GiPod: return @"N80";
- case UIDeviceUnknowniPod: return IPOD_UNKNOWN_NAMESTRING;
-
- case UIDeviceiPhoneSimulator: return IPHONE_SIMULATOR_NAMESTRING;
-
- default: return IPOD_FAMILY_UNKNOWN_DEVICE;
- }
-}
-@end
-
-@implementation UIDevice (Orientation)
-- (BOOL) isLandscape
-{
- return (self.orientation == UIDeviceOrientationLandscapeLeft) || (self.orientation == UIDeviceOrientationLandscapeRight);
-}
-
-- (BOOL) isPortrait
-{
- return (self.orientation == UIDeviceOrientationPortrait) || (self.orientation == UIDeviceOrientationPortraitUpsideDown);
-}
-
-- (NSString *) orientationString
-{
- switch ([[UIDevice currentDevice] orientation])
- {
- case UIDeviceOrientationUnknown: return @"Unknown";
- case UIDeviceOrientationPortrait: return @"Portrait";
- case UIDeviceOrientationPortraitUpsideDown: return @"Portrait Upside Down";
- case UIDeviceOrientationLandscapeLeft: return @"Landscape Left";
- case UIDeviceOrientationLandscapeRight: return @"Landscape Right";
- case UIDeviceOrientationFaceUp: return @"Face Up";
- case UIDeviceOrientationFaceDown: return @"Face Down";
- default: break;
- }
- return nil;
-}
-@end
View
40 UIDevice-IOKitExtensions.h
@@ -1,40 +0,0 @@
-/*
- Erica Sadun, http://ericasadun.com
- iPhone Developer's Cookbook, 3.0 Edition
- BSD License, Use at your own risk
- */
-
-/*
- http://broadcast.oreilly.com/2009/04/iphone-dev-iokit---the-missing.html
-
- In Xcode, I was surprised to see that Apple didn't include IOKit header files. When I tried to
- add #import <IOKit/IOKit.h>, the file could not be found. So I manually put together a simple
- header file by hand, added IOKit to my frameworks and attempted to compile.
-
- As you can see from the screenshot at the top of this post, I failed to do so. Xcode complained
- that the IOKit framework could not be found. Despite being filed as public, IOKit is apparently
- not meant to be used by the general public. As iPhone evangelist Matt Drance tweeted,
- "IOKit is not public on iPhone. Lack of headers and docs is rarely an oversight."
-
- In the official docs, I found a quote that described IOKit as such: "Contains interfaces used by
- the device. Do not include this framework directly." So in the end, my desire to access that IOKit
- information was thwarted. For whatever reason, Apple has chosen to list it as a public framework
- but the reality is that it is not.
-*/
-
-#import <UIKit/UIKit.h>
-
-#define SUPPORTS_IOKIT_EXTENSIONS 1
-
-/*
- * To use, you must add the (semi)public IOKit framework before compiling
- */
-
-#if SUPPORTS_IOKIT_EXTENSIONS
-@interface UIDevice (IOKit_Extensions)
-+ (NSString *) imei;
-+ (NSString *) serialnumber;
-+ (NSString *) backlightlevel;
-@end
-#endif
-
View
120 UIDevice-IOKitExtensions.m
@@ -1,120 +0,0 @@
-/*
- Erica Sadun, http://ericasadun.com
- iPhone Developer's Cookbook, 3.0 Edition
- BSD License, Use at your own risk
- */
-
-#import "UIDevice-IOKitExtensions.h"
-#include <sys/types.h>
-#include <sys/sysctl.h>
-#import <mach/mach_host.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <ifaddrs.h>
-#include <sys/socket.h>
-#include <net/if.h>
-#include <net/if_dl.h>
-#include <ifaddrs.h>
-
-#if SUPPORTS_IOKIT_EXTENSIONS
-#pragma mark IOKit miniheaders
-
-#define kIODeviceTreePlane "IODeviceTree"
-
-enum {
- kIORegistryIterateRecursively = 0x00000001,
- kIORegistryIterateParents = 0x00000002
-};
-
-typedef mach_port_t io_object_t;
-typedef io_object_t io_registry_entry_t;
-typedef char io_name_t[128];
-typedef UInt32 IOOptionBits;
-
-CFTypeRef
-IORegistryEntrySearchCFProperty(
- io_registry_entry_t entry,
- const io_name_t plane,
- CFStringRef key,
- CFAllocatorRef allocator,
- IOOptionBits options );
-
-kern_return_t
-IOMasterPort( mach_port_t bootstrapPort,
- mach_port_t * masterPort );
-
-io_registry_entry_t
-IORegistryGetRootEntry(
- mach_port_t masterPort );
-
-CFTypeRef
-IORegistryEntrySearchCFProperty(
- io_registry_entry_t entry,
- const io_name_t plane,
- CFStringRef key,
- CFAllocatorRef allocator,
- IOOptionBits options );
-
-kern_return_t mach_port_deallocate
-(ipc_space_t task,
- mach_port_name_t name);
-
-
-@implementation UIDevice (IOKit_Extensions)
-#pragma mark IOKit Utils
-NSArray *getValue(NSString *iosearch)
-{
- mach_port_t masterPort;
- CFTypeID propID = (CFTypeID) NULL;
- unsigned int bufSize;
-
- kern_return_t kr = IOMasterPort(MACH_PORT_NULL, &masterPort);
- if (kr != noErr) return nil;
-
- io_registry_entry_t entry = IORegistryGetRootEntry(masterPort);
- if (entry == MACH_PORT_NULL) return nil;
-
- CFTypeRef prop = IORegistryEntrySearchCFProperty(entry, kIODeviceTreePlane, (CFStringRef) iosearch, nil, kIORegistryIterateRecursively);
- if (!prop) return nil;
-
- propID = CFGetTypeID(prop);
- if (!(propID == CFDataGetTypeID()))
- {
- mach_port_deallocate(mach_task_self(), masterPort);
- return nil;
- }
-
- CFDataRef propData = (CFDataRef) prop;
- if (!propData) return nil;
-
- bufSize = CFDataGetLength(propData);
- if (!bufSize) return nil;
-
- NSString *p1 = [[[NSString alloc] initWithBytes:CFDataGetBytePtr(propData) length:bufSize encoding:1] autorelease];
- mach_port_deallocate(mach_task_self(), masterPort);
- return [p1 componentsSeparatedByString:@"\0"];
-}
-
-+ (NSString *) imei
-{
- NSArray *results = getValue(@"device-imei");
- if (results) return [results objectAtIndex:0];
- return nil;
-}
-
-+ (NSString *) serialnumber
-{
- NSArray *results = getValue(@"serial-number");
- if (results) return [results objectAtIndex:0];
- return nil;
-}
-
-+ (NSString *) backlightlevel
-{
- NSArray *results = getValue(@"backlight-level");
- if (results) return [results objectAtIndex:0];
- return nil;
-}
-@end
-#endif
View
73 UIDevice-Reachability.h
@@ -1,73 +0,0 @@
-/*
- Erica Sadun, http://ericasadun.com
- iPhone Developer's Cookbook, 3.0 Edition
- BSD License for anything not specifically marked as developed by a third party.
- Apple's code excluded.
- Use at your own risk
- */
-
-#import <UIKit/UIKit.h>
-
-#define SUPPORTS_UNDOCUMENTED_API 1
-
-@protocol ReachabilityWatcher <NSObject>
-- (void) reachabilityChanged;
-@end
-
-
-@interface UIDevice (Reachability)
-+ (NSString *) stringFromAddress: (const struct sockaddr *) address;
-+ (BOOL)addressFromString:(NSString *)IPAddress address:(struct sockaddr_in *)address;
-
-+ (NSString *) hostname;
-+ (NSString *) getIPAddressForHost: (NSString *) theHost;
-+ (NSString *) localIPAddress;
-+ (NSString *) localWiFiIPAddress;
-+ (NSString *) whatismyipdotcom;
-
-+ (BOOL) hostAvailable: (NSString *) theHost;
-+ (BOOL) networkAvailable;
-+ (BOOL) activeWLAN;
-+ (BOOL) activeWWAN;
-+ (BOOL) performWiFiCheck;
-
-+ (BOOL) forceWWAN; // via Apple
-+ (void) shutdownWWAN; // via Apple
-
-+ (BOOL) scheduleReachabilityWatcher: (id) watcher;
-+ (void) unscheduleReachabilityWatcher;
-
-#ifdef SUPPORTS_UNDOCUMENTED_API
-// Don't use this code in real life, boys and girls. It is not App Store friendly.
-// It is, however, really nice for testing callbacks
-// DEVICE ONLY!!!!
-+ (void) setAPMode: (BOOL) yorn;
-#endif
-@end
-
-#ifdef SUPPORTS_UNDOCUMENTED_API
-@interface NSHost : NSObject
-{
- NSArray *names;
- NSArray *addresses;
- void *reserved;
-}
-
-+ (id)currentHost;
-+ (void)_fixNSHostLeak;
-+ (id)hostWithName:(id)fp8;
-+ (id)hostWithAddress:(id)fp8;
-+ (BOOL)isHostCacheEnabled;
-+ (void)setHostCacheEnabled:(BOOL)fp8;
-+ (void)flushHostCache;
-- (BOOL)isEqualToHost:(id)fp8;
-- (id)name;
-- (id)names;
-- (id)address;
-- (id)addresses;
-- (id)description;
-- (void)dealloc;
-
-@end
-#endif
-
View
325 UIDevice-Reachability.m
@@ -1,325 +0,0 @@
-/*
- Erica Sadun, http://ericasadun.com
- iPhone Developer's Cookbook, 3.0 Edition
- BSD License for anything not specifically marked as developed by a third party.
- Apple's code excluded.
- Use at your own risk
- */
-
-#import <SystemConfiguration/SystemConfiguration.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <net/if.h>
-#include <ifaddrs.h>
-#import <dlfcn.h>
-#import "UIDevice-Reachability.h"
-#import "wwanconnect.h"
-
-@implementation UIDevice (Reachability)
-SCNetworkConnectionFlags connectionFlags;
-SCNetworkReachabilityRef reachability;
-
-#pragma mark Class IP and Host Utilities
-// This IP Utilities are mostly inspired by or derived from Apple code. Thank you Apple.
-
-+ (NSString *) stringFromAddress: (const struct sockaddr *) address
-{
- if(address && address->sa_family == AF_INET) {
- const struct sockaddr_in* sin = (struct sockaddr_in*) address;
- return [NSString stringWithFormat:@"%@:%d", [NSString stringWithUTF8String:inet_ntoa(sin->sin_addr)], ntohs(sin->sin_port)];
- }
-
- return nil;
-}
-
-+ (BOOL)addressFromString:(NSString *)IPAddress address:(struct sockaddr_in *)address
-{
- if (!IPAddress || ![IPAddress length]) {
- return NO;
- }
-
- memset((char *) address, sizeof(struct sockaddr_in), 0);
- address->sin_family = AF_INET;
- address->sin_len = sizeof(struct sockaddr_in);
-
- int conversionResult = inet_aton([IPAddress UTF8String], &address->sin_addr);
- if (conversionResult == 0) {
- NSAssert1(conversionResult != 1, @"Failed to convert the IP address string into a sockaddr_in: %@", IPAddress);
- return NO;
- }
-
- return YES;
-}
-
-+ (NSString *) hostname
-{
- char baseHostName[255];
- int success = gethostname(baseHostName, 255);
- if (success != 0) return nil;
- baseHostName[255] = '\0';
-
- #if !TARGET_IPHONE_SIMULATOR
- return [NSString stringWithFormat:@"%s.local", baseHostName];
- #else
- return [NSString stringWithFormat:@"%s", baseHostName];
- #endif
-}
-
-+ (NSString *) getIPAddressForHost: (NSString *) theHost
-{
- struct hostent *host = gethostbyname([theHost UTF8String]);
- if (!host) {herror("resolv"); return NULL; }
- struct in_addr **list = (struct in_addr **)host->h_addr_list;
- NSString *addressString = [NSString stringWithCString:inet_ntoa(*list[0]) encoding:NSUTF8StringEncoding];
- return addressString;
-}
-
-+ (NSString *) localIPAddress
-{
- struct hostent *host = gethostbyname([[self hostname] UTF8String]);
- if (!host) {herror("resolv"); return nil;}
- struct in_addr **list = (struct in_addr **)host->h_addr_list;
- return [NSString stringWithCString:inet_ntoa(*list[0]) encoding:NSUTF8StringEncoding];
-}
-
-// Matt Brown's get WiFi IP addy solution
-// Author gave permission to use in Cookbook under cookbook license
-// http://mattbsoftware.blogspot.com/2009/04/how-to-get-ip-address-of-iphone-os-v221.html
-+ (NSString *) localWiFiIPAddress
-{
- BOOL success;
- struct ifaddrs * addrs;
- const struct ifaddrs * cursor;
-
- success = getifaddrs(&addrs) == 0;
- if (success) {
- cursor = addrs;
- while (cursor != NULL) {
- // the second test keeps from picking up the loopback address
- if (cursor->ifa_addr->sa_family == AF_INET && (cursor->ifa_flags & IFF_LOOPBACK) == 0)
- {
- NSString *name = [NSString stringWithUTF8String:cursor->ifa_name];
- if ([name isEqualToString:@"en0"]) // Wi-Fi adapter
- return [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)cursor->ifa_addr)->sin_addr)];
- }
- cursor = cursor->ifa_next;
- }
- freeifaddrs(addrs);
- }
- return nil;
-}
-
-+ (NSString *) whatismyipdotcom
-{
- NSError *error;
- NSURL *ipURL = [NSURL URLWithString:@"http://www.whatismyip.com/automation/n09230945.asp"];
- NSString *ip = [NSString stringWithContentsOfURL:ipURL encoding:1 error:&error];
- return ip ? ip : [error localizedDescription];
-}
-
-+ (BOOL) hostAvailable: (NSString *) theHost
-{
-
- NSString *addressString = [self getIPAddressForHost:theHost];
- if (!addressString)
- {
- printf("Error recovering IP address from host name\n");
- return NO;
- }
-
- struct sockaddr_in address;
- BOOL gotAddress = [self addressFromString:addressString address:&address];
-
- if (!gotAddress)
- {
- printf("Error recovering sockaddr address from %s\n", [addressString UTF8String]);
- return NO;
- }
-
- SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&address);
- SCNetworkReachabilityFlags flags;
-
- BOOL didRetrieveFlags =SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags);
- CFRelease(defaultRouteReachability);
-
- if (!didRetrieveFlags)
- {
- printf("Error. Could not recover network reachability flags\n");
- return NO;
- }
-
- BOOL isReachable = flags & kSCNetworkFlagsReachable;
- return isReachable ? YES : NO;;
-}
-
-#pragma mark Checking Connections
-
-+ (void) pingReachabilityInternal
-{
- if (!reachability)
- {
- BOOL ignoresAdHocWiFi = NO;
- struct sockaddr_in ipAddress;
- bzero(&ipAddress, sizeof(ipAddress));
- ipAddress.sin_len = sizeof(ipAddress);
- ipAddress.sin_family = AF_INET;
- ipAddress.sin_addr.s_addr = htonl(ignoresAdHocWiFi ? INADDR_ANY : IN_LINKLOCALNETNUM);
-
- /* Can also create zero addy
- struct sockaddr_in zeroAddress;
- bzero(&zeroAddress, sizeof(zeroAddress));
- zeroAddress.sin_len = sizeof(zeroAddress);
- zeroAddress.sin_family = AF_INET; */
-
- reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (struct sockaddr *)&ipAddress);
- CFRetain(reachability);
- }
-
- // Recover reachability flags
- BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(reachability, &connectionFlags);
- if (!didRetrieveFlags) printf("Error. Could not recover network reachability flags\n");
-}
-
-+ (BOOL) networkAvailable
-{
- [self pingReachabilityInternal];
- BOOL isReachable = ((connectionFlags & kSCNetworkFlagsReachable) != 0);
- BOOL needsConnection = ((connectionFlags & kSCNetworkFlagsConnectionRequired) != 0);
- return (isReachable && !needsConnection) ? YES : NO;
-}
-
-+ (BOOL) activeWWAN
-{
- if (![self networkAvailable]) return NO;
- return ((connectionFlags & kSCNetworkReachabilityFlagsIsWWAN) != 0);
-}
-
-+ (BOOL) activeWLAN
-{
- return ([UIDevice localWiFiIPAddress] != nil);
-}
-
-
-#pragma mark WiFi Check and Alert
-+ (void) showAlert: (id) formatstring,...
-{
- va_list arglist;
- if (!formatstring) return;
- va_start(arglist, formatstring);
- id outstring = [[[NSString alloc] initWithFormat:formatstring arguments:arglist] autorelease];
- va_end(arglist);
-
- UIAlertView *av = [[[UIAlertView alloc] initWithTitle:outstring message:nil delegate:nil cancelButtonTitle:@"OK"otherButtonTitles:nil] autorelease];
- [av show];
-}
-
-+ (BOOL) performWiFiCheck
-{
- if (![self networkAvailable] || ![self activeWLAN])
- {
- [self performSelector:@selector(showAlert:) withObject:@"This application requires WiFi. Please enable WiFi in Settings and run this application again." afterDelay:0.5f];
- return NO;
- }
- return YES;
-}
-
-#pragma mark Forcing WWAN connection. Courtesy of Apple. Thank you Apple.
-MyStreamInfoPtr myInfoPtr;
-static void myClientCallback(void *refCon)
-{
- int *val = (int*)refCon;
- printf("myClientCallback entered - value from refCon is %d\n", *val);
-}
-
-+ (BOOL) forceWWAN
-{
- int value = 0;
- myInfoPtr = (MyStreamInfoPtr) StartWWAN(myClientCallback, &value);
- NSLog(@"%@", myInfoPtr ? @"Started WWAN" : @"Failed to start WWAN");
- return (!(myInfoPtr == NULL));
-}
-
-+ (void) shutdownWWAN
-{
- if (myInfoPtr) StopWWAN((MyInfoRef) myInfoPtr);
-}
-
-#pragma mark Monitoring reachability
-static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkConnectionFlags flags, void* info)
-{
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
- [(id)info performSelector:@selector(reachabilityChanged)];
- [pool release];
-}
-
-+ (BOOL) scheduleReachabilityWatcher: (id) watcher
-{
- if (![watcher conformsToProtocol:@protocol(ReachabilityWatcher)])
- {
- NSLog(@"Watcher must conform to ReachabilityWatcher protocol. Cannot continue.");
- return NO;
- }
-
- [self pingReachabilityInternal];
-
- SCNetworkReachabilityContext context = {0, watcher, NULL, NULL, NULL};
- if(SCNetworkReachabilitySetCallback(reachability, ReachabilityCallback, &context))
- {
- if(!SCNetworkReachabilityScheduleWithRunLoop(reachability, CFRunLoopGetCurrent(), kCFRunLoopCommonModes))
- {
- NSLog(@"Error: Could not schedule reachability");
- SCNetworkReachabilitySetCallback(reachability, NULL, NULL);
- return NO;
- }
- }
- else
- {
- NSLog(@"Error: Could not set reachability callback");
- return NO;
- }
-
- return YES;
-}
-
-+ (void) unscheduleReachabilityWatcher
-{
- SCNetworkReachabilitySetCallback(reachability, NULL, NULL);
- if (SCNetworkReachabilityUnscheduleFromRunLoop(reachability, CFRunLoopGetCurrent(), kCFRunLoopCommonModes))
- NSLog(@"Unscheduled reachability");
- else
- NSLog(@"Error: Could not unschedule reachability");
-
- CFRelease(reachability);
- reachability = nil;
-}
-
-#ifdef SUPPORTS_UNDOCUMENTED_API
-#define SBSERVPATH "/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices"
-#define UIKITPATH "/System/Library/Framework/UIKit.framework/UIKit"
-
-// Don't use this code in real life, boys and girls. It is not App Store friendly.
-// It is, however, really nice for testing callbacks
-+ (void) setAPMode: (BOOL) yorn
-{
- mach_port_t *thePort;
- void *uikit = dlopen(UIKITPATH, RTLD_LAZY);
- int (*SBSSpringBoardServerPort)() = dlsym(uikit, "SBSSpringBoardServerPort");
- thePort = (mach_port_t *)SBSSpringBoardServerPort();
- dlclose(uikit);
-
- // Link to SBSetAirplaneModeEnabled
- void *sbserv = dlopen(SBSERVPATH, RTLD_LAZY);
- int (*setAPMode)(mach_port_t* port, BOOL yorn) = dlsym(sbserv, "SBSetAirplaneModeEnabled");
- setAPMode(thePort, yorn);
- dlclose(sbserv);
-}
-
-// This uses the NSHost class illicitly
-+ (BOOL) networkAvailableByNSHost
-{
- // Unavailable has only one address: 127.0.0.1
- return !(([[[NSHost currentHost] addresses] count] == 1) &&
- [[UIDevice localIPAddress] isEqualToString:@"127.0.0.1"]);
-}
-#endif
-@end
View
1  do-git
@@ -5,7 +5,6 @@ if ($#argv != 1) then
exit 1
endif
-cp ../UIDevice/*.[hm] .
rm -rf build
rm .DS_Store
rm */.DS_Store

0 comments on commit 2f93e22

Please sign in to comment.
Something went wrong with that request. Please try again.