-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 に答える