gpt4 book ai didi

objective-c - objective-c : Send email without leaving app

转载 作者:IT老高 更新时间:2023-10-28 11:44:44 25 4
gpt4 key购买 nike

如何在不离开应用的情况下在应用内发送电子邮件。

这行得通:

-(void) sendEmailTo:(NSString *)to withSubject:(NSString *)subject withBody:(NSString *)body {
NSString *mailString = [NSString stringWithFormat:@"mailto:?to=%@&subject=%@&body=%@",
[to stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[subject stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[body stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailString]];
}

但转到邮件应用程序发送。有没有办法在不离开应用的情况下做到这一点?

最佳答案

是的。使用 MFMailComposeViewController .

// From within your active view controller
if([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailCont = [[MFMailComposeViewController alloc] init];
mailCont.mailComposeDelegate = self;

[mailCont setSubject:@"yo!"];
[mailCont setToRecipients:[NSArray arrayWithObject:@"joel@stackoverflow.com"]];
[mailCont setMessageBody:@"Don't ever want to give you up" isHTML:NO];
[self presentViewController:mailCont animated:YES completion:nil];

}


// Then implement the delegate method
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self dismissViewControllerAnimated:YES completion:nil];
}

关于objective-c - objective-c : Send email without leaving app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4862523/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com