-1

我正在从 iphone 应用程序发送邮件,我希望用户应该输入邮件字段而不是这个静态接收,并且邮件应该发送给他们。

    - (void)onEmailResult
    {

   if ([[MFMailComposeViewController class] canSendMail]) {
     MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
     picker.mailComposeDelegate = self;

     [picker setSubject:@"Game"];

     // Set up recipients
     NSArray * toRecipients = [NSArray arrayWithObject:@"husain_2000@yahoo.com"];
     [picker setToRecipients:toRecipients];

     // Fill out the email body text
     NSString * emailBody = [NSString stringWithFormat:@"My Score: %d/%d, My Time: %@", numberOfCorrectAnswer, [[[DataManager sharedInstance] questions] count], time];
     [picker setMessageBody:emailBody isHTML:NO];

     [self presentModalViewController:picker animated:YES];
     [picker release];
     }


     else {
     NSString *recipients = @"mailto:husain_2000@yahoo.com?&subject=Game";
     NSString *body = [NSString stringWithFormat:@"&body=My Score: %d/%d, My Time: %@", numberOfCorrectAnswer, [[[DataManager sharedInstance] questions] count], time];

     NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
     email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
    }
   }
4

1 回答 1

0

电子邮件应在 iPhone 中配置。

然后试试这个代码

- (void)onEmailResult
    {

   if ([[MFMailComposeViewController class] canSendMail]) {
     MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
     picker.mailComposeDelegate = self;

     [picker setSubject:@"Game"];

     // Leave recipients as blank


     // Fill out the email body text
     NSString * emailBody = [NSString stringWithFormat:@"My Score: %d/%d, My Time: %@", numberOfCorrectAnswer, [[[DataManager sharedInstance] questions] count], time];
     [picker setMessageBody:emailBody isHTML:NO];

     [self presentModalViewController:picker animated:YES];
     [picker release];
     }



   }
于 2012-07-11T05:12:14.670 回答