开发者

How to include the content of a decimal variable inside the body of email sent from my iphone app

I have read some posts regarding the MFMailViewController , and wo开发者_StackOverflow社区nder if I can include the content of a decimal variable, which I am using in my Iphone app to store result of some calculation, into the body of the email message which to be sent from my iPhone app.

Here is the code for the calculation I am using inside my app to calculate and display the result into a Text field in the screen:

GPM1 = [NSDecimalNumber decimalNumberWithString: GPMinput1.text];
GPM2 = [NSDecimalNumber decimalNumberWithString: GPMinput2.text];
Result = [GPM1 decimalNumberByDividingBy:GPM2] ;
GPMresult.text = [numberFormatter stringFromNumber:Result];

I want to display the content of the "Result" decimal variable as part of the email body. For example: Your GPM result = "Result".

Any body has an idea ?


Try this

 float GPM1 = [GPMinput1.text floatValue];
 float GPM2 = [GPMinput2.text floatValue]];
 float Result = GPM1/GPM2 ;

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
NSString    *pResult=[NSString  stringWithFormat:@"GPM result  = %.4f",Result];
[controller setMessageBody: pResult isHTML:NO];         
[controller setSubject:@"Subject"];         
[self presentModalViewController:controller animated:YES];      
[controller release]


You have to use the MFMailComposeViewController on iOS 3.0 and later and implement the MFMailComposeViewControllerDelegate protocol:

MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"My Subject"];
[controller setMessageBody:@"Hello there." isHTML:NO]; 
if(controller) {
  [self presentModalViewController:controller animated:YES];
}
[controller release];

When The user sent the mail, you get called back with the following method:

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
  if (result == MFMailComposeResultSent) {
    NSLog(@"It has been sent.");
  }
  [self dismissModalViewControllerAnimated:YES];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜