Skip to content

Commit

Permalink
Added Device Additions
Browse files Browse the repository at this point in the history
  • Loading branch information
MugunthKumar committed Feb 14, 2011
1 parent b07a3dd commit d3f5c02
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 43 deletions.
16 changes: 8 additions & 8 deletions SSToolkit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/* Begin PBXBuildFile section */
AACBBE4A0F95108600F1A2B1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; };
AB3EDE061308FF32007F0BF9 /* UIDevice+MKAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = AB3EDE041308FF32007F0BF9 /* UIDevice+MKAdditions.h */; };
AB3EDE071308FF32007F0BF9 /* UIDevice+MKAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = AB3EDE051308FF32007F0BF9 /* UIDevice+MKAdditions.m */; };
B207C63712EA209100412418 /* SSWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = B207C63512EA209100412418 /* SSWindow.h */; };
B207C63812EA209100412418 /* SSWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = B207C63612EA209100412418 /* SSWindow.m */; };
B20AC0691267988600687143 /* SSTableViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = B20AC0671267988600687143 /* SSTableViewController.h */; };
Expand Down Expand Up @@ -62,8 +64,6 @@
B24E9E74121DC29A0085F81E /* UIColor+SSToolkitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = B24E9E36121DC29A0085F81E /* UIColor+SSToolkitAdditions.m */; };
B24E9E75121DC29A0085F81E /* UIControl+SSToolkitAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = B24E9E37121DC29A0085F81E /* UIControl+SSToolkitAdditions.h */; };
B24E9E76121DC29A0085F81E /* UIControl+SSToolkitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = B24E9E38121DC29A0085F81E /* UIControl+SSToolkitAdditions.m */; };
B24E9E77121DC29A0085F81E /* UIDevice+SSToolkitAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = B24E9E39121DC29A0085F81E /* UIDevice+SSToolkitAdditions.h */; };
B24E9E78121DC29A0085F81E /* UIDevice+SSToolkitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = B24E9E3A121DC29A0085F81E /* UIDevice+SSToolkitAdditions.m */; };
B24E9E79121DC29A0085F81E /* UIImage+SSToolkitAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = B24E9E3B121DC29A0085F81E /* UIImage+SSToolkitAdditions.h */; };
B24E9E7A121DC29A0085F81E /* UIImage+SSToolkitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = B24E9E3C121DC29A0085F81E /* UIImage+SSToolkitAdditions.m */; };
B24E9E7B121DC29A0085F81E /* UIScrollView+SSToolkitAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = B24E9E3D121DC29A0085F81E /* UIScrollView+SSToolkitAdditions.h */; };
Expand Down Expand Up @@ -108,6 +108,8 @@

/* Begin PBXFileReference section */
AACBBE490F95108600F1A2B1 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
AB3EDE041308FF32007F0BF9 /* UIDevice+MKAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice+MKAdditions.h"; sourceTree = "<group>"; };
AB3EDE051308FF32007F0BF9 /* UIDevice+MKAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice+MKAdditions.m"; sourceTree = "<group>"; };
B207C63512EA209100412418 /* SSWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSWindow.h; sourceTree = "<group>"; };
B207C63612EA209100412418 /* SSWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSWindow.m; sourceTree = "<group>"; };
B20AC0671267988600687143 /* SSTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSTableViewController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -163,8 +165,6 @@
B24E9E36121DC29A0085F81E /* UIColor+SSToolkitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIColor+SSToolkitAdditions.m"; sourceTree = "<group>"; };
B24E9E37121DC29A0085F81E /* UIControl+SSToolkitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIControl+SSToolkitAdditions.h"; sourceTree = "<group>"; };
B24E9E38121DC29A0085F81E /* UIControl+SSToolkitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIControl+SSToolkitAdditions.m"; sourceTree = "<group>"; };
B24E9E39121DC29A0085F81E /* UIDevice+SSToolkitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIDevice+SSToolkitAdditions.h"; sourceTree = "<group>"; };
B24E9E3A121DC29A0085F81E /* UIDevice+SSToolkitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIDevice+SSToolkitAdditions.m"; sourceTree = "<group>"; };
B24E9E3B121DC29A0085F81E /* UIImage+SSToolkitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+SSToolkitAdditions.h"; sourceTree = "<group>"; };
B24E9E3C121DC29A0085F81E /* UIImage+SSToolkitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+SSToolkitAdditions.m"; sourceTree = "<group>"; };
B24E9E3D121DC29A0085F81E /* UIScrollView+SSToolkitAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIScrollView+SSToolkitAdditions.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -315,14 +315,14 @@
B2601A72122307A2005506D5 /* UIKit */ = {
isa = PBXGroup;
children = (
AB3EDE041308FF32007F0BF9 /* UIDevice+MKAdditions.h */,
AB3EDE051308FF32007F0BF9 /* UIDevice+MKAdditions.m */,
B2AE1132126F963300534CF2 /* UIApplication+SSToolkitAdditions.h */,
B2AE1133126F963300534CF2 /* UIApplication+SSToolkitAdditions.m */,
B24E9E35121DC29A0085F81E /* UIColor+SSToolkitAdditions.h */,
B24E9E36121DC29A0085F81E /* UIColor+SSToolkitAdditions.m */,
B24E9E37121DC29A0085F81E /* UIControl+SSToolkitAdditions.h */,
B24E9E38121DC29A0085F81E /* UIControl+SSToolkitAdditions.m */,
B24E9E39121DC29A0085F81E /* UIDevice+SSToolkitAdditions.h */,
B24E9E3A121DC29A0085F81E /* UIDevice+SSToolkitAdditions.m */,
B24E9E3B121DC29A0085F81E /* UIImage+SSToolkitAdditions.h */,
B24E9E3C121DC29A0085F81E /* UIImage+SSToolkitAdditions.m */,
B279539712FC67E300FFE28D /* UIScreen+SSToolkitAdditions.h */,
Expand Down Expand Up @@ -472,7 +472,6 @@
B24E9E71121DC29A0085F81E /* SSWebView.h in Headers */,
B24E9E73121DC29A0085F81E /* UIColor+SSToolkitAdditions.h in Headers */,
B24E9E75121DC29A0085F81E /* UIControl+SSToolkitAdditions.h in Headers */,
B24E9E77121DC29A0085F81E /* UIDevice+SSToolkitAdditions.h in Headers */,
B24E9E79121DC29A0085F81E /* UIImage+SSToolkitAdditions.h in Headers */,
B24E9E7B121DC29A0085F81E /* UIScrollView+SSToolkitAdditions.h in Headers */,
B24E9E7D121DC29A0085F81E /* UIView+SSToolkitAdditions.h in Headers */,
Expand All @@ -496,6 +495,7 @@
B2E241541301C71400F7DC3B /* SSAddressBarTextField.h in Headers */,
B2E241561301C71400F7DC3B /* SSAddressBarTextFieldBackgroundView.h in Headers */,
B2E241581301C71400F7DC3B /* SSAddressBarTextFieldBackgroundViewInnerView.h in Headers */,
AB3EDE061308FF32007F0BF9 /* UIDevice+MKAdditions.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -572,7 +572,6 @@
B24E9E72121DC29A0085F81E /* SSWebView.m in Sources */,
B24E9E74121DC29A0085F81E /* UIColor+SSToolkitAdditions.m in Sources */,
B24E9E76121DC29A0085F81E /* UIControl+SSToolkitAdditions.m in Sources */,
B24E9E78121DC29A0085F81E /* UIDevice+SSToolkitAdditions.m in Sources */,
B24E9E7A121DC29A0085F81E /* UIImage+SSToolkitAdditions.m in Sources */,
B24E9E7C121DC29A0085F81E /* UIScrollView+SSToolkitAdditions.m in Sources */,
B24E9E7E121DC29A0085F81E /* UIView+SSToolkitAdditions.m in Sources */,
Expand All @@ -597,6 +596,7 @@
B2E241551301C71400F7DC3B /* SSAddressBarTextField.m in Sources */,
B2E241571301C71400F7DC3B /* SSAddressBarTextFieldBackgroundView.m in Sources */,
B2E241591301C71400F7DC3B /* SSAddressBarTextFieldBackgroundViewInnerView.m in Sources */,
AB3EDE071308FF32007F0BF9 /* UIDevice+MKAdditions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion SSToolkit/UIColor+SSToolkitAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
@interface UIColor (SSToolkitAdditions)

- (CGFloat)alpha;

- (UIColor) colorFromHex:(int) hexColor; // Mugunth Kumar
@end
13 changes: 13 additions & 0 deletions SSToolkit/UIColor+SSToolkitAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,17 @@ - (CGFloat)alpha {
return CGColorGetAlpha(self.CGColor);
}

- (UIColor) colorFromHex:(int) hexColor
{

float redComponent = (float)((hexColor & 0xFF0000) >> 16))/255.0;
float greenComponent = (float)((hexColor & 0x00FF00) >> 8))/255.0;
float blueComponent = (float)(hexColor & 0x0000FF)/255.0;

return [UIColor colorWithRed:redComponent
green:greenComponent
blue:blueComponent
alpha:1.0]
}

@end
51 changes: 51 additions & 0 deletions SSToolkit/UIDevice+MKAdditions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// UIDevice_MKAdditions.h
// DeviceHelper
//
// Created by Mugunth Kumar on 15-Aug-10.
// Copyright 2010 Steinlogic. All rights reserved.
// As a side note on using this code, you might consider giving some credit to me by
// 1) linking my website from your app's website
// 2) or crediting me inside the app's credits page
// 3) or a tweet mentioning @mugunthkumar
// 4) A paypal donation to mugunth.kumar@gmail.com
//
// A note on redistribution
// if you are re-publishing after editing, please retain the above copyright notices

#import <Foundation/Foundation.h>
#import <MessageUI/MessageUI.h>

#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioServices.h>
#import <CoreLocation/CoreLocation.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import <CoreMotion/CoreMotion.h>

@interface UIDevice (MKAdditions) {

}

- (BOOL) isSimulator; // by Sam Soffes
- (BOOL) microphoneAvailable;
- (void) vibrateWithSound;
- (void) vibrateWithoutSound;

- (BOOL) doesPhotoLibraryHavePictures;
- (BOOL) doesCameraRollHavePictures;

- (BOOL) cameraAvailable;
- (BOOL) videoCameraAvailable;
- (BOOL) frontCameraAvailable;
- (BOOL) cameraFlashAvailable;

- (BOOL) canSendEmail;
- (BOOL) canSendSMS;
- (BOOL) canMakePhoneCalls;

- (BOOL) multitaskingCapable;
- (BOOL) retinaDisplayCapable;

- (BOOL) compassAvailable;
- (BOOL) gyroscopeAvailable;
@end
172 changes: 172 additions & 0 deletions SSToolkit/UIDevice+MKAdditions.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
//
// UIDevice_MKAdditions.m
// DeviceHelper
//
// Created by Mugunth Kumar on 15-Aug-10.
// Copyright 2010 Steinlogic. All rights reserved.
// As a side note on using this code, you might consider giving some credit to me by
// 1) linking my website from your app's website
// 2) or crediting me inside the app's credits page
// 3) or a tweet mentioning @mugunthkumar
// 4) A paypal donation to mugunth.kumar@gmail.com
//
// A note on redistribution
// if you are re-publishing after editing, please retain the above copyright notices

#import "UIDevice+MKAdditions.h"

@implementation UIDevice (MKAdditions)

- (BOOL)isSimulator { // by Sam Soffes

static NSString *simulatorModel = @"iPhone Simulator";

return [[self model] isEqual:simulatorModel];
}

- (BOOL) microphoneAvailable
{
AVAudioSession *ptr = [AVAudioSession sharedInstance];
return ptr.inputIsAvailable;
}

- (void) vibrateWithSound
{
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
}

-(void) vibrateWithoutSound
{
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}

- (BOOL) doesPhotoLibraryHavePictures
{
return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary];
}

- (BOOL) doesCameraRollHavePictures
{
return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum];
}

- (BOOL) cameraAvailable
{
return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
}

- (BOOL) videoCameraAvailable
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
NSArray *sourceTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType];
[picker release];

if (![sourceTypes containsObject:(NSString *)kUTTypeMovie ]){

return NO;
}

return YES;
}

- (BOOL) frontCameraAvailable
{
#ifdef __IPHONE_4_0
return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront];
#else
return NO;
#endif

}

- (BOOL) cameraFlashAvailable
{
#ifdef __IPHONE_4_0
return [UIImagePickerController isFlashAvailableForCameraDevice:UIImagePickerControllerCameraDeviceRear];
#else
return NO;
#endif
}

// later when Apple adds a camera flash to the front camera in iPhone 5 or 6 or whatever, this function can be uncommented :)
/*
- (BOOL) isCameraFlashAvailableForFrontCamera
{
#ifdef __IPHONE_5_0 or 6?!?
return [UIImagePickerController isFlashAvailableForCameraDevice:UIImagePickerControllerCameraDeviceFront];
#else
return NO;
#endif
}
*/

- (BOOL) canSendEmail
{
return [MFMailComposeViewController canSendMail];
}

- (BOOL) canSendSMS
{
#ifdef __IPHONE_4_0
return [MFMessageComposeViewController canSendText];
#else
return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"sms://"]];
#endif
}

- (BOOL) canMakePhoneCalls
{
return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel://"]];
}

- (BOOL) multitaskingCapable
{
BOOL backgroundSupported = NO;
if ([self respondsToSelector:@selector(isMultitaskingSupported)])
backgroundSupported = self.multitaskingCapable;

return backgroundSupported;
}

- (BOOL) compassAvailable
{
BOOL compassAvailable = NO;

#ifdef __IPHONE_3_0
compassAvailable = [CLLocationManager headingAvailable];
#else
CLLocationManager *cl = [[CLLocationManager alloc] init];
compassAvailable = cl.headingAvailable;
[cl release];
#endif

return compassAvailable;

}

- (BOOL) gyroscopeAvailable
{
#ifdef __IPHONE_4_0
CMMotionManager *motionManager = [[CMMotionManager alloc] init];
BOOL gyroAvailable = motionManager.gyroAvailable;
[motionManager release];
return gyroAvailable;
#else
return NO;
#endif

}


- (BOOL) retinaDisplayCapable
{
int scale = 1.0;
UIScreen *screen = [UIScreen mainScreen];
if([screen respondsToSelector:@selector(scale)])
scale = screen.scale;

if(scale == 2.0f) return YES;
else return NO;
}

@end
13 changes: 0 additions & 13 deletions SSToolkit/UIDevice+SSToolkitAdditions.h

This file was deleted.

20 changes: 0 additions & 20 deletions SSToolkit/UIDevice+SSToolkitAdditions.m

This file was deleted.

8 changes: 7 additions & 1 deletion SSToolkit/UIViewController+SSToolkitAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ - (void)displayError:(NSError *)error {
return;
}

[self displayErrorString:[error localizedDescription]];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[error localizedFailureReason]
message:[error localizedRecoverySuggestion]
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}


Expand Down

0 comments on commit d3f5c02

Please sign in to comment.