使用 mailto: URL 发送电子邮件
有人可以帮我解决以下代码吗?对于在 iOS 中发送电子邮件,下面的代码是一个好的代码还是我应该使用 MFMailComposeViewController 而不是这个?:
NSString *url = [NSString stringWithString: @"mailto:[email protected][email protected]&subject=Greetings%20from%20Cupertino!&body=Wish%20you%20were%20here!"];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];NSString *url = [NSString stringWithString: @"mailto:[email protected][email protected]&subject=Greetings%20from%20Cupertino!&body=Wish%20you%20were%20here!"];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
它是发送邮件的可靠代码吗?
Can someone help me with the following code? For sending email in iOS, is the below code a good one or should I use the MFMailComposeViewController than this?:
NSString *url = [NSString stringWithString: @"mailto:[email protected][email protected]&subject=Greetings%20from%20Cupertino!&body=Wish%20you%20were%20here!"];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];NSString *url = [NSString stringWithString: @"mailto:[email protected][email protected]&subject=Greetings%20from%20Cupertino!&body=Wish%20you%20were%20here!"];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
Is it a reliable code for sending mail?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果这是针对 IOS 3.0+ 的,则 MFMailCompseViewController
然后用户完成工作,您会及时收到委托回调:
If this is targeted for IOS 3.0+ then MFMailCompseViewController
Then the user does the work and you get the delegate callback in time:
您确实应该使用 MFMailComposeViewController。它让您留在应用程序中并使您的代码更具可读性。
You really should use MFMailComposeViewController. It keeps you in the app and makes your code more readable.
为了扩展所提供的答案,我想补充一点,
mailto
方法有一个好处,那就是您实际上不必检查用户是否能够发送电子邮件。如果用户无法这样做,它将通过电子邮件向导提示用户,该向导将允许他/她使用默认的苹果邮件应用程序设置电子邮件帐户。对于
MFMailComposeViewController
,您应该始终检查用户是否可以使用canSendMail
方法发送电子邮件,并采取相应措施。我还想指出,
mailto
方法不允许您以直接的方式设置委托,这使得错误处理变得更加棘手。To expand on the answers provided, I'd like to add that there is one benefit to the
mailto
approach, and that is that You don't really have to check if the user is able to send emails. If the user is not able to, it will prompt the user with the email wizard that will allow him/her to set up an email account with the default apple mail app.In case of the
MFMailComposeViewController
, you should always check if the user can send emails with thecanSendMail
method, and act accordingly.I'd like to also note that the
mailto
approach does not allow you to set a delegate in a straight forward way, making the error handling a little more tricky.