Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iPad 4 Models #20

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
/build

/.DS_Store
2 changes: 1 addition & 1 deletion Apple Sample Code/wwanconnect.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ extern MyInfoRef StartWWAN(ConnectClientCallBack clientCB, void *refCon)
CFStreamClientContext ctxt = {0, NULL, NULL, NULL, NULL};
Boolean errorOccurred = FALSE;

myInfoPtr = malloc(sizeof(MyStreamInfo));
myInfoPtr = ( MyStreamInfoPtr )malloc(sizeof(MyStreamInfo));
if (!myInfoPtr)
{
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion UIDevice-Capabilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ - (BOOL) supportsCapability: (NSString *) capability
void *libHandle = dlopen(GRAPHICS_SERVICES_PATH, RTLD_LAZY);
int (*GSSystemHasCapability)(NSString *);
GSSystemHasCapability = dlsym(libHandle, "GSSystemHasCapability");
BOOL result = GSSystemHasCapability(capability);
BOOL result = ( BOOL )GSSystemHasCapability(capability);
dlclose(libHandle);
return result;
}
Expand Down
11 changes: 11 additions & 0 deletions UIDevice-Hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#define IPAD_4G_NAMESTRING @"iPad 4G"
#define IPAD_UNKNOWN_NAMESTRING @"Unknown iPad"

#define IPAD_MINI_NAMESTRING @"iPad Mini"

#define APPLETV_2G_NAMESTRING @"Apple TV 2G"
#define APPLETV_3G_NAMESTRING @"Apple TV 3G"
#define APPLETV_4G_NAMESTRING @"Apple TV 4G"
Expand Down Expand Up @@ -65,6 +67,8 @@ typedef enum {
UIDevice3GiPad,
UIDevice4GiPad,

UIDeviceiPadMini,

UIDeviceAppleTV2,
UIDeviceAppleTV3,
UIDeviceAppleTV4,
Expand Down Expand Up @@ -104,5 +108,12 @@ typedef enum {
- (NSString *) macaddress;

- (BOOL) hasRetinaDisplay;
- (NSString *) imageSuffixRetinaDisplay;
- (BOOL) has4InchDisplay;
- (NSString *) imageSuffix4InchDisplay;

- (UIDeviceFamily) deviceFamily;

- (float) cameraFieldOfView;

@end
64 changes: 62 additions & 2 deletions UIDevice-Hardware.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ @implementation UIDevice (Hardware)
iPad3,1 -> (iPad 3G, WiFi)
iPad3,2 -> (iPad 3G, GSM)
iPad3,3 -> (iPad 3G, CDMA)
iPad3,4 -> (iPad 4G, WiFi)
iPad4,1 -> (iPad 4G, WiFi)
iPad4,2 -> (iPad 4G, GSM)
iPad4,3 -> (iPad 4G, CDMA)

iPad2,5 -> (iPad Mini, Wifi)

AppleTV2,1 -> AppleTV 2, K66
AppleTV3,1 -> AppleTV 3, ??
Expand Down Expand Up @@ -146,6 +149,18 @@ - (NSNumber *) freeDiskSpace
return [fattributes objectForKey:NSFileSystemFreeSize];
}

+( NSInteger )getSubmodel:( NSString* )platform
{
NSInteger submodel = -1;

NSArray* components = [ platform componentsSeparatedByString:@"," ];
if ( [ components count ] >= 2 )
{
submodel = [ [ components objectAtIndex:1 ] intValue ];
}
return submodel;
}

#pragma mark platform type and name utils
- (NSUInteger) platformType
{
Expand All @@ -170,8 +185,28 @@ - (NSUInteger) platformType

// iPad
if ([platform hasPrefix:@"iPad1"]) return UIDevice1GiPad;
if ([platform hasPrefix:@"iPad2"]) return UIDevice2GiPad;
if ([platform hasPrefix:@"iPad3"]) return UIDevice3GiPad;
if ([platform hasPrefix:@"iPad2"])
{
NSInteger submodel = [ UIDevice getSubmodel:platform ];
if ( submodel <= 4 )
{
return UIDevice2GiPad;
} else
{
return UIDeviceiPadMini;
}
}
if ([platform hasPrefix:@"iPad3"])
{
NSInteger submodel = [ UIDevice getSubmodel:platform ];
if ( submodel <= 3 )
{
return UIDevice3GiPad;
} else
{
return UIDevice4GiPad;
}
}
if ([platform hasPrefix:@"iPad4"]) return UIDevice4GiPad;

// Apple TV
Expand Down Expand Up @@ -217,6 +252,8 @@ - (NSString *) platformString
case UIDevice4GiPad : return IPAD_4G_NAMESTRING;
case UIDeviceUnknowniPad : return IPAD_UNKNOWN_NAMESTRING;

case UIDeviceiPadMini : return IPAD_MINI_NAMESTRING;

case UIDeviceAppleTV2 : return APPLETV_2G_NAMESTRING;
case UIDeviceAppleTV3 : return APPLETV_3G_NAMESTRING;
case UIDeviceAppleTV4 : return APPLETV_4G_NAMESTRING;
Expand All @@ -238,6 +275,21 @@ - (BOOL) hasRetinaDisplay
return ([UIScreen mainScreen].scale == 2.0f);
}

- (NSString *) imageSuffixRetinaDisplay
{
return @"@2x";
}

- (BOOL) has4InchDisplay
{
return ([UIScreen mainScreen].bounds.size.height == 568);
}

- (NSString *) imageSuffix4InchDisplay
{
return @"-568h";
}

- (UIDeviceFamily) deviceFamily
{
NSString *platform = [self platform];
Expand Down Expand Up @@ -308,4 +360,12 @@ - (NSString *) macaddress
printf("Bluetooth %s enabled\n", bluetooth ? "is" : "isn't");
}
*/

- (float) cameraFieldOfView
{
// TODO: fill out and test for all iDevice models
// http://www.caramba-apps.com/blog/files/field-of-view-angles-ipad-iphone.html
return 58.498f;
}

@end
28 changes: 17 additions & 11 deletions UIDevice-Orientation.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@
#import "UIDevice-Orientation.h"

@implementation UIDevice (Orientation)
const CGFloat to_angle_upside_down = ( CGFloat )M_PI;
const CGFloat to_angle_landscape_left = ( CGFloat )-( M_PI/2.0f );
const CGFloat to_angle_landscape_right = ( CGFloat )( M_PI/2.0f );

const CGFloat from_angle = ( CGFloat )( M_PI * 2.0f );

#pragma mark current angle
CGFloat device_angle;

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
CGFloat xx = acceleration.x;
CGFloat yy = -acceleration.y;
device_angle = M_PI / 2.0f - atan2(yy, xx);
double xx = acceleration.x;
double yy = -acceleration.y;
device_angle = ( CGFloat )( M_PI / 2.0f - atan2(yy, xx) );

if (device_angle > M_PI)
device_angle -= 2 * M_PI;
Expand All @@ -32,11 +38,11 @@ - (CGFloat) orientationAngle
case UIDeviceOrientationPortrait:
return 0.0f;
case UIDeviceOrientationPortraitUpsideDown:
return M_PI;
return to_angle_upside_down;
case UIDeviceOrientationLandscapeLeft:
return -(M_PI/2.0f);
return to_angle_landscape_left;
case UIDeviceOrientationLandscapeRight:
return (M_PI/2.0f);
return to_angle_landscape_right;
default:
return 0.0f;
}
Expand Down Expand Up @@ -76,15 +82,15 @@ - (CGFloat) orientationAngleRelativeToOrientation:(UIDeviceOrientation) someOrie
CGFloat dOrientation = 0.0f;
switch (someOrientation)
{
case UIDeviceOrientationPortraitUpsideDown: {dOrientation = M_PI; break;}
case UIDeviceOrientationLandscapeLeft: {dOrientation = -(M_PI/2.0f); break;}
case UIDeviceOrientationLandscapeRight: {dOrientation = (M_PI/2.0f); break;}
case UIDeviceOrientationPortraitUpsideDown: {dOrientation = to_angle_upside_down; break;}
case UIDeviceOrientationLandscapeLeft: {dOrientation = to_angle_landscape_left; break;}
case UIDeviceOrientationLandscapeRight: {dOrientation = to_angle_landscape_right; break;}
default: break;
}

CGFloat adjustedAngle = fmod(self.orientationAngle - dOrientation, 2.0f * M_PI);
CGFloat adjustedAngle = fmodf(self.orientationAngle - dOrientation, from_angle );
if (adjustedAngle > (M_PI + 0.01f))
adjustedAngle = (adjustedAngle - 2.0f * M_PI);
adjustedAngle = ( adjustedAngle - from_angle );
return adjustedAngle;
}

Expand Down
37 changes: 30 additions & 7 deletions UIDevice-Reachability.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ + (NSString *) portFromData:(NSData *) addressData
if (addressData != nil)
{
struct sockaddr_in addrIn = *(struct sockaddr_in *)[addressData bytes];
port = [NSString stringWithFormat: @"%s", ntohs(addrIn.sin_port)];
port = [NSString stringWithFormat: @"%us", ntohs(addrIn.sin_port)];
}

return port;
Expand Down Expand Up @@ -178,15 +178,29 @@ + (NSArray *) localWiFiIPAddresses
- (NSString *) whatismyipdotcom
{
NSError *error;
NSURL *ipURL = [NSURL URLWithString:@"http://www.whatismyip.com/automation/n09230945.asp"];
NSURL *ipURL = [NSURL URLWithString:@"http://automation.whatismyip.com/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];
NSArray *hostComponents = [theHost componentsSeparatedByString:@":"];
NSString *hostName;
NSString *port;
if ( [ hostComponents count ] > 0 )
{
hostName = [ hostComponents objectAtIndex:0 ];
if ( [ hostComponents count ] > 1 )
{
port = [ hostComponents objectAtIndex:1 ];
}
} else
{
hostName = theHost;
}

NSString *addressString = [self getIPAddressForHost:hostName];
if (!addressString)
{
printf("Error recovering IP address from host name\n");
Expand Down Expand Up @@ -314,7 +328,12 @@ - (void) shutdownWWAN
static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkConnectionFlags flags, void* info)
{
@autoreleasepool {
id watcher = (__bridge id) info;
id watcher;
#if __has_feature(objc_arc)
watcher = (__bridge id) info;
#else
watcher = (id) info;
#endif
if ([watcher respondsToSelector:@selector(reachabilityChanged)])
[watcher performSelector:@selector(reachabilityChanged)];
}
Expand All @@ -330,8 +349,12 @@ - (BOOL) scheduleReachabilityWatcher: (id) watcher

[self pingReachabilityInternal];

SCNetworkReachabilityContext context = {0, (__bridge void *)watcher, NULL, NULL, NULL};
if(SCNetworkReachabilitySetCallback(reachability, ReachabilityCallback, &context))
#if __has_feature(objc_arc)
SCNetworkReachabilityContext context = {0, (__bridge void *)watcher, NULL, NULL, NULL};
#else
SCNetworkReachabilityContext context = {0, watcher, NULL, NULL, NULL};
#endif
if(SCNetworkReachabilitySetCallback(reachability, ReachabilityCallback, &context))
{
if(!SCNetworkReachabilityScheduleWithRunLoop(reachability, CFRunLoopGetCurrent(), kCFRunLoopCommonModes))
{
Expand Down