私は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]];
}
}