私は連絡先と呼ばれる私のアプリのボタンがあります!私が提供するToとSubjectで満たされたiPhoneのEamilクライアントを開く方法はありますか?
MFMailComposeViewController を使用します。 >クラス。 Appleの MailComposerの例:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Hello from California!"];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"];
[picker setToRecipients:toRecipients];
[self presentModalViewController:picker animated:YES];
[picker release];
MailComposerサンプルでは、外部メールアプリケーションを開く方法も示しています。
NSString *recipients = @"mailto:[email protected]&subject=Hello from California!";
NSString *body = @"&body=It is raining in sunny California!";
NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
もちろんできます。
- (void)emailExport:(NSString *)filePath
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
//Set the subject of email
[picker setSubject:@"My desired subject"];
//Add email addresses
//Notice three sections: "to" "cc" and "bcc"
NSString *valueForEmail = @"[email protected]";
NSString *valueForCCEmail = @"myCcEmail";
if( valueForEmail == nil || [valueForEmail isEqualToString:@""])
{
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Please set an email address before sending a time entry!" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
return;
}
else {
[picker setToRecipients:[NSArray arrayWithObjects:valueForEmail, nil]];
}
if(valueForCCEmail != nil || ![valueForCCEmail isEqualToString:@""])
{
[picker setCcRecipients:[NSArray arrayWithObjects:valueForCCEmail, nil]];
}
//Fill out the email body text
NSString *emailBody = @"My email body text.";
//This is not an HTML formatted email
[picker setMessageBody:emailBody isHTML:NO];
//Show email view
[self presentModalViewController:picker animated:YES];
//Release picker
[picker release];
}