Showing posts with label Objective-C. Show all posts
Showing posts with label Objective-C. Show all posts

iOS SDK - GET UDID from different Device System Version

#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
- (NSString*)deviceUDID {
    NSString *udidString;
   
    if (SYSTEM_VERSION_LESS_THAN(@"6.0")) {
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        udidString = [defaults objectForKey:@"udidKey"];
        if (!udidString) {
            CFUUIDRef identifierObject = CFUUIDCreate(kCFAllocatorDefault);
            // Convert the CFUUID to a string
            udidString = (NSString *)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, identifierObject));
            [defaults setObject:udidString forKey:@"udidKey"];
            [defaults synchronize];
            CFRelease((CFTypeRef) identifierObject);
        }
       
    } else {
        udidString = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    }
    return udidString;
}

iOS SDK Url encode for special characters

//!*'();:@&=+$,/?%#[]
- (NSString *)encodeWith:(NSString *)string
{
    return CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef)string, NULL, CFSTR("!*'();:@&=+$,/?%#[]"), kCFStringEncodingUTF8));
}

iOS SDK Custom NSLog

//  Modify to Prefix.pch
//  Prefix header
//
//  The contents of this file are implicitly included at the beginning of every source file.
//

#import <Availability.h>

#ifndef __IPHONE_3_0
#warning "This project uses features only available in iOS SDK 3.0 and later."
#endif

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
#endif

/************* Custom Log *************/
#ifndef CULog

#ifdef DEBUG
#   define CULog(fmt, ...) {NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);}

#else

#   define CULog(fmt, ...) {}

#endif

#endif

iOS SDK Fix Custom TextField Placehold issues

#import "CustomTextField.h"

#define TEXTFIELD_PADDING 10.0

@implementation CustomTextField

//placehold
- (CGRect)textRectForBounds:(CGRect)bounds
{
    return CGRectMake(bounds.origin.x + TEXTFIELD_PADDING, bounds.origin.y + TEXTFIELD_PADDING, bounds.size.width - TEXTFIELD_PADDING*2, bounds.size.height - TEXTFIELD_PADDING*2);
}

// text position
- (CGRect)editingRectForBounds:(CGRect)bounds
{
    return [self textRectForBounds:bounds];
}

- (void)drawPlaceholderInRect:(CGRect)rect
{
    [[UIColor blueColor] setFill];
    //Fixed for iOS 5 and iOS 7 display issue
    CGRect placeholderRect = CGRectMake(rect.origin.x, (rect.size.height- self.font.pointSize)/2, rect.size.width, self.font.pointSize);
    [[self placeholder] drawInRect:placeholderRect withFont:self.font lineBreakMode:NSLineBreakByWordWrapping alignment:self.textAlignment];
}

@end

Fix UITableView background issue on iOS 7

#pragma mark Table View Delegate methods
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [cell setBackgroundColor:[UIColor clearColor]];
}