Tuesday, 13 December 2011

UrlDemo 5

URLDemo5
//For the CiFaceDetection

http://maniacdev.com/2011/11/tutorial-easy-face-detection-with-core-image-in-ios-5/

//For the different example
http://iphonecode.weebly.com/second-page.html

//For the paint app reference
http://itunes.apple.com/us/app/xpaint/id388881325?mt=8
http://itunes.apple.com/us/app/doodle-touch/id398904512?mt=8

//For the Enape and MKStoreManager of the app
http://www.sixtemia.com/journal/2009/08/12/using-store-kit-framework/

//For the different snippet of the iphone
http://borkware.com/quickies/everything-by-date
http://jidh.weebly.com/iphone-development.html

//For the UUID in iphone
  CFUUIDRef cfuuid = CFUUIDCreate (kCFAllocatorDefault);
    NSString *uuid = (NSString *)CFUUIDCreateString (kCFAllocatorDefault, cfuuid);
    CFRelease (cfuuid);
    NSLog(@"%@",uuid);
//For the paint demo
http://code.google.com/p/paintboardiphone/downloads/list
http://pastebin.com/9dKPHt6R

http://www.iphonedevsdk.com/forum/iphone-sdk-development/13064-how-draw-transparent-stroke-anyway-delete-some-part-uiimage-cg.html

//For the checking of network
-(BOOL)checkNetworkConnection{
    NSString *connectingString=[[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://google.com"]];
    if ([connectingString length]==0) {
        NSLog(@"not connected");
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Error" message:@"Network is not available " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];
        netWork=YES;
    }
    else {
        netWork=NO;
    }
   
    [connectingString release];
    return netWork;
}
// For the sorting of array into alphabetic order
wordArray = [[wordArray sortedArrayUsingSelector:
                       @selector(compare:)] mutableCopy];
//For the pdf demos
http://pspdfkit.com/

//For the line drawing and erasing
write it between the touch moved

UITouch *touch = [touches anyObject];   
    CGPoint currentPoint = [touch locationInView:self.colorView];
      //currentPoint.y -= 20;
        if (appDelegate.iphoneIpad==1) {
            drawPencil.frame=CGRectMake(currentPoint.x+5,currentPoint.y-30,drawPencil.frame.size.width,drawPencil.frame.size.height);       
           
        }
        else{
            drawPencil.frame=CGRectMake(currentPoint.x+10,currentPoint.y-80,drawPencil.frame.size.width,drawPencil.frame.size.height);       
           
        }
       
        if (eraseDrawImg==NO) {
                //For Drawing of line....
           
                //drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
                UIGraphicsBeginImageContext(self.colorView.frame.size);
                [drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)];
                CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
                CGContextSetLineWidth(UIGraphicsGetCurrentContext(), eraseSize);
                
                    CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(),color);
               
                CGContextBeginPath(UIGraphicsGetCurrentContext());
                CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
                CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
                CGContextStrokePath(UIGraphicsGetCurrentContext());
                drawImage.image=UIGraphicsGetImageFromCurrentImageContext();
                          
                UIGraphicsEndImageContext();  
                
            } 
            else{
                //For Erasing of Drawn line....

                UIGraphicsBeginImageContext(self.colorView.frame.size);
                [drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)];
                CGContextSetLineCap(UIGraphicsGetCurrentContext(),kCGImageAlphaNone); //kCGImageAlphaPremultipliedLast);
                CGContextSetLineWidth(UIGraphicsGetCurrentContext(), eraseSize);
                CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1, 0, 0, 10);
                CGContextAddArc(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y, eraseSize, 0.0, 2*M_PI, 0);//, 50, 50, 50, 0.0, 2*M_PI, 0);
                CGContextClip(UIGraphicsGetCurrentContext());
                CGContextClearRect(UIGraphicsGetCurrentContext(),self.colorView.frame);

                CGContextBeginPath(UIGraphicsGetCurrentContext());
                CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
                CGContextClearRect(UIGraphicsGetCurrentContext(), CGRectMake(lastPoint.x, lastPoint.y, eraseSize,eraseSize));
                
                CGContextStrokePath(UIGraphicsGetCurrentContext());
                drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
                UIGraphicsEndImageContext();
            }           
           // NSLog(@"%d",imageTag);
         NSLog(@"%@",lineArray);
        lastPoint = currentPoint;
   
        mouseMoved++;
   
    if (mouseMoved == 10) {
        mouseMoved = 0;
        }
    }

//For the Bluring to imageview

-(UIImage*)imageWithBlurAroundPoint:(CGPoint)point {
    CGRect             bnds = CGRectZero;
    UIImage*           copy = nil;
    CGContextRef       ctxt = nil;
    CGImageRef         imag = rgbImg.image.CGImage;
    CGRect             rect = CGRectZero;
    CGAffineTransform  tran = CGAffineTransformIdentity;
    int                indx = 0;
   
    rect.size.width  = CGImageGetWidth(imag);
    rect.size.height = CGImageGetHeight(imag);
   
    bnds = rect;
   
    UIGraphicsBeginImageContext(bnds.size);
    ctxt = UIGraphicsGetCurrentContext();
   
    // Cut out a sample out the image
    CGRect fillRect = CGRectMake(point.x - 10, point.y - 10, 20, 20);
    CGImageRef sampleImageRef = CGImageCreateWithImageInRect(rgbImg.image.CGImage, fillRect);
   
    // Flip the image right side up & draw
    CGContextSaveGState(ctxt);
   
    CGContextScaleCTM(ctxt, 1.0, -1.0);
    CGContextTranslateCTM(ctxt, 0.0, -rect.size.height);
    CGContextConcatCTM(ctxt, tran);
   
    CGContextDrawImage(UIGraphicsGetCurrentContext(), rect, imag);
   
    // Restore the context so that the coordinate system is restored
    CGContextRestoreGState(ctxt);
   
    // Cut out a sample image and redraw it over the source rect
    // several times, shifting the opacity and the positioning slightly
    // to produce a blurred effect
    for (indx = 0; indx < 5; indx++) {
        CGRect myRect = CGRectOffset(fillRect, 0.5 * indx, 0.5 * indx);
        CGContextSetAlpha(ctxt, 0.2 * indx);
        CGContextScaleCTM(ctxt, 1.0, -1.0);
        CGContextDrawImage(ctxt, myRect, sampleImageRef);
    }
   
    copy = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
   
    return copy;

}
//For the soap parsing demo
http://www.icodeblog.com/2008/11/03/iphone-programming-tutorial-intro-to-soap-web-services/

//For the page curl effect from left to right & vice versa
https://github.com/jemmons/PageCurl


 //For the glow of the line
    /*float glowWidth = 10.0;
     float colorValues[] = { 0, 0, 1, 1.0 };
     CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
     CGColorRef glowColor = CGColorCreate( colorSpace, colorValues );
     CGContextSetShadowWithColor( c, CGSizeMake( 0.0, 0.0 ), glowWidth, glowColor );*/

//touch and erase in uiimageview in iphone
http://www.iphonedevsdk.com/forum/iphone-sdk-development/13064-how-draw-transparent-stroke-anyway-delete-some-part-uiimage-cg.html




Friday, 18 November 2011

iphone snippet

//For the Invert of any object in iphone
UIGraphicsBeginImageContext(rgbImg.image.size);
    CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy);
    UIImage * image=rgbImg.image;
    [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
    CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeDifference);
    CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),[UIColor whiteColor].CGColor);
    CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, image.size.width, image.size.height));
    rgbImg.image= UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();


//For the Black & White of the image
UIImage *originalImage = rgbImg.image; // this image we get from UIImagePickerController
    CGColorSpaceRef colorSapce = CGColorSpaceCreateDeviceGray();
    CGContextRef context = CGBitmapContextCreate(nil, originalImage.size.width, originalImage.size.height, 8, originalImage.size.width, colorSapce, kCGImageAlphaNone);
    CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
    CGContextSetShouldAntialias(context, NO);
    CGContextDrawImage(context, CGRectMake(0, 0, originalImage.size.width, originalImage.size.height), [originalImage CGImage]);
    CGImageRef bwImage = CGBitmapContextCreateImage(context);
    CGContextRelease(context);
    CGColorSpaceRelease(colorSapce);
    rgbImg.image = [UIImage imageWithCGImage:bwImage]; // This is result B/W image.
    CGImageRelease(bwImage);


//For the mirrored image orientation
if (mirrorOn==NO) {
       rgbImg.image = [UIImage imageWithCGImage:rgbImg.image.CGImage scale:rgbImg.image.scale orientation:UIImageOrientationUpMirrored];
       mirrorOn=YES;

    }
   else if (mirrorOn==YES) {
       mirrorOn=NO;
       rgbImg.image = [UIImage imageWithCGImage:rgbImg.image.CGImage scale:rgbImg.image.scale orientation:UIImageOrientationUp];

    }


//For the uiimage+extra classes for the brightness and contrast

https://github.com/coryleach/UIImageAdjust

//For the uiimage sepia and more

https://github.com/Nyx0uf/NYXImagesUtilities/tree/master/Categories

//For the paint in iphone

http://www.bogotobogo.com/XcodeSDK-Chapter11.html

//Dropdown in iphone
http://kshitizghimire.com.np/dropdown-in-iphoneipad/

//Lazy loading of tableview in iphone

http://kshitizghimire.com.np/lazy-loading-custom-uitableviewcell/

//TwitPic

http://www.techotopia.com/index.php/An_Example_iPhone_iOS_5_TWTweetComposeViewController_Twitter_Application

//For Image Cropping

- (UIImage*)imageByCropping:(UIImage *)imageToCrop toRect:(CGRect)rect
{
    CGImageRef imageRef = CGImageCreateWithImageInRect([imageToCrop CGImage], rect);
    UIImage *cropped = [UIImage imageWithCGImage:imageRef];
    CGImageRelease(imageRef);   
   
    return cropped;
}


//For imageview animation like crossDissolve

#import <QuartzCore/QuartzCore.h>
...
imageView.image = [UIImage imageNamed:(i % 2) ? @"3.jpg" : @"4.jpg"];

CATransition *transition = [CATransition animation];
transition.duration = 1.0f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;

[imageView.layer addAnimation:transition forKey:nil];

//For memory warning issues
http://akosma.com/2009/01/28/10-iphone-memory-management-tips/

//Cook book Example
http://code.google.com/p/iphone-sdk-programming-book-code-samples/downloads/list

//Send sms from the iphone ipad
- (void)sendSMS
{
    if ([MFMessageComposeViewController canSendText])
    {
        MFMessageComposeViewController *messageView = [[MFMessageComposeViewController alloc] init];
        messageView.messageComposeDelegate = self;
       
         [self presentModalViewController:messageView animated:YES];
        [messageView release];
    }
    else {
        [appDel showAlert:@"Oops" message:@"You can't send message"];
    }
   
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
  //  SMS.hidden = NO;
    switch (result)
    {
        case MessageComposeResultCancelled:
           // SMS.text = @"Result: canceled";
            NSLog(@"Result: canceled");
            break;
        case MessageComposeResultSent:
         //   SMS.text = @"Result: sent";
            NSLog(@"Result: sent");
            break;
        case MessageComposeResultFailed:
          //  SMS.text = @"Result: failed";
            NSLog(@"Result: failed");
            break;
        default:
         //   SMS.text = @"Result: not sent";
            NSLog(@"Result: not sent");
            break;
    }
   
    [self dismissModalViewControllerAnimated:YES];
   
}

//Send mail from the iphone ipad
-(IBAction)sendEmail
{
   
    //disappear=YES;
    if([MFMailComposeViewController canSendMail] == false) {
        UIAlertView *view = [[UIAlertView alloc] initWithTitle:@"Error" message:@"The device cannot currently send email." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [view show];
        [view release];
        return;
    }
    else{
        Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
        if (mailClass != nil)
        {
            // We must always check whether the current device is configured for sending emails
            if ([mailClass canSendMail])
            {
                [self displayComposerSheet];
            }
            else
            {
                [self launchMailAppOnDevice];
            }
        }
        else
        {
            [self launchMailAppOnDevice];
        }
    }
   
}
-(void)displayComposerSheet
{
   
    MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc] init];
    mailView.mailComposeDelegate = self;
    //SharedManager *sm = [SharedManager sharedInstance];
    [mailView setSubject:@"Hello from "];//[sm.text substringToIndex:20]];
   
    [mailView setMessageBody:@"You can know more from this url!" isHTML:YES];
   
    NSData *attachmentData = UIImageJPEGRepresentation(getImg, 1.0);
    UIImage *image=getImg;
    [mailView addAttachmentData:attachmentData mimeType:@"image/png" fileName:[NSString stringWithFormat:@"%@",image]];
     [self presentModalViewController:mailView animated:YES];
    [mailView release];
   
}


#pragma mark -
#pragma mark Workaround

// Launches the Mail application on the device.
-(void)launchMailAppOnDevice
{    
    MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc] init];
    mailView.mailComposeDelegate = self;
    [mailView setSubject:@"Hello from  "];    
    [mailView setMessageBody:@"You can know more from this url!" isHTML:YES];
   
    NSData *attachmentData = UIImageJPEGRepresentation(getImg, 1.0);
    UIImage *image=getImg;
    [mailView addAttachmentData:attachmentData mimeType:@"image/png" fileName:[NSString stringWithFormat:@"%@",image]];
    [self presentModalViewController:mailView animated:YES];
    [mailView release];
   
   
   
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    // Dismiss Mail View
    [self dismissModalViewControllerAnimated:YES];
   
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"Mail send canceled");
            self.navigationController.navigationBar.hidden =YES;
            break;
        case MFMailComposeResultSent:
            [appDel showAlert:@"Mail sent successfully." message:@"Success"];
            NSLog(@"Mail send successfully");
            break;
        case MFMailComposeResultSaved:
            [appDel showAlert:@"Mail saved to drafts successfully." message:@"Mail saved"];
            NSLog(@"Mail Saved");
            break;
        case MFMailComposeResultFailed:
            [appDel showAlert:[NSString stringWithFormat:@"Error:%@.", [error localizedDescription]] message:@"Failed to send mail"];
            NSLog(@"Mail send error : %@",[error localizedDescription]);
            break;
        default:
            break;
    }
}

// For SCListner class
https://github.com/stephencelis/sc_listener
//For mic Detection program
http://mobileorchard.com/tutorial-detecting-when-a-user-blows-into-the-mic/


//For the drawing the rectangle lines on the any object
- (void)drawRect  {
    UIGraphicsBeginImageContext(self.view.frame.size);
   
    CGContextRef currentContext = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(currentContext, 3.0); //or whatever width you want
    CGContextSetRGBStrokeColor(currentContext, 0.0, 0.0, 0.0, 1.0);
   
    CGRect myRect = CGContextGetClipBoundingBox(currentContext);
    //printf("rect = %f,%f,%f,%f\n", myRect.origin.x, myRect.origin.y, myRect.size.width, myRect.size.height);
   
    CGContextStrokeRect(currentContext, myRect);
    UIImage *backgroundImage = (UIImage *)UIGraphicsGetImageFromCurrentImageContext();
    UIImageView *myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [myImageView setImage:backgroundImage];
    [self.view addSubview:myImageView];
    [backgroundImage release];
   
    UIGraphicsEndImageContext();
}

//For the Border of the imageview in iphone

 [imageView.layer setBorderColor: [[UIColor redColor] CGColor]];
    [imageView.layer setBorderWidth: 2.0];

//Different Example for ios
http://projectswithlove.com/projects/

Wednesday, 5 October 2011

//For wifi driver for mac 10.6

http://www.insanelymac.com/forum/index.php?showtopic=218189


http://www.insanelymac.com/forum/index.php?act=Search&CODE=show&searchid=90d2112282c961971f33961e5ff7a55d&search_in=posts&result_type=topics&highlite=%2Blenovo

http://www.insanelymac.com/forum/index.php?showtopic=51725
Usage: unzip, open a Terminal window and type 'sudo ./bcm43xx_enabler.sh'. Reboot 

For Getting particular named images from the project

//For Getting particular named images from the project

NSMutableArray *any=[[NSMutableArray alloc] init];
    NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
    NSArray *dirContents = [[NSFileManager defaultManager] directoryContentsAtPath:bundleRoot];
    for (NSString *tString in dirContents) {
        if ([tString hasPrefix:@"Fire Type1"] && [tString hasSuffix:@".png"]) {
           
            [any addObject:tString];
           
        }
    }
    NSLog(@"%@",any);

Accessing specific folder files in iphone app

Accessing specific folder files
1. add folder with the second radio button
2. it is located at anyname.app/yourfolder


NSString *bundleRoot1 = [[NSBundle mainBundle] resourcePath];
    bundleRoot1=[bundleRoot1 stringByAppendingString:@"/Images"];
    NSArray *dirContents1 = [[NSFileManager defaultManager] directoryContentsAtPath:bundleRoot1];
    NSLog(@"dirContents1 %@",dirContents1);
   
    [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:[dirContents1 objectAtIndex:0]]]];

Tuesday, 4 October 2011

twit Image on twitter with Share kit





 //


#import "TwitImageAppDelegate.h"
@interface TwitterMain : UIViewController<UIActionSheetDelegate> {

   
    TwitImageAppDelegate *appDel;
    IBOutlet UIButton *doneBtn;
    IBOutlet UITextField *userNameTxt;
    IBOutlet UITextField *passTxt;
    IBOutlet UIImageView *imageView;
}
-(IBAction)doneBtnPress;



//////////
#import "TwitterMain.h"
#import "SHKItem.h"
#import "SHKActionSheet.h"
#import "SHKSharer.h"
#import "SHKCustomShareMenu.h"
#import "Global.h"


BOOL checkImg;
@implementation TwitterMain

@synthesize controller,popover;




- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)viewWillAppear:(BOOL)animated
{
    checkImg=NO;
    appDel=(TwitImageAppDelegate *)[[UIApplication sharedApplication]delegate];
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}
-(IBAction)doneBtnPress{
   
    if (checkImg==NO) {
        [Global showAlert:@"! Opps" message:@"First Select the Image To Upload"];
    }
    else{
        appDel.username=userNameTxt.text;
        appDel.password=passTxt.text;
        SHKItem *item = [SHKItem image:imageView.image title:@"Selected Image"];
        //    SHKSharer *sharers;
        SHKActionSheet *as = [[SHKActionSheet alloc] initWithTitle:SHKLocalizedString(@"Share")
                                                          delegate:self
                                                 cancelButtonTitle:nil
                                            destructiveButtonTitle:nil
                                                 otherButtonTitles:nil];
        as.item = [[[SHKItem alloc] init] autorelease];
        as.item.shareType = SHKShareTypeImage;
       
        as.sharers = [NSMutableArray arrayWithCapacity:0];
        id class;
        class = NSClassFromString(@"SHKTwitter");
        [as addButtonWithTitle: [class sharerTitle]];
        [as.sharers addObject:@"SHKTwitter"];
        [NSClassFromString([as.sharers objectAtIndex:0]) performSelector:@selector(shareItem:) withObject:item];
    }
    //SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
     //[actionSheet showFromToolbar:self.navigationController.toolbar];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
   
    [textField resignFirstResponder];   
   
    return YES;
}
-(IBAction)camera{
    //UIImagePickerController *controller;
    if (appDel.iphoneIpad==1) {
       
       
       
#if TARGET_IPHONE_SIMULATOR
       
        [Global showAlert:@"Camera is not available." message:@"Not Successfull"];
       
#elif TARGET_OS_IPHONE   
        if ([UIImagePickerController isSourceTypeAvailable:
             UIImagePickerControllerSourceTypeCamera])
        {
            controller = [[UIImagePickerController alloc] init]; 
            controller.sourceType = UIImagePickerControllerSourceTypeCamera; 
            controller.delegate = self; 
            //picker.allowsEditing = YES; 
            [self presentModalViewController:controller animated:YES];
            [controller release];
        }
        else {
            [Global showAlert:@"Camera is not available." message:@"Not Successfull"];
        }
       
#endif   
    }
    else if(appDel.iphoneIpad==2){
       
       
        controller = [[UIImagePickerController alloc] init];
        self.popover = [[UIPopoverController alloc] initWithContentViewController:controller];
        NSLog(@"The value of the bool is %@\n", (self.popover.popoverVisible ? @"YES" : @"NO"));
        //[self dismissPopoverAnimated:YES];
        if (self.popover.popoverVisible == YES) {
           
            [self.popover dismissPopoverAnimated:YES];
            [Global showAlert:@"FIRST CLOSE THE." message:@"PHOTO GALLARY"];
        }
       
        else {
           
            if ([UIImagePickerController isSourceTypeAvailable:
                 UIImagePickerControllerSourceTypeCamera])
            {
                controller.sourceType=UIImagePickerControllerSourceTypeCamera;
                [controller setDelegate:self];
               
                [self.popover setDelegate:self];
                [self.popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 1200.0,1200.0)
                                              inView:self.view
                            permittedArrowDirections:UIPopoverArrowDirectionAny
                                            animated:YES];
                //[self.popover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
            }
            else {
                [Global showAlert:@"Camera is not available." message:@"Not Successfull"];
            }
           
           
        }
    }
   
}

-(IBAction)addPhoto {

    if (appDel.iphoneIpad==1) {
        controller = [[UIImagePickerController alloc] init];
        //[controller setMediaTypes:[NSArray arrayWithObject:kUTTypeImage]];
        [controller setDelegate:self];
        [self presentModalViewController:controller animated:YES];
       
    }
    else if(appDel.iphoneIpad==2){
        controller = [[UIImagePickerController alloc] init];
        self.popover = [[UIPopoverController alloc] initWithContentViewController:controller];
       
        if ( self.popover.popoverVisible == YES) {
           
            [self.popover dismissPopoverAnimated:YES];
            [Global showAlert:@"FIRST CLOSE THE." message:@"PHOTO GALLARY"];
        }
        else {
           
            controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            [controller setDelegate:self];
            [popover setPopoverContentSize:CGSizeMake(700.0f,300.0f)];
           
            //self.popover= [[UIPopoverController alloc] initWithContentViewController:controller];
            [self.popover setDelegate:self];
           
            [self.popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 800.0, 400.0)
                                          inView:self.view
                        permittedArrowDirections:UIPopoverArrowDirectionAny
                                        animated:YES];   
        }
       
    }
   
}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [[picker parentViewController] dismissModalViewControllerAnimated:YES];
    [picker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    //    savePhotoBtn.enabled=YES;
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    ///heroImgView.image=image;
    checkImg=YES;
   
    imageView.image=image;
   
    if (appDel.iphoneIpad==2) {
        [self.popover dismissPopoverAnimated:YES];
    }
    [self dismissModalViewControllerAnimated:YES];
   
   
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    UIAlertView *alert;
   
    // Unable to save the image 
    if (error){
       
        alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                           message:@"Unable to save image to Photo Album."
                                          delegate:self cancelButtonTitle:@"Ok"
                                 otherButtonTitles:nil];
    }
    else{ // All is well
        alert = [[UIAlertView alloc] initWithTitle:@"Success"
                                           message:@"Image saved to Photo Album."
                                          delegate:self cancelButtonTitle:@"Ok"
                                 otherButtonTitles:nil];
        [alert show];
        [alert release];
       
       
    }
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    // Relinquish ownership any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
   
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
    // For example: self.myOutlet = nil;
}

- (void)dealloc
{
    [super dealloc];
}

@end

Friday, 30 September 2011

Checking white space and Trimming specific character in iphone

#define allTrim( anyobject ) [anyobject
 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet] ]

NSString *stringname = @"   ";
if ( [allTrim( stringname ) length] == 0 ) NSLog(@"Is empty!");