PDA

View Full Version : Email Test in a label




cabrown
May 7, 2009, 11:43 PM
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.



jnic
May 8, 2009, 04:09 AM
// 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 Mail.app.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];