Search This Blog

Wednesday, 16 April 2014

iPhone Screenshot Programatically

Below is the method to take screenshot :

- (UIImage *) screenshot
{
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
    
    [self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES];
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

Saturday, 12 April 2014

How to use NSArray in Macro


Here is the solution to define array in macro 

#define Alphabats @[@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z"]

How to access this array in your code :

NSMutableArray *charArray =[NSMutableArray arrayWithArray:Alphabats];

Thursday, 10 April 2014

Check Date Format in iPhone

This method is useful to check which date formate is selected in iphone etither 24 hours or 12 hours

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setLocale:[NSLocale currentLocale]];
[formatter setDateStyle:NSDateFormatterNoStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
NSString *dateString = [formatter stringFromDate:[NSDate date]];
NSRange amRange = [dateString rangeOfString:[formatter AMSymbol]];
NSRange pmRange = [dateString rangeOfString:[formatter PMSymbol]];


Bool HourFormate24 = (amRange.location == NSNotFound && pmRange.location == NSNotFound);

Wednesday, 9 April 2014

UIKeyboard notifications Show & Hide - iPhone SDK

This post will help you integrate keyboard     Notifications to handle the show and hide functionality 

Below are two observer which keep listening keyboard actions . You can keep this two observer in viewdidload
OBSERVERS:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardDidShowNotification object:nil];

   

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardDidHideNotification object:nil];


These are two delegate methods and these will be trigered on keyboard actions.

DELEGATE METHODS:
- (void)keyboardWillShow:(NSNotification*)notification
{
    
}
-(void)keyboardWillHide: (NSNotification*)notification
{
    

}

Tuesday, 8 April 2014

Check Email validation

- (BOOL)validateEmailWithString:(NSString*)email
{
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    return [emailTest evaluateWithObject:email];
    

}

ASIFormDataRequest UPLOAD IMAGE TO THE SERVER

NSMutableDictionary *dic=[NSMutableDictionary dictionary];
        
        [dic setValue:@"Abdul Kareem" forKeyPath:@"user_name"];
        [dic setValue:@"signup" forKeyPath:@"action"];        
        [dic setValue:@"a.kareem.tn@gmail.com" forKeyPath:@"email"];
        [dic setValue:@"abc" forKeyPath:@"password"];
        [dic setValue:@"28" forKeyPath:@"age"];
        [dic setValue:@"Male" forKeyPath:@"gender"];
        [dic setValue:@"80" forKeyPath:@"weight"];
        [dic setValue:@"6" forKeyPath:@"height"];

        NSString *jsonRequest = [dic JSONRepresentation];
        jsonRequest =[jsonRequest stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVIEC_URL,jsonRequest]];

        ASIFormDataRequest *request =[ASIFormDataRequest requestWithURL:url];

        [request setRequestMethod:@"POST"];
        
        [request addRequestHeader:@"User-Agent" value:@"ASIHTTPRequest"];
        [request addRequestHeader:@"Content-Type" value:@"application/json"];
        //[request appendPostData:[jsonRequest  dataUsingEncoding:NSUTF8StringEncoding]];

        if (imageData != nil) { ///for image data
            [request setData:imageData withFileName:@"image.jpg" andContentType:@"image/jpeg" forKey:@"picture"];
        }
       
        [request setDelegate:self];
        [request setShowAccurateProgress:YES];
        
        [request setUsername:"user name if you have on webservice"];
        [request setPassword:"password if you have on webservice"];

        [request startAsynchronous];