Email Test in a label

Discussion in 'iOS Programming' started by cabrown, May 7, 2009.

  1. macrumors regular


    Sep 2, 2008
    Anyone how to go about putting the text from a label into the body of an email? I know how to create an email that can be sent on a button touch but I am not sure how to put the label text in the body of the email. My label is randomly populated from a plist file and the view is populated by
    TestAppDelegate *appDelegate =  
        (TestAppDelegate *)[[UIApplication sharedApplication] delegate];  
    	fileContents = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"plist"];
    	NSDictionary *test = [[NSDictionary alloc] initWithContentsOfFile:fileContents];
    	NSMutableArray *things = [test valueForKey:@"things"];
    		[UIView beginAnimations:nil context:NULL];
    		[UIView setAnimationDuration:1.0];
    		[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:label cache:YES];
    		[UIView commitAnimations];
    	int randomNumber = arc4random() % [things count];
    	things = [things objectAtIndex:randomNumber];
    	[appDelegate setModelData:things];
    I already know how to set up an email I just don't know what to place in for the body text that would set it as the current displaying label.
  2. macrumors 6502a

    Oct 24, 2008
    // Get the content of your label.
    NSString *body = yourLabel.text;
    // Percent escaping.
    NSString *subject = [@"Your Subject" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSString *body = [body stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    // Construct mailto URL.
    NSString *url = [NSString stringWithFormat:@"mailto:?subject=%@&body=%@", subject, body];
    // Open
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

Share This Page