Wednesday, October 10, 2012

Send Email with Image Attcahment in iPhone


-(void)sendEmail
{
    
    
    Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
    if (mailClass != nil)
    {
        if ([mailClass canSendMail])
        {
            [self displayComposerSheet];
        }
        else
        {
            UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"Error!!" message:@"Device not configured to send mail." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil ];
            [alert show];
            [alert release];
        }
    }
    
}

-(void)displayComposerSheet
{
    if(EmailViewControllerObj==Nil)
        EmailViewControllerObj = [[EmailViewController alloc] init];
    [_glView addSubview:EmailViewControllerObj.view];
    EmailViewControllerObj.view.backgroundColor=[UIColor clearColor];
    picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
    [picker setSubject:@""];
NSArray *toRecipients = [NSArray arrayWithObject:@"abc@xyz.com"];
    NSArray *ccRecipients = [NSArray arrayWithObjects:@"abc@xyz.com",nil];
[picker setToRecipients:toRecipients];
    [picker setCcRecipients:ccRecipients];
    
    
    NSData *myData = UIImagePNGRepresentation(YOURIMAGE);
    [myData writeToFile:@"emailImage.png" atomically:YES];

    [picker addAttachmentData:myData mimeType:@"image/png" fileName:@"emailImage.png"];
    
    
    // Fill out the email body text
    NSString *emailBody = @"Text on Email Body";
    [picker setMessageBody:emailBody isHTML:NO];
    
    
    [EmailViewControllerObj presentModalViewController:picker animated:YES];
    [picker release];
    
    
    
    
}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"Result: Mail sending canceled");
            break;
        case MFMailComposeResultSaved:
            NSLog( @"Result: Mail saved");
            break;
        case MFMailComposeResultSent:
        {
            // NSLog( @"Result: Mail sent");
            
        }
            break;
        case MFMailComposeResultFailed:
            NSLog( @"Result: Mail sending failed");
            break;
        default:
            NSLog( @"Result: Mail not sent");
            break;
    }
[EmailViewControllerObj dismissModalViewControllerAnimated:YES];
    [EmailViewControllerObj.view removeFromSuperview];
}

Wednesday, October 3, 2012

Add buttons on navigation bar


You need to add UIBarButtonItem instance to a UINavigationItem, not to a UINavigationBar. So you can do this as:
NSArray *buttonArray = [NSArray arrayWithObjects:logoButton, logoButton2, logoButton3, nil];
self.navigationItem.leftBarButtonItems = buttonArray;
If you want your buttons on the right, use rightBarButtonItems.


Tuesday, September 25, 2012

Read data from document directory Folder


   
        NSString * resourcePath = [[NSBundle mainBundle] resourcePath];
        NSString * documentsPath = [resourcePath stringByAppendingPathComponent:@"Folder_Name"];
        NSError * error;
        NSArray *contentarr = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsPath error:&error];

Monday, September 24, 2012

Steps to analyze crash report from apple


  1. Copy the release .app file which was pushed to the appstore, the .dSYM file that was created at the time of release and the crash report receive from APPLE into a FOLDER.
  2. OPEN terminal application and go to the folder created above (using CD command)
  3. atos -arch armv7 -o YOURAPP.app/YOURAPP MEMORY_LOCATION_OF_CRASH. The memory location should be the one at which the app crashed as per the report.
Ex: atos -arch armv7 -o 'app name.app'/'app name' 0x0003b508
This would show you the exact line, method name which resulted in crash.
Ex: [classname functionName:]; -510
Symbolicating IPA
if we use IPA for symbolicating - just rename the extention .ipa with .zip , extract it then we can get a Payload Folder which contain app. In this case we don't need .dSYM file.

Sunday, September 23, 2012

Validate textfield for number input




- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    static NSCharacterSet *charSet = nil;
    if(!charSet) {
        charSet = [[[NSCharacterSet characterSetWithCharactersInString:@"0123456789."] invertedSet] retain];
    }
    NSRange location = [string rangeOfCharacterFromSet:charSet];
    return (location.location == NSNotFound);
}

set image and textcolur to navigation item



self.navigationController.navigationBarHidden = NO;
    
    UIImage *image = [UIImage imageNamed: @"nav_bar.png"];
    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
    
    
    UILabel *label = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
    label.backgroundColor = [UIColor clearColor];
    label.font = [UIFont boldSystemFontOfSize:16.0];
    label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.0];
    label.textAlignment = UITextAlignmentCenter;
    label.textColor = [UIColor blackColor]; // change this color
    self.navigationItem.titleView = label;
    label.text = NSLocalizedString(@"Services", @"");
    [label sizeToFit];

calculate EMI In Objective - C


- (CGFloat)calculateEmi{
    CGFloat loanAmt =[[loanAmountTxt text]floatValue];
    CGFloat tenure =[[loanTenureTxt text]floatValue];
    CGFloat InterestRateReducing = [[IntRateTxt text]floatValue];
    CGFloat r = InterestRateReducing/12/100;
    
    CGFloat emi = (loanAmt * r)*(pow((1+r), tenure)/((pow((1+r), tenure)-1)));
    NSLog(@"emi value...%f",emi);

    return emi;
}