Permalink
Browse files

Partial update

1 parent 8f40fe5 commit 619c159826613d0851cf200f4be41b7a2fe5a762 @erica committed Jul 2, 2012
View
54 HelloWorld.xcodeproj/project.pbxproj
@@ -14,16 +14,14 @@
8E03075512382230000616A0 /* GraphicsServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8E03075412382230000616A0 /* GraphicsServices.framework */; };
8E278438101E6BCE002772F5 /* wwanconnect.c in Sources */ = {isa = PBXBuildFile; fileRef = 8E278431101E6BCE002772F5 /* wwanconnect.c */; };
8E3A1F090FAA199F009B0518 /* cover320x416.png in Resources */ = {isa = PBXBuildFile; fileRef = 8E3A1F080FAA199F009B0518 /* cover320x416.png */; };
- 8E3E64BD1028A0EB0009F50A /* UIDevice-IOKitExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E3E64B91028A0EB0009F50A /* UIDevice-IOKitExtensions.m */; };
- 8E3E64BE1028A0EB0009F50A /* UIDevice-Hardware.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E3E64BA1028A0EB0009F50A /* UIDevice-Hardware.m */; };
- 8E3E79ED1237E44200FAD883 /* UIDevice-Capabilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E3E79EC1237E44200FAD883 /* UIDevice-Capabilities.m */; };
8E4156E90FA4EE0E0006D27C /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 8E4156E70FA4EE0E0006D27C /* Default.png */; };
8E4156EA0FA4EE0E0006D27C /* icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 8E4156E80FA4EE0E0006D27C /* icon.png */; };
- 8E43B864114EA15D0079785E /* UIDevice-Orientation.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E43B863114EA15D0079785E /* UIDevice-Orientation.m */; };
8E785FCB0FCDB853006EA81F /* TestBedViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8E785FCA0FCDB853006EA81F /* TestBedViewController.xib */; };
8E7EA6631028A1A7004DB9E8 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8E7EA6621028A1A7004DB9E8 /* IOKit.framework */; };
- 8E9B2341101E2BB0005DB65B /* UIDevice-Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E9B233E101E2BB0005DB65B /* UIDevice-Reachability.m */; };
8E9B2373101E2D3A005DB65B /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8E9B2372101E2D3A005DB65B /* SystemConfiguration.framework */; };
+ 8EC1C37815A2387100C782C4 /* UIDevice-Hardware.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EC1C37715A2387100C782C4 /* UIDevice-Hardware.m */; };
+ 8EC1C37B15A2387C00C782C4 /* UIDevice-Orientation.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EC1C37A15A2387C00C782C4 /* UIDevice-Orientation.m */; };
+ 8EC1C38515A2392400C782C4 /* UIDevice-Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EC1C38415A2392400C782C4 /* UIDevice-Reachability.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -38,23 +36,23 @@
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>"; };
- 8E3E64B71028A0EB0009F50A /* UIDevice-Hardware.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice-Hardware.h"; sourceTree = "<group>"; };
8E3E64B91028A0EB0009F50A /* UIDevice-IOKitExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice-IOKitExtensions.m"; sourceTree = "<group>"; };
- 8E3E64BA1028A0EB0009F50A /* UIDevice-Hardware.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice-Hardware.m"; sourceTree = "<group>"; };
8E3E64BB1028A0EB0009F50A /* UIDevice-IOKitExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice-IOKitExtensions.h"; sourceTree = "<group>"; };
8E3E79EB1237E44200FAD883 /* UIDevice-Capabilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice-Capabilities.h"; sourceTree = "<group>"; };
8E3E79EC1237E44200FAD883 /* UIDevice-Capabilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice-Capabilities.m"; sourceTree = "<group>"; };
8E4156E70FA4EE0E0006D27C /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = "<group>"; };
8E4156E80FA4EE0E0006D27C /* icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = icon.png; sourceTree = "<group>"; };
- 8E43B862114EA15D0079785E /* UIDevice-Orientation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice-Orientation.h"; sourceTree = "<group>"; };
- 8E43B863114EA15D0079785E /* UIDevice-Orientation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice-Orientation.m"; sourceTree = "<group>"; };
8E785FCA0FCDB853006EA81F /* TestBedViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = TestBedViewController.xib; sourceTree = "<group>"; };
8E7D45921128878A00B184C5 /* Default-Landscape.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-Landscape.png"; sourceTree = "<group>"; };
8E7D45931128878A00B184C5 /* Default-Portrait.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-Portrait.png"; sourceTree = "<group>"; };
8E7EA6621028A1A7004DB9E8 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
- 8E9B233D101E2BB0005DB65B /* UIDevice-Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice-Reachability.h"; sourceTree = "<group>"; };
- 8E9B233E101E2BB0005DB65B /* UIDevice-Reachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice-Reachability.m"; sourceTree = "<group>"; };
8E9B2372101E2D3A005DB65B /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
+ 8EC1C37615A2387100C782C4 /* UIDevice-Hardware.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice-Hardware.h"; sourceTree = "<group>"; };
+ 8EC1C37715A2387100C782C4 /* UIDevice-Hardware.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice-Hardware.m"; sourceTree = "<group>"; };
+ 8EC1C37915A2387C00C782C4 /* UIDevice-Orientation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice-Orientation.h"; sourceTree = "<group>"; };
+ 8EC1C37A15A2387C00C782C4 /* UIDevice-Orientation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice-Orientation.m"; sourceTree = "<group>"; };
+ 8EC1C38315A2392400C782C4 /* UIDevice-Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice-Reachability.h"; sourceTree = "<group>"; };
+ 8EC1C38415A2392400C782C4 /* UIDevice-Reachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice-Reachability.m"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -86,16 +84,16 @@
isa = PBXGroup;
children = (
29B97316FDCFA39411CA2CEA /* main.m */,
- 8E3E64B71028A0EB0009F50A /* UIDevice-Hardware.h */,
- 8E3E64BA1028A0EB0009F50A /* UIDevice-Hardware.m */,
+ 8EC1C37915A2387C00C782C4 /* UIDevice-Orientation.h */,
+ 8EC1C37A15A2387C00C782C4 /* UIDevice-Orientation.m */,
+ 8EC1C37615A2387100C782C4 /* UIDevice-Hardware.h */,
+ 8EC1C37715A2387100C782C4 /* UIDevice-Hardware.m */,
8E3E79EB1237E44200FAD883 /* UIDevice-Capabilities.h */,
8E3E79EC1237E44200FAD883 /* UIDevice-Capabilities.m */,
+ 8EC1C38315A2392400C782C4 /* UIDevice-Reachability.h */,
+ 8EC1C38415A2392400C782C4 /* UIDevice-Reachability.m */,
8E3E64BB1028A0EB0009F50A /* UIDevice-IOKitExtensions.h */,
8E3E64B91028A0EB0009F50A /* UIDevice-IOKitExtensions.m */,
- 8E9B233D101E2BB0005DB65B /* UIDevice-Reachability.h */,
- 8E9B233E101E2BB0005DB65B /* UIDevice-Reachability.m */,
- 8E43B862114EA15D0079785E /* UIDevice-Orientation.h */,
- 8E43B863114EA15D0079785E /* UIDevice-Orientation.m */,
8E27843B101E6BD3002772F5 /* Apple */,
8EB688610FA64AD100489E4B /* Support */,
29B97323FDCFA39411CA2CEA /* Frameworks */,
@@ -205,12 +203,10 @@
buildActionMask = 2147483647;
files = (
1D60589B0D05DD56006BFB54 /* main.m in Sources */,
- 8E9B2341101E2BB0005DB65B /* UIDevice-Reachability.m in Sources */,
8E278438101E6BCE002772F5 /* wwanconnect.c in Sources */,
- 8E3E64BD1028A0EB0009F50A /* UIDevice-IOKitExtensions.m in Sources */,
- 8E3E64BE1028A0EB0009F50A /* UIDevice-Hardware.m in Sources */,
- 8E43B864114EA15D0079785E /* UIDevice-Orientation.m in Sources */,
- 8E3E79ED1237E44200FAD883 /* UIDevice-Capabilities.m in Sources */,
+ 8EC1C37815A2387100C782C4 /* UIDevice-Hardware.m in Sources */,
+ 8EC1C37B15A2387C00C782C4 /* UIDevice-Orientation.m in Sources */,
+ 8EC1C38515A2392400C782C4 /* UIDevice-Reachability.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -220,6 +216,7 @@
1D6058940D05DD3E006BFB54 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_ARC = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Erica Sadun";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
@@ -233,16 +230,18 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = HelloWorld_Prefix.pch;
INFOPLIST_FILE = Info.plist;
+ IPHONEOS_DEPLOYMENT_TARGET = 5.1;
PREBINDING = NO;
PRODUCT_NAME = HelloWorld;
- SDKROOT = iphoneos4.1;
+ SDKROOT = iphoneos5.1;
TARGETED_DEVICE_FAMILY = 1;
};
name = Debug;
};
1D6058950D05DD3E006BFB54 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ CLANG_ENABLE_OBJC_ARC = YES;
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
FRAMEWORK_SEARCH_PATHS = (
@@ -253,9 +252,10 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = HelloWorld_Prefix.pch;
INFOPLIST_FILE = Info.plist;
+ IPHONEOS_DEPLOYMENT_TARGET = 5.1;
PREBINDING = NO;
PRODUCT_NAME = HelloWorld;
- SDKROOT = iphoneos3.2;
+ SDKROOT = iphoneos5.1;
TARGETED_DEVICE_FAMILY = "1,2";
WRAPPER_EXTENSION = app;
};
@@ -266,6 +266,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_IDENTITY = "Erica Sadun";
"CODE_SIGN_IDENTITY[sdk=iphonesimulator*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99;
@@ -274,16 +275,17 @@
ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO;
PRODUCT_NAME = "";
- SDKROOT = iphoneos3.0;
+ SDKROOT = iphoneos5.1;
};
name = Debug;
};
C01FCF5008A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ CLANG_ENABLE_OBJC_ARC = YES;
PREBINDING = NO;
- SDKROOT = iphoneos2.0;
+ SDKROOT = iphoneos5.1;
};
name = Release;
};
View
6 UIDevice-Capabilities.h
@@ -18,6 +18,12 @@
Thanks DB42
*/
+/*
+
+ This category remains for historic reasons. It is no longer being maintained
+
+ */
+
#define UIDevice720pPlaybackCapability @"720p"
#define UIDeviceARMV6ExecutionCapability @"armv6"
#define UIDeviceARMV7ExecutionCapability @"armv7"
View
39 UIDevice-Hardware.h
@@ -1,6 +1,6 @@
/*
Erica Sadun, http://ericasadun.com
- iPhone Developer's Cookbook, 5.0 Edition
+ iPhone Developer's Cookbook, 6.x Edition
BSD License, Use at your own risk
*/
@@ -12,6 +12,7 @@
#define IPHONE_3G_NAMESTRING @"iPhone 3G"
#define IPHONE_3GS_NAMESTRING @"iPhone 3GS"
#define IPHONE_4_NAMESTRING @"iPhone 4"
+#define IPHONE_4S_NAMESTRING @"iPhone 4S"
#define IPHONE_5_NAMESTRING @"iPhone 5"
#define IPHONE_UNKNOWN_NAMESTRING @"Unknown iPhone"
@@ -24,28 +25,34 @@
#define IPAD_1G_NAMESTRING @"iPad 1G"
#define IPAD_2G_NAMESTRING @"iPad 2G"
#define IPAD_3G_NAMESTRING @"iPad 3G"
+#define IPAD_4G_NAMESTRING @"iPad 4G"
#define IPAD_UNKNOWN_NAMESTRING @"Unknown iPad"
#define APPLETV_2G_NAMESTRING @"Apple TV 2G"
+#define APPLETV_3G_NAMESTRING @"Apple TV 3G"
+#define APPLETV_4G_NAMESTRING @"Apple TV 4G"
#define APPLETV_UNKNOWN_NAMESTRING @"Unknown Apple TV"
#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 SIMULATOR_NAMESTRING @"iPhone Simulator"
+#define SIMULATOR_IPHONE_NAMESTRING @"iPhone Simulator"
+#define SIMULATOR_IPAD_NAMESTRING @"iPad Simulator"
+#define SIMULATOR_APPLETV_NAMESTRING @"Apple TV Simulator" // :)
typedef enum {
UIDeviceUnknown,
- UIDeviceiPhoneSimulator,
- UIDeviceiPhoneSimulatoriPhone, // both regular and iPhone 4 devices
- UIDeviceiPhoneSimulatoriPad,
+ UIDeviceSimulator,
+ UIDeviceSimulatoriPhone,
+ UIDeviceSimulatoriPad,
+ UIDeviceSimulatorAppleTV,
UIDevice1GiPhone,
UIDevice3GiPhone,
UIDevice3GSiPhone,
UIDevice4iPhone,
+ UIDevice4SiPhone,
UIDevice5iPhone,
UIDevice1GiPod,
@@ -56,17 +63,29 @@ typedef enum {
UIDevice1GiPad,
UIDevice2GiPad,
UIDevice3GiPad,
+ UIDevice4GiPad,
UIDeviceAppleTV2,
- UIDeviceUnknownAppleTV,
+ UIDeviceAppleTV3,
+ UIDeviceAppleTV4,
UIDeviceUnknowniPhone,
UIDeviceUnknowniPod,
UIDeviceUnknowniPad,
+ UIDeviceUnknownAppleTV,
UIDeviceIFPGA,
} UIDevicePlatform;
+typedef enum {
+ UIDeviceFamilyiPhone,
+ UIDeviceFamilyiPod,
+ UIDeviceFamilyiPad,
+ UIDeviceFamilyAppleTV,
+ UIDeviceFamilyUnknown,
+
+} UIDeviceFamily;
+
@interface UIDevice (Hardware)
- (NSString *) platform;
- (NSString *) hwmodel;
@@ -75,11 +94,15 @@ typedef enum {
- (NSUInteger) cpuFrequency;
- (NSUInteger) busFrequency;
+- (NSUInteger) cpuCount;
- (NSUInteger) totalMemory;
- (NSUInteger) userMemory;
- (NSNumber *) totalDiskSpace;
- (NSNumber *) freeDiskSpace;
- (NSString *) macaddress;
+
+- (BOOL) hasRetinaDisplay;
+- (UIDeviceFamily) deviceFamily;
@end
View
84 UIDevice-Hardware.m
@@ -1,6 +1,6 @@
/*
Erica Sadun, http://ericasadun.com
- iPhone Developer's Cookbook, 5.0 Edition
+ iPhone Developer's Cookbook, 6.x Edition
BSD License, Use at your own risk
*/
@@ -25,8 +25,12 @@ @implementation UIDevice (Hardware)
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
+ iPhone4,1 -> (iPhone 4S/GSM), TBD
+ iPhone4,2 -> (iPhone 4S/CDMA), TBD
+ iPhone4,3 -> (iPhone 4S/???)
+ iPhone5,1 -> iPhone Next Gen, TBD
+ iPhone5,1 -> iPhone Next Gen, TBD
+ iPhone5,1 -> iPhone Next Gen, TBD
iPod1,1 -> iPod touch 1G, N45
iPod2,1 -> iPod touch 2G, N72
@@ -39,10 +43,15 @@ @implementation UIDevice (Hardware)
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)
+ iPad3,1 -> (iPad 3G, WiFi)
+ iPad3,2 -> (iPad 3G, GSM)
+ iPad3,3 -> (iPad 3G, CDMA)
+ iPad4,1 -> (iPad 4G, WiFi)
+ iPad4,2 -> (iPad 4G, GSM)
+ iPad4,3 -> (iPad 4G, CDMA)
AppleTV2,1 -> AppleTV 2, K66
+ AppleTV3,1 -> AppleTV 3, ??
i386, x86_64 -> iPhone Simulator
*/
@@ -95,6 +104,11 @@ - (NSUInteger) busFrequency
return [self getSysInfo:HW_BUS_FREQ];
}
+- (NSUInteger) cpuCount
+{
+ return [self getSysInfo:HW_NCPU];
+}
+
- (NSUInteger) totalMemory
{
return [self getSysInfo:HW_PHYSMEM];
@@ -111,6 +125,15 @@ - (NSUInteger) maxSocketBufferSize
}
#pragma mark file system -- Thanks Joachim Bean!
+
+/*
+ extern NSString *NSFileSystemSize;
+ extern NSString *NSFileSystemFreeSize;
+ extern NSString *NSFileSystemNodes;
+ extern NSString *NSFileSystemFreeNodes;
+ extern NSString *NSFileSystemNumber;
+*/
+
- (NSNumber *) totalDiskSpace
{
NSDictionary *fattributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil];
@@ -136,10 +159,11 @@ - (NSUInteger) platformType
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 hasPrefix:@"iPhone4"]) return UIDevice4SiPhone;
+ if ([platform hasPrefix:@"iPhone5"]) return UIDevice5iPhone;
// iPod
- if ([platform hasPrefix:@"iPod1"]) return UIDevice1GiPod;
+ if ([platform hasPrefix:@"iPod1"]) return UIDevice1GiPod;
if ([platform hasPrefix:@"iPod2"]) return UIDevice2GiPod;
if ([platform hasPrefix:@"iPod3"]) return UIDevice3GiPod;
if ([platform hasPrefix:@"iPod4"]) return UIDevice4GiPod;
@@ -148,19 +172,22 @@ - (NSUInteger) platformType
if ([platform hasPrefix:@"iPad1"]) return UIDevice1GiPad;
if ([platform hasPrefix:@"iPad2"]) return UIDevice2GiPad;
if ([platform hasPrefix:@"iPad3"]) return UIDevice3GiPad;
+ if ([platform hasPrefix:@"iPad4"]) return UIDevice4GiPad;
// Apple TV
if ([platform hasPrefix:@"AppleTV2"]) return UIDeviceAppleTV2;
+ if ([platform hasPrefix:@"AppleTV3"]) return UIDeviceAppleTV3;
if ([platform hasPrefix:@"iPhone"]) return UIDeviceUnknowniPhone;
if ([platform hasPrefix:@"iPod"]) return UIDeviceUnknowniPod;
if ([platform hasPrefix:@"iPad"]) return UIDeviceUnknowniPad;
+ if ([platform hasPrefix:@"AppleTV"]) return UIDeviceUnknownAppleTV;
- // Simulator thanks Jordan Breeding
+ // 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 smallerScreen ? UIDeviceSimulatoriPhone : UIDeviceSimulatoriPad;
}
return UIDeviceUnknown;
@@ -174,6 +201,7 @@ - (NSString *) platformString
case UIDevice3GiPhone: return IPHONE_3G_NAMESTRING;
case UIDevice3GSiPhone: return IPHONE_3GS_NAMESTRING;
case UIDevice4iPhone: return IPHONE_4_NAMESTRING;
+ case UIDevice4SiPhone: return IPHONE_4S_NAMESTRING;
case UIDevice5iPhone: return IPHONE_5_NAMESTRING;
case UIDeviceUnknowniPhone: return IPHONE_UNKNOWN_NAMESTRING;
@@ -186,21 +214,41 @@ - (NSString *) platformString
case UIDevice1GiPad : return IPAD_1G_NAMESTRING;
case UIDevice2GiPad : return IPAD_2G_NAMESTRING;
case UIDevice3GiPad : return IPAD_3G_NAMESTRING;
+ case UIDevice4GiPad : return IPAD_4G_NAMESTRING;
case UIDeviceUnknowniPad : return IPAD_UNKNOWN_NAMESTRING;
case UIDeviceAppleTV2 : return APPLETV_2G_NAMESTRING;
+ case UIDeviceAppleTV3 : return APPLETV_3G_NAMESTRING;
+ case UIDeviceAppleTV4 : return APPLETV_4G_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 UIDeviceSimulator: return SIMULATOR_NAMESTRING;
+ case UIDeviceSimulatoriPhone: return SIMULATOR_IPHONE_NAMESTRING;
+ case UIDeviceSimulatoriPad: return SIMULATOR_IPAD_NAMESTRING;
+ case UIDeviceSimulatorAppleTV: return SIMULATOR_APPLETV_NAMESTRING;
case UIDeviceIFPGA: return IFPGA_NAMESTRING;
default: return IOS_FAMILY_UNKNOWN_DEVICE;
}
}
+- (BOOL) hasRetinaDisplay
+{
+ return ([UIScreen mainScreen].scale == 2.0f);
+}
+
+- (UIDeviceFamily) deviceFamily
+{
+ NSString *platform = [self platform];
+ if ([platform hasPrefix:@"iPhone"]) return UIDeviceFamilyiPhone;
+ if ([platform hasPrefix:@"iPod"]) return UIDeviceFamilyiPod;
+ if ([platform hasPrefix:@"iPad"]) return UIDeviceFamilyiPad;
+ if ([platform hasPrefix:@"AppleTV"]) return UIDeviceFamilyAppleTV;
+
+ return UIDeviceFamilyUnknown;
+}
+
#pragma mark MAC addy
// Return the local MAC addy
// Courtesy of FreeBSD hackers email list
@@ -231,24 +279,22 @@ - (NSString *) macaddress
}
if ((buf = malloc(len)) == NULL) {
- printf("Could not allocate memory. error!\n");
+ printf("Error: Memory allocation error\n");
return NULL;
}
if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
- printf("Error: sysctl, take 2");
+ printf("Error: sysctl, take 2\n");
+ free(buf); // Thanks, Remy "Psy" Demerest
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 *outstring = [NSString stringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X", *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
+ free(buf);
return outstring;
}
View
6 UIDevice-IOKitExtensions.h
@@ -30,6 +30,12 @@
* To use, you must add the (semi)public IOKit framework before compiling
*/
+/*
+
+ This category is no longer maintained.
+
+ */
+
#if SUPPORTS_IOKIT_EXTENSIONS
@interface UIDevice (IOKit_Extensions)
- (NSString *) imei;
View
11 UIDevice-Orientation.h
@@ -1,19 +1,20 @@
/*
Erica Sadun, http://ericasadun.com
- iPhone Developer's Cookbook, 3.0 Edition
+ iPhone Developer's Cookbook, 6.0 Edition
BSD License, Use at your own risk
*/
#import <UIKit/UIKit.h>
-
+#import <CoreMotion/CoreMotion.h>
@interface UIDevice (Orientation) <UIAccelerometerDelegate>
-- (BOOL) isLandscape;
-- (BOOL) isPortrait;
-- (NSString *) orientationString;
- (float) orientationAngleRelativeToOrientation:(UIDeviceOrientation) someOrientation;
++ (NSString *) orientationString: (UIDeviceOrientation) orientation;
+
@property (nonatomic, readonly) BOOL isLandscape;
@property (nonatomic, readonly) BOOL isPortrait;
@property (nonatomic, readonly) NSString *orientationString;
@property (nonatomic, readonly) float orientationAngle;
+@property (nonatomic, readonly) UIDeviceOrientation acceleratorBasedOrientation;
+
@end
View
64 UIDevice-Orientation.m
@@ -1,6 +1,6 @@
/*
Erica Sadun, http://ericasadun.com
- iPhone Developer's Cookbook, 3.0 Edition
+ iPhone Developer's Cookbook, 6.0 Edition
BSD License, Use at your own risk
*/
@@ -9,23 +9,24 @@
#import "UIDevice-Orientation.h"
@implementation UIDevice (Orientation)
-
-float device_angle;
-CFRunLoopRef currentLoop;
+#pragma mark current angle
+CGFloat device_angle;
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
- float xx = [acceleration x];
- float yy = -[acceleration y];
+ CGFloat xx = acceleration.x;
+ CGFloat yy = -acceleration.y;
device_angle = M_PI / 2.0f - atan2(yy, xx);
+
+ if (device_angle > M_PI)
+ device_angle -= 2 * M_PI;
- CFRunLoopStop(currentLoop);
+ CFRunLoopStop(CFRunLoopGetCurrent());
}
-- (float) orientationAngle
+- (CGFloat) orientationAngle
{
#if TARGET_IPHONE_SIMULATOR
- // NSLog( @"Running in the simulator!" );
switch (self.orientation)
{
case UIDeviceOrientationPortrait:
@@ -40,22 +41,39 @@ - (float) orientationAngle
return 0.0f;
}
#else
- id accelerometer_delegate = [UIAccelerometer sharedAccelerometer].delegate;
+ // supercede current delegate
+ id priorDelegate = [UIAccelerometer sharedAccelerometer].delegate;
[UIAccelerometer sharedAccelerometer].delegate = self;
// Wait for a reading
- currentLoop = CFRunLoopGetCurrent();
CFRunLoopRun();
- [UIAccelerometer sharedAccelerometer].delegate = accelerometer_delegate;
+
+ // restore delgate
+ [UIAccelerometer sharedAccelerometer].delegate = priorDelegate;
return device_angle;
#endif
}
+// Limited to the four portrait/landscape options
+- (UIDeviceOrientation) acceleratorBasedOrientation
+{
+ CGFloat baseAngle = self.orientationAngle;
+ if ((baseAngle > -M_PI_4) && (baseAngle < M_PI_4))
+ return UIDeviceOrientationPortrait;
+ if ((baseAngle < -M_PI_4) && (baseAngle > -3 * M_PI_4))
+ return UIDeviceOrientationLandscapeLeft;
+ if ((baseAngle > M_PI_4) && (baseAngle < 3 * M_PI_4))
+ return UIDeviceOrientationLandscapeRight;
+ return UIDeviceOrientationPortraitUpsideDown;
+}
+
+#pragma mark relative orientation
+
// Thanks Jonah Williams
-- (float) orientationAngleRelativeToOrientation:(UIDeviceOrientation) someOrientation
+- (CGFloat) orientationAngleRelativeToOrientation:(UIDeviceOrientation) someOrientation
{
- float dOrientation = 0.0f;
+ CGFloat dOrientation = 0.0f;
switch (someOrientation)
{
case UIDeviceOrientationPortraitUpsideDown: {dOrientation = M_PI; break;}
@@ -64,11 +82,14 @@ - (float) orientationAngleRelativeToOrientation:(UIDeviceOrientation) someOrient
default: break;
}
- float adjustedAngle = fmod(self.orientationAngle - dOrientation, 2.0f * M_PI);
- if (adjustedAngle > (M_PI + 0.01f)) adjustedAngle = (adjustedAngle - 2.0f * M_PI);
+ CGFloat adjustedAngle = fmod(self.orientationAngle - dOrientation, 2.0f * M_PI);
+ if (adjustedAngle > (M_PI + 0.01f))
+ adjustedAngle = (adjustedAngle - 2.0f * M_PI);
return adjustedAngle;
}
+#pragma mark basic orientation
+
- (BOOL) isLandscape
{
return UIDeviceOrientationIsLandscape(self.orientation);
@@ -79,9 +100,10 @@ - (BOOL) isPortrait
return UIDeviceOrientationIsPortrait(self.orientation);
}
-- (NSString *) orientationString
+// Transform to real world-readable string for arbitrary orientation
++ (NSString *) orientationString: (UIDeviceOrientation) orientation
{
- switch ([[UIDevice currentDevice] orientation])
+ switch (orientation)
{
case UIDeviceOrientationUnknown: return @"Unknown";
case UIDeviceOrientationPortrait: return @"Portrait";
@@ -94,4 +116,10 @@ - (NSString *) orientationString
}
return nil;
}
+
+// String for current orientaiton
+- (NSString *) orientationString
+{
+ return [UIDevice orientationString:self.orientation];
+}
@end
View
50 UIDevice-Reachability.h
@@ -1,28 +1,26 @@
/*
Erica Sadun, http://ericasadun.com
- iPhone Developer's Cookbook, 3.0 Edition
+ iPhone Developer's Cookbook, 5.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;
++ (NSData *) dataFromAddress: (struct sockaddr_in) address;
++ (NSString *) addressFromData:(NSData *) addressData;
++ (NSString *) portFromData:(NSData *) addressData;
+
- (NSString *) hostname;
- (NSString *) getIPAddressForHost: (NSString *) theHost;
- (NSString *) localIPAddress;
- (NSString *) localWiFiIPAddress;
++ (NSArray *) localWiFiIPAddresses;
- (NSString *) whatismyipdotcom;
- (BOOL) hostAvailable: (NSString *) theHost;
@@ -36,38 +34,4 @@
- (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
-
+@end
View
127 UIDevice-Reachability.m
@@ -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 for anything not specifically marked as developed by a third party.
Apple's code excluded.
Use at your own risk
@@ -27,8 +27,9 @@ @implementation UIDevice (Reachability)
+ (NSString *) stringFromAddress: (const struct sockaddr *) address
{
- if(address && address->sa_family == AF_INET) {
- const struct sockaddr_in* sin = (struct sockaddr_in*) 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)];
}
@@ -37,23 +38,53 @@ + (NSString *) stringFromAddress: (const struct sockaddr *) address
+ (BOOL)addressFromString:(NSString *)IPAddress address:(struct sockaddr_in *)address
{
- if (!IPAddress || ![IPAddress length]) {
- return NO;
- }
+ 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) {
+ if (conversionResult == 0)
+ {
NSAssert1(conversionResult != 1, @"Failed to convert the IP address string into a sockaddr_in: %@", IPAddress);
return NO;
}
return YES;
}
++ (NSString *) addressFromData:(NSData *) addressData
+{
+ NSString *adr = nil;
+
+ if (addressData != nil)
+ {
+ struct sockaddr_in addrIn = *(struct sockaddr_in *)[addressData bytes];
+ adr = [NSString stringWithFormat: @"%s", inet_ntoa(addrIn.sin_addr)];
+ }
+
+ return adr;
+}
+
++ (NSString *) portFromData:(NSData *) addressData
+{
+ NSString *port = nil;
+
+ if (addressData != nil)
+ {
+ struct sockaddr_in addrIn = *(struct sockaddr_in *)[addressData bytes];
+ port = [NSString stringWithFormat: @"%s", ntohs(addrIn.sin_port)];
+ }
+
+ return port;
+}
+
++ (NSData *) dataFromAddress: (struct sockaddr_in) address
+{
+ return [NSData dataWithBytes:&address length:sizeof(struct sockaddr_in)];
+}
+
- (NSString *) hostname
{
char baseHostName[256]; // Thanks, Gunnar Larisch
@@ -88,6 +119,8 @@ - (NSString *) localIPAddress
// 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
+// Updates: changed en0 to en.
+// More updates: TBD
- (NSString *) localWiFiIPAddress
{
BOOL success;
@@ -102,7 +135,7 @@ - (NSString *) localWiFiIPAddress
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
+ if ([name isEqualToString:@"en"]) // Wi-Fi adapter -- was en0
return [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)cursor->ifa_addr)->sin_addr)];
}
cursor = cursor->ifa_next;
@@ -112,6 +145,36 @@ - (NSString *) localWiFiIPAddress
return nil;
}
++ (NSArray *) localWiFiIPAddresses
+{
+ BOOL success;
+ struct ifaddrs * addrs;
+ const struct ifaddrs * cursor;
+
+ NSMutableArray *array = [NSMutableArray array];
+
+ 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 hasPrefix:@"en"])
+ [array addObject:[NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)cursor->ifa_addr)->sin_addr)]];
+ }
+ cursor = cursor->ifa_next;
+ }
+ freeifaddrs(addrs);
+ }
+
+ if (array.count) return array;
+
+ return nil;
+}
+
+
- (NSString *) whatismyipdotcom
{
NSError *error;
@@ -209,10 +272,10 @@ - (void) privateShowAlert: (id) formatstring,...
va_list arglist;
if (!formatstring) return;
va_start(arglist, formatstring);
- id outstring = [[[NSString alloc] initWithFormat:formatstring arguments:arglist] autorelease];
+ id outstring = [[NSString alloc] initWithFormat:formatstring arguments:arglist];
va_end(arglist);
- UIAlertView *av = [[[UIAlertView alloc] initWithTitle:outstring message:nil delegate:nil cancelButtonTitle:@"OK"otherButtonTitles:nil] autorelease];
+ UIAlertView *av = [[UIAlertView alloc] initWithTitle:outstring message:nil delegate:nil cancelButtonTitle:@"OK"otherButtonTitles:nil];
[av show];
}
@@ -250,22 +313,24 @@ - (void) shutdownWWAN
#pragma mark Monitoring reachability
static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkConnectionFlags flags, void* info)
{
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
- [(id)info performSelector:@selector(reachabilityChanged)];
- [pool release];
+ @autoreleasepool {
+ id watcher = (__bridge id) info;
+ if ([watcher respondsToSelector:@selector(reachabilityChanged)])
+ [watcher performSelector:@selector(reachabilityChanged)];
+ }
}
- (BOOL) scheduleReachabilityWatcher: (id) watcher
{
- if (![watcher conformsToProtocol:@protocol(ReachabilityWatcher)])
+ if (![watcher respondsToSelector:@selector(reachabilityChanged)])
{
- NSLog(@"Watcher must conform to ReachabilityWatcher protocol. Cannot continue.");
+ NSLog(@"Watcher must implement reachabilityChanged callback. Cannot continue.");
return NO;
}
[self pingReachabilityInternal];
- SCNetworkReachabilityContext context = {0, watcher, NULL, NULL, NULL};
+ SCNetworkReachabilityContext context = {0, (__bridge void *)watcher, NULL, NULL, NULL};
if(SCNetworkReachabilitySetCallback(reachability, ReachabilityCallback, &context))
{
if(!SCNetworkReachabilityScheduleWithRunLoop(reachability, CFRunLoopGetCurrent(), kCFRunLoopCommonModes))
@@ -295,34 +360,4 @@ - (void) unscheduleReachabilityWatcher
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 currentDevice] localIPAddress] isEqualToString:@"127.0.0.1"]);
-}
-#endif
@end
View
133 main.m
@@ -1,123 +1,70 @@
/*
Erica Sadun, http://ericasadun.com
- iPhone Developer's Cookbook, 3.0 Edition
+ iPhone Developer's Cookbook, 6.x Edition
BSD License, Use at your own risk
*/
#import <UIKit/UIKit.h>
-#import "UIDevice-Reachability.h"
-#import "UIDevice-IOKitExtensions.h"
-#import "UIDevice-Hardware.h"
-#import "UIDevice-Capabilities.h"
#import "UIDevice-Orientation.h"
-#define COOKBOOK_PURPLE_COLOR [UIColor colorWithRed:0.20392f green:0.19607f blue:0.61176f alpha:1.0f]
-#define BARBUTTON(TITLE, SELECTOR) [[[UIBarButtonItem alloc] initWithTitle:TITLE style:UIBarButtonItemStylePlain target:self action:SELECTOR] autorelease]
-#define CFN(X) [self commasForNumber:X]
+#define COOKBOOK_PURPLE_COLOR [UIColor colorWithRed:0.20392f green:0.19607f blue:0.61176f alpha:1.0f]
+#define BARBUTTON(TITLE, SELECTOR) [[UIBarButtonItem alloc] initWithTitle:TITLE style:UIBarButtonItemStylePlain target:self action:SELECTOR]
+#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
+
+#define CONSTRAIN(VIEW, FORMAT) [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:(FORMAT) options:0 metrics:nil views:NSDictionaryOfVariableBindings(VIEW)]]
+#define PREPCONSTRAINTS(VIEW) [VIEW setTranslatesAutoresizingMaskIntoConstraints:NO]
@interface TestBedViewController : UIViewController
-{
- NSMutableString *log;
- IBOutlet UITextView *textView;
-}
-@property (retain) NSMutableString *log;
-@property (retain) UITextView *textView;
@end
@implementation TestBedViewController
-@synthesize log;
-@synthesize textView;
-
-- (void) doLog: (NSString *) formatstring, ...
-{
- va_list arglist;
- if (!formatstring) return;
- va_start(arglist, formatstring);
- NSString *outstring = [[[NSString alloc] initWithFormat:formatstring arguments:arglist] autorelease];
- va_end(arglist);
-
- NSLog(@"%@", outstring);
-
- [self.log appendString:outstring];
- [self.log appendString:@"\n"];
- self.textView.text = self.log;
-}
-- (NSString *) commasForNumber: (long long) num
+- (void) showOrientation: (NSNotification *) notification
{
- if (num < 1000) return [NSString stringWithFormat:@"%d", num];
- return [[self commasForNumber:num/1000] stringByAppendingFormat:@",%03d", (num % 1000)];
+ NSString *orientationString = [UIDevice orientationString:[UIDevice currentDevice].acceleratorBasedOrientation];
+ NSLog(@"%@", orientationString);
+ self.title = orientationString;
}
-- (void) action: (UIBarButtonItem *) bbi
+- (void) loadView
{
- self.log = [NSMutableString string];
- [[UIDevice currentDevice] scanCapabilities];
-
- // [self doLog:@"Adjusted Orientation Angle: %f\n", [[UIDevice currentDevice] orientationAngleRelativeToOrientation:UIDeviceOrientationLandscapeLeft]];
-
- // TESTING REACHABILITY
- /*
- [self doLog:@"Host Name: %@", [[UIDevice currentDevice] hostname]];
- [self doLog:@"Local IP Addy: %@", [[UIDevice currentDevice] localIPAddress]];
- [self doLog:@" Google IP Addy: %@", [[UIDevice currentDevice] getIPAddressForHost:@"www.google.com"]];
- [self doLog:@" Amazon IP Addy: %@", [[UIDevice currentDevice] getIPAddressForHost:@"www.amazon.com"]];
- [self doLog:@"Local WiFI Addy: %@", [[UIDevice currentDevice] localWiFiIPAddress]];
- if ([[UIDevice currentDevice] networkAvailable])
- [self doLog:@"What is My IP: %@", [[UIDevice currentDevice] whatismyipdotcom]];
- */
-
- // TESTING IOKIT
- /*
- [self doLog:[[UIDevice currentDevice] imei]];
- [self doLog:[[UIDevice currentDevice] serialnumber]];
- */
-
- // 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"];
- [self doLog:@"Orientation: %@", [UIDevice currentDevice].orientationString];
- [self doLog:@"Platform: %@", [[UIDevice currentDevice] platform]];
- [self doLog:@"Platform String: %@", [[UIDevice currentDevice] platformString]];
- [self doLog:@"Platform Code: %@", [[UIDevice currentDevice] platformCode]];
- [self doLog:@"CPU Freq: %d\nBus Freq: %@\nTotal Memory: %@\nUser Memory: %@", CFN([[UIDevice currentDevice] cpuFrequency]), CFN([[UIDevice currentDevice] busFrequency]), CFN([[UIDevice currentDevice] totalMemory]), CFN([[UIDevice currentDevice] userMemory])];
- [self doLog:@"Mac addy: %@", [[UIDevice currentDevice] macaddress]];
- */
+ [super loadView];
+ self.view.backgroundColor = [UIColor whiteColor];
+
+ [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(showOrientation:) userInfo:nil repeats:YES];
}
-- (void) viewDidLoad
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
- self.navigationController.navigationBar.tintColor = COOKBOOK_PURPLE_COLOR;
- self.navigationItem.rightBarButtonItem = BARBUTTON(@"Action", @selector(action:));
- if ([[[UIDevice currentDevice] platformString] hasPrefix:@"iPad"])
- {
- UIImageView *imgView = (UIImageView *)[self.view viewWithTag:999];
- imgView.frame = [[UIScreen mainScreen] applicationFrame];
- imgView.image = [UIImage imageNamed:([[UIDevice currentDevice] isLandscape]) ? @"Default-Landscape.png" : @"Default-Portrait.png"];
- }
+ return YES;
}
@end
+#pragma mark -
+
+#pragma mark Application Setup
@interface TestBedAppDelegate : NSObject <UIApplicationDelegate>
+{
+ UIWindow *window;
+}
@end
-
@implementation TestBedAppDelegate
-- (void)applicationDidFinishLaunching:(UIApplication *)application {
- UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[TestBedViewController alloc] init]];
- [window addSubview:nav.view];
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+ // [application setStatusBarHidden:YES];
+ [[UINavigationBar appearance] setTintColor:COOKBOOK_PURPLE_COLOR];
+
+ window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+ TestBedViewController *tbvc = [[TestBedViewController alloc] init];
+ UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:tbvc];
+ window.rootViewController = nav;
[window makeKeyAndVisible];
+ return YES;
}
@end
-
-int main(int argc, char *argv[])
-{
- NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
- int retVal = UIApplicationMain(argc, argv, nil, @"TestBedAppDelegate");
- [pool release];
- return retVal;
-}
+int main(int argc, char *argv[]) {
+ @autoreleasepool {
+ int retVal = UIApplicationMain(argc, argv, nil, @"TestBedAppDelegate");
+ return retVal;
+ }
+}

0 comments on commit 619c159

Please sign in to comment.