Friday, September 30, 2011

sending email in obj-c

in.h


import MessageUI/MessageUI.h


delegate  MFMailComposeViewControllerDelegate

 - (void)openInAppEmail:(NSArray*)recipients
           mailSubject:(NSString*)mailSubject
              mailBody:(NSString*)mailBody
                isHtml:(BOOL)isHtml;
 ##########################################
in .m



- (IBAction)mail:(id)sender {
   
   
   
   
        // SMS *   start = [[SMS  alloc] initWithNibName:@"SMS" bundle:[NSBundle mainBundle]];
        //start.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        // start.modalPresentationStyle = UIModalPresentationFormSheet;
        // [self presentModalViewController:start animated:YES];
    email=@"hi@hi.com";
   
    [self openInAppEmail:[NSArray arrayWithObject:email] mailSubject:@"" mailBody:@"" isHtml:YES];
   
   
   
   
   
}


- (void)openInAppEmail:(NSArray*)recipients
           mailSubject:(NSString*)mailSubject
              mailBody:(NSString*)mailBody
                isHtml:(BOOL)isHtml
{
    MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
    controller.mailComposeDelegate = self;
    [controller setToRecipients:recipients];
    [controller setSubject:mailSubject];
    [controller setMessageBody:mailBody isHTML:isHtml];
    [self presentModalViewController:controller animated:YES];
}

- (void)mailComposeController:(MFMailComposeViewController*)controller
          didFinishWithResult:(MFMailComposeResult)result
                        error:(NSError*)error {
    [self dismissModalViewControllerAnimated:YES];
}

Thursday, September 29, 2011

marker in core -Plot

 // OHLC plot
    CPTMutableLineStyle *whiteLineStyle = [CPTMutableLineStyle lineStyle];
    whiteLineStyle.lineColor = [CPTColor whiteColor];
    whiteLineStyle.lineWidth = 1.0f;
    CPTTradingRangePlot *ohlcPlot = [[[CPTTradingRangePlot alloc] initWithFrame:graph.bounds] autorelease];
    ohlcPlot.identifier = @"OHLC";
    ohlcPlot.lineStyle = whiteLineStyle;
    CPTMutableTextStyle *whiteTextStyle = [CPTMutableTextStyle textStyle];
    whiteTextStyle.color = [CPTColor whiteColor];
    whiteTextStyle.fontSize = 48.0;
    ohlcPlot.labelTextStyle = whiteTextStyle;
    ohlcPlot.labelOffset = 5.0;
    ohlcPlot.stickLength = 2.0f;
    ohlcPlot.dataSource = self;
    ohlcPlot.plotStyle = CPTTradingRangePlotStyleOHLC;
    [graph addPlot:ohlcPlot];

Sunday, September 4, 2011

NSSCANNER take out String and numbers

NSString *str = @" hello i am emp 1313 object of string class 123";
NSScanner *scanner = [NSScanner scannerWithString:str];
// set it to skip non-numeric characters
[scanner setCharactersToBeSkipped:
[[NSCharacterSet decimalDigitCharacterSet] 
 invertedSet]];
int i;
while ([scanner scanInt:&i])
{
    NSLog(@"Found int: %d",i);
}
// reset the scanner to skip numeric characters
[scanner setScanLocation:0];
[scanner setCharactersToBeSkipped:
[NSCharacterSet decimalDigitCharacterSet]];
NSString *resultString;
while ([scanner scanUpToCharactersFromSet:
[NSCharacterSet decimalDigitCharacterSet] 
 intoString:&resultString]) {
    NSLog(@"Found string: %@",resultString);
}

Friday, September 2, 2011

save and update data / Read and Write

-(NSString *)readFile:(NSString *)fileName

{
   
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
   
    NSString *documentsDirectory = [paths objectAtIndex:0];
   
    NSString *appFile = [documentsDirectory stringByAppendingPathComponent:fileName];
   
    NSFileManager *fileManager=[NSFileManager defaultManager];
   
    if ([fileManager fileExistsAtPath:appFile])
       
        {
       
        NSError *error= NULL;
       
        id resultData=[NSString stringWithContentsOfFile:appFile encoding:NSUTF8StringEncoding error:&error];
       
        if (error == NULL)
           
            {
           
            return resultData;
           
            }
       
        }
   
    return NULL;
   
}

-(void)writeFile:(NSString *)fileName dataArray:(NSArray *)data

{
   
    NSMutableString *dataString=[NSMutableString stringWithString:@""];
   
    for (int i=0; i<[data count]; i++)
       
        {
       
        if (i == [data count]-1)
           
            {
           
            [(NSMutableString *)dataString appendFormat:@"%@",[data objectAtIndex:i]];
           
            }
       
        else
           
            {
           
            [(NSMutableString *)dataString appendFormat:@"%@\n",[data objectAtIndex:i]];
           
            }
       
        }
   
     [self writeFile:fileName data:dataString];
   
}

-(void)writeFile:(NSString *)fileName data:(id)data

{
   
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
   
    NSString *documentsDirectory = [paths objectAtIndex:0];
   
    NSString *appFile = [documentsDirectory stringByAppendingPathComponent:fileName];
   
    NSError *error=NULL;
   
    NSFileManager *fileManager=[NSFileManager defaultManager];
   
    if ([fileManager fileExistsAtPath:appFile])
       
        {
       
        NSString *fileString=[NSString stringWithContentsOfFile:appFile encoding:NSUTF8StringEncoding error:&error];
       
        data=[data stringByAppendingFormat:@"\n%@",fileString];
       
        [data writeToFile:appFile atomically:YES encoding:NSUTF8StringEncoding error:&error];
       
        }
   
    else
       
        {
       
        [data writeToFile:appFile atomically:YES encoding:NSUTF8StringEncoding error:&error];
       
        }
   
    if (error != NULL)
       
        {
       
            //Check Error Here. if any.
       
        }
   
}



- (IBAction)save:(id)sender {
        //To Write the File.
       
    NSArray *array=[NSArray arrayWithObjects:usernameField.text,passwordField.text, nil];
   
    [self writeFile:@"arra.txt" dataArray:array];
   
   
        //Read the File
   
    NSString *result=[self readFile:@"arra.txt"];
   
    NSArray *outputArray=[result componentsSeparatedByString:@"\n"];
   
    for (int i=0; i<[outputArray count]; i++)
       
        {
       
        NSLog(@"the output=%@ index=%i",[outputArray objectAtIndex:i], i);
       
        }
    }

FEEDJIT Live