In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
The purpose of this article is to share with you the content of the example analysis of sending ordinary mail in iOS12 system application. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
IOS12 system uses sending ordinary mail to realize sending.
After you have built the message, you can send it. At this point, you need to use the mailComposeDelegate property, which is used to set the delegate. The syntax is as follows:
Unowned (unsafe) var mailComposeDelegate: MFMailComposeViewControllerDelegate? {get set}
The value of this property is the MFMailComposeViewControllerDelegate protocol type. The protocol includes the mailComposeController (_: didFinishWith:error:) method. This method is called when the user closes the MFMailComposeViewController interface, and its syntax is as follows:
Optional func mailComposeController (_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?)
The parameters are described as follows:
Controller:MFMailComposeViewController object.
Result: the result of the user action. This parameter is the MFMailComposeResult enumeration type, which contains four members. Among them, cancelled means to tap the "Delete draft" button in the cancellation; saved means to tap the "Save draft" button in the cancellation, and the message will be saved in the user's "draft" folder rather than sent; sent means to tap the "send" button, and the message is added to the user's outbox and ready to be sent; failed means that the message has not been saved or queued, which may be an error.
Error:Error object. If an error occurs, this parameter contains an error object that contains information about the type of failure, such as the error field and the error code. Developers can use the MFMailComposeErrorDomain global variable to obtain the error domain. The syntax is as follows:
Let MFMailComposeErrorDomain: String
The error encoding is the MFMailComposeError.Code enumeration type. The enumeration contains 2 members. Where saveFailed indicates that an error occurred while trying to save the message to the drafts folder; sendFailed indicates that an error occurred while trying to queue or send an email.
[example 3-1] send an ordinary email in plain text. The code is as follows:
@ IBAction func sendMail (_ sender: Any) {let composeVC = MFMailComposeViewController () / / instantiate composeVC.mailComposeDelegate = self composeVC.setToRecipients (["address@example.com"]) / / set recipient composeVC.setSubject ("Hello!") / / set the theme composeVC.setMessageBody ("Hello from California!" IsHTML: false) / / set message body self.present (composeVC, animated: true, completion: nil)} func mailComposeController (_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult Error: Error?) {/ / tap the "delete draft" button in cancellation if (result==MFMailComposeResult.cancelled) {print ("message cancellation") / / tap the "Save draft" button in cancellation if (result==MFMailComposeResult.saved) {print ("message saved in drafts folder")} / / message failed if (result==MFMailComposeResult.failed) { Print ("Mail failed")} / / tap the "send" button if (result==MFMailComposeResult.sent) {print ("Mail has been queued in the user's outbox" Ready to send ")} self.dismiss (animated: true, completion: nil)}
Running the program and tapping the button opens the standard email interface provided by MFMailComposeViewController, as shown in figure 3.1. When you tap the Delete draft button of the cancel button, the following is output:
Mail cancellation
When you tap the Save draft button of the cancel button, the following is output:
Messages are saved in the drafts folder
When you tap the send button, the following is output:
The message has been queued in the user's outbox, ready to be sent
When an error occurs in the message, the following is output:
Email failed
Thank you for reading! This is the end of this article on "the example analysis of sending ordinary mail in iOS12 system application". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.