Skip to content

Instantly share code, notes, and snippets.

View sag333ar's full-sized avatar

sagar kothari sag333ar

View GitHub Profile
@sag333ar
sag333ar / getUDID.m
Last active December 28, 2015 09:49
Get the UDID of the current iOS device.
- (NSString*)UDID {
NSString *uuidString = nil;
// get os version
NSUInteger currentOSVersion = [[[[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."] objectAtIndex:0] integerValue];
if(currentOSVersion <= 5) {
if([[NSUserDefaults standardUserDefaults] valueForKey:@"udid"]) {
uuidString = [[NSUserDefaults standardDefaults] valueForKey:@"udid"];
} else {
CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault);
@sag333ar
sag333ar / detectDeviceType.m
Last active December 28, 2015 09:49
Detect device type of iPhone
#define IS_HEIGHT_GTE_568 [[UIScreen mainScreen ] bounds].size.height >= 568.0f
typedef NS_ENUM(NSInteger, DeviceType) {
DeviceType_iPhone3Gs,
DeviceType_iPhone4_4s,
DeviceType_iPhone5,
};
- (DeviceType)getTypeOfDevice {
if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] &&
@sag333ar
sag333ar / SessionDelegate.m
Last active December 28, 2015 09:59
NSURLSession, NSURLSessionConfiguration, NSURLSessionDelegate, NSURLSessionDataTask, AFNetworking, AFHTTPRequestOperation, Core-Class
#define IS_IOS_7 ([[[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."][0] intValue] >= 7)
#define API_RQST_TIME_OUT 30
// part of header file --------------------------------------------------------
#import <Foundation/Foundation.h>
@protocol API_Handler <NSObject>
@required
- (void)didSuccess:(NSData*)data;
- (void)didFail:(NSError*)error;
@end
@sag333ar
sag333ar / applyColorToImage.m
Last active December 28, 2015 09:59
Apply color to black-masked-image
// pass color & supply masked (masked with black-color) image
+ (UIImage *)applyColor:(UIColor *)color toImage:(UIImage*)toImage{
// create context
UIGraphicsBeginImageContextWithOptions(toImage.size, NO, toImage.scale);
// get context reference
CGContextRef context = UIGraphicsGetCurrentContext();
// Change the origin of the user coordinate system in a context.
CGContextTranslateCTM(context, 0, toImage.size.height);
@sag333ar
sag333ar / ALERT_WITH_TAG.m
Last active December 28, 2015 09:59
Show Alertview with one-line of code & also detect alertview with tag. Examples are as follows ALERT_WITH_TAG(100, @"Message", @"send this request", nil, self, @"Yes", @"No",nil); ALERT_WITH_TAG(100, @"Message", @"Data deleted", @"Okay", self, nil);
void ALERT_WITH_TAG(NSUInteger tag,NSString *title, NSString *message,NSString *canceBtnTitle,id delegate,NSString *otherButtonTitles, ... )
{
UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:title
message:message
delegate:delegate
cancelButtonTitle:canceBtnTitle
otherButtonTitles:nil
];
va_list args;
@sag333ar
sag333ar / EnableDebugConsole.c
Last active December 28, 2015 09:59
Enable console logs only for Debug mode, while sending release disable Debug_mode to turn off console logs.
#define DEBUG_MODE
#ifdef DEBUG_MODE
#define STLog(x,...) NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(x), ##__VA_ARGS__])
#else
#define STLog
#endif
@sag333ar
sag333ar / generate1xAndAssets.sh
Last active December 28, 2015 09:59
Put all 2x images in proper folder-structure. Open terminal & cd to parent-directory of images folder. Run following script to generate XCAssets. View article - http://sugartin.info/2013/10/18/shell-script-for-genrating-xcassets-for-projects/
#!/bin/bash
createImagesets() {
for d in *; do
if [ -d $d ] ; then
(cd $d; createImagesets)
fi
if [ -f $d ] ; then
a=${d%@2x.*};
dirname=$a".imageset";
@sag333ar
sag333ar / takeScreenshot.m
Last active December 28, 2015 09:59
Take screen-shot of current-application-window.
// a function to take screen-shot of application's screen
- (UIImage*)takeScreenshot
{
// get the key-window references
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
// manipulate boundries of key-window
CGRect rect = [keyWindow bounds];
// create context using size
@sag333ar
sag333ar / hideDesktopIcons
Last active December 29, 2015 07:29
How to Hide All Desktop Icons in Mac OS X by command line?
--comment
--step-1 - hide icons
defaults write com.apple.finder CreateDesktop -bool false
--step-2 - kill finder & relaunch
killall Finder
@sag333ar
sag333ar / showDesktopIcons.APPLESCRIPT
Last active December 29, 2015 07:29
How to SHOW All Desktop Icons in Mac OS X by command line?
--comment
--step-1 - show icons
defaults write com.apple.finder CreateDesktop -bool true
--step-2 - kill finder & relaunch
killall Finder