Tuesday, May 3, 2011

Email Validation in Objective C

-(BOOL)emailValidation:(NSString *)email {
    BOOL result;
    //checking email validation
    NSString *emailRegEx = @"[A-Z0-9a-z._-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegEx];
    //Valid email address
    if ([emailTest evaluateWithObject:email] == YES){
        NSLog(@"Valid email address");
        result=NO;
    }else{
        NSLog(@"Invalid email address");
        result=YES;
    }
    return result;
}

MD5 in Objective C

Just Import  CommonCrypto/CommonDigest.h and following method returns md5 string.

 #import <CommonCrypto/CommonDigest.h>

- (NSString *)convertIntoMD5:(NSString *) string{
    const char *cStr = [string UTF8String];
    unsigned char digest[16];

    CC_MD5( cStr, strlen(cStr), digest ); // This is the md5 call
   
    NSMutableString *resultString = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
   
    for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
        [resultString appendFormat:@"%02x", digest[i]];
    return  resultString;
}

Thursday, December 23, 2010

Image upload in iphone

Hi
Today I am sharing image browse and image upload tutorial with you..
Call following method for uploading photo you need to pass image data and file name of your image
Other thing you need small php code for uploading..

  







Please make sure your upload directory have read/write permission 
<?php
$uploaddir = 'photos/';
$file = basename($_FILES['userfile']['name']);
$uploadfile = $uploaddir . $file;
         if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)){
         echo "YES";
         }else{
         echo "NO";
         }
?>


- (NSString *)uploadImageFunction:(NSData *)imageData filename:(NSString *)filename{
   
    // Please Specify your php script Url here
     NSString *urlString = @"http://127.0.0.1/iphone/uploader.php";
   
    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
    [request setURL:[NSURL URLWithString:urlString]];
    [request setHTTPMethod:@"POST"];
    NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
     
    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
    [request addValue:contentType forHTTPHeaderField: @"Content-Type"];
   
    NSMutableData *body = [NSMutableData data];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithString:[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@\"\r\n",filename]] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[NSData dataWithData:imageData]];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [request setHTTPBody:body];
   
    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
    return (returnString);
}
you can download zip and php script from here.

Friday, December 17, 2010

Let get start work on blog agian.

Hi friends,

Lets start exploring cocoa. From a couple of months I was departed from my blog..
And the phenomenon of learning was stopped during that period. I have a few things to share
with you.

Wednesday, August 18, 2010

Installing an Application for Testing Over iPhone/iPod



The developer sends you an archive containing two files: the application and a provisioning profile.
You need to install both files into iTunes to be able run the application on your device.
After opening the archive:
  1. Drag the provisioning profile (the file with the .mobileprovision extension) to the iTunes Library group.
  2. Drag the application (the file with the .app extension) to the iTunes Library group.
    The application appears in the Applications list.
  3. Sync your device.
    If the version of iPhone OS on your device is earlier than the test application can run on, you need to update your device with the current release of iPhone OS.

Tuesday, July 27, 2010

UIView With Rounded corners

For Rounded Corners of UIView You Can use the following Code..
But you have to import first....
#import <QuartzCore/QuartzCore.h>

aView.layer.cornerRadius=8.0;
aView.layer.masksToBounds=YES;


cheers
Mandeep

Thursday, June 3, 2010

PDF Reader on iphone and ipad

hey
I found that beginner face problem in my previous post related to the pdf file reading on the iphone / ipad. so I upload a sample application and you can download from here.

PDFReader.zip

please ask feel freely any thing regarding iphone/ipad programming