Thursday, November 22, 2012

Send Email with Attachment in iphone

Send Email with Attachment in iphone

1) In Xcode 4 goto the build phases tab for your target. Make sure you see MessageUI.framework. If it's not there click + to add a new framework.

2)In your interface file


#import <MessageUI/MFMailComposeViewController.h>


@interface YourViewController : UIViewController <MFMailComposeViewControllerDelegate> 


3)Add this Method


-(void)displayComposerSheet
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;
    [picker setSubject:@"Check My Image!"];

    // Set up recipients
    // NSArray *toRecipients = [NSArray arrayWithObject:@"first@example.com"];
    // NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil];
    // NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"];

    // [picker setToRecipients:toRecipients];
    // [picker setCcRecipients:ccRecipients];  
    // [picker setBccRecipients:bccRecipients];

    // Attach an image to the email
    UIImage *myImage = YourImage;
    NSData *myData = UIImagePNGRepresentation(
myImage);
    [picker addAttachmentData:myData mimeType:@"image/png" fileName:@"
myImage.png"];

    // Fill out the email body text
    NSString *emailBody = @"My Pic";
    [picker setMessageBody:emailBody isHTML:NO];
    [self presentModalViewController:picker animated:YES];

    [picker release];
}


4) Implement the delegate method

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{  
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"Result: canceled");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Result: saved");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Result: sent");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Result: failed");
            break;
        default:
            NSLog(@"Result: not sent");
            break;
    }
    [self dismissModalViewControllerAnimated:YES];
}




Sunday, November 18, 2012

Recieve SMS and show it in Activity as DialogBox

Recieve SMS and show it in Activity as DialogBox


Source Code

Thursday, November 15, 2012

Take SnapShot and save in gallery in iphone

Take SnapShot and Save in gallery in iphone

canvasView is UIView. if you want to take snapshot of whole screen use self.view.

    UIGraphicsBeginImageContext(canvasView.frame.size);
    [canvasView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

Wednesday, November 14, 2012

Drag UIImageVIew ( touch Event ) in iphone


Drag UIImageVIew ( touch Event ) in iphone

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
blockView.center = location;   // blockView = UIimageView which you want to drag
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[self touchesBegan:touches withEvent:event];
}

Thursday, November 8, 2012

Custom Color in Iphone and Core Plot

Custom Color in Iphone and Core Plot



Add Custom Color in Iphone

[UIColor colorWithRed:0.47 green:0.77 blue:0.37 alpha:1.0



Add Custom Color in Core-Plot

[CPTColor colorWithComponentRed:0.47 green:0.77 blue:0.37 alpha:1.0];

Thursday, November 1, 2012

Merge two NSDictionary in one NSDictionary ( if keyvalues are same )

Merge two NSDictionary in one NSDictionary ( if keyvalues are same )


NSMutableDictionary *combined = [your_nsdictionary mutableCopy];
    for(NSString *key in [combined allKeys])
    {
        NSString *breakfastDate = [your_nsdictionary valueForKey:key];
        NSString *dinnerDate = [your_nsdictionarytwo objectForKey:key];
        if(dinnerDate){
            [combined setObject:[NSString stringWithFormat:@"%@,%@",breakfastDate, dinnerDate] forKey:key];
            } else {
                [combined setObject:[NSString stringWithFormat:@"%@,0",breakfastDate] forKey:key];
                }
    }
    NSLog(@"Combine %@",combined);

Remove Duplicate Values from NSMutableArray iPhone

Remove Duplicate Values from NSMutableArray iPhone

NSArray *copy = [mutableArray copy];
NSInteger index = [copy count] - 1;
for (id object in [copy reverseObjectEnumerator]) {
    if ([mutableArray indexOfObject:object inRange:NSMakeRange(0, index)] != NSNotFound) {
        [mutableArray removeObjectAtIndex:index];
    }
    index--;
}
[copy release];