Learning Swift — Day 222(236)

How to send an email from your app in Swift

studying the video by Sean Allen

Once more the link brings only to the finished project so I will just have to follow the video. I will highlight the interesting bits.

MFMailComposeViewController

Summary

A standard view controller, whose interface lets the user manage, edit, and send email messages.

Declaration

Discussion

Use this view controller to display a standard email interface inside your app. Before presenting the interface, populate the fields with initial values for the subject, email recipients, body text, and attachments of the email. After presenting the interface, the user can edit your initial values before sending the email.

The composition interface does not guarantee the delivery of your email message; it only lets you construct the initial message and present it for user approval. The user may opt to cancel the composition interface, in which case the message and its contents are discarded. If the user opts to send the message, the message is queued in the user’s Mail app outbox. The Mail app is ultimately responsible for sending the message.

Important

You must not modify the view hierarchy presented by this view controller. However, you can customize the appearance of the interface using the UIAppearance protocol.

An alternate way to compose emails is to create and open a URL that uses the mailto scheme. URLs of that type are directed to the built-in Mail app, which uses your URL to configure a message. For information about the structure of mailto URLs, see Apple URL Scheme Reference.

Oh … how much I missed this documentation-delving part of my learning! I love it!

MFMailComposeViewControllerDelegate

Summary

An interface for responding to user interactions with a mail compose view controller.

Declaration

Discussion

The MFMailComposeViewControllerDelegate protocol defines the method that your delegate must implement to manage the mail composition interface. The method of this protocol notifies your delegate object when the user has finished with the interface and is ready to dismiss it.

Your delegate object is responsible for dismissing the picker when the operation completes. You do this by using the dismissModalViewController(animated:) method of the parent view controller, which is responsible for displaying the MFMailComposeViewController object’s interface.

mailComposeController(_:didFinishWith:error:)

Summary

Tells the delegate that the user wants to dismiss the mail composition view.

Declaration

Discussion

Your implementation of this method should dismiss the mail composition view. Implementation of this method is optional, but expected.

If the user has opted to send the email created by this interface, that email should be queued in the user’s Mail program by the time this method is called. If an error occurred while queueing the email message, the error parameter contains an error object that indicates the type of failure that occurred.

Parameters

controller: The view controller object that manages the mail composition view.

result: The result of the user’s action.

error: If an error occurred, this parameter contains an error object with information about the type of failure.

That’s it for this tutorial, on to the next one!

Finding Inner Peace

Following the Swift on Sunday event by Paul Hudson, streamed live on February 3rd 2019.

After watching and coding following the video I can say this was a greatest video. Tomorrow I will go through it line by line and describe what it does and study together with you!

See you tomorrow!


If you like what I’m doing here please consider liking this article and sharing it with some of your peers. If you are feeling like being really awesome, please consider making a small donation to support my studies and my writing (please appreciate that I am not using advertisement on my articles).

If you are interested in my music engraving and my publications don’t forget visit my Facebook page and the pages where I publish my scores (Gumroad, SheetMusicPlus, ScoreExchange and on Apple Books).

You can also support me by buying Paul Hudson’s books from this Affiliate Link.

Anyways, thank you so much for reading!

Till the next one!

Published by Michele Galvagno

Professional Musical Scores Designer and Engraver Graduated Classical Musician (cello) and Teacher Tech Enthusiast and Apprentice iOS / macOS Developer Grafico di Partiture Musicali Professionista Musicista classico diplomato (violoncello) ed insegnante Appassionato di tecnologia ed apprendista Sviluppatore iOS / macOS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: