automatically post an e-mail subject line when calling a mailer

Asked 2 years ago, Updated 2 years ago, 58 views

Use Swift to call a mailer in the app and
I wanted to automatically enter the destination email address and subject line when I called, so I organized the following programs:

// Generate mailer URL.
let myMailURL:NSURL = NSURL (string: "mailto:[email protected]")!
let myMailSub:NSURL=NSURL(string: "Subject=\(dateString)"!

UIAApplication.sharedApplication().openURL(myMailURL)//mail address
UIAApplication.sharedApplication().openURL(myMailSub)// Subject

There are no errors in simulators or debugs, but
If you check it on the actual machine, it will fall off as soon as you call the mailer.

In my estimation, I thought the subject was wrong, and I thought the subject was strange.

If you don't mind, please let me know.
Thank you for your cooperation.

swift iphone

2022-09-29 22:17

1 Answers

The second URL is not a mailto: scheme, so the mailer will not start.Put them all together

NSURL (string: "mailto:[email protected]?subject=(dateString)")

must be .Also, if dateString contains slashes that are not available in the URL,

varescapedDateString=dateString.stringByAddingPercentEncodingWithAllowedCharacters (.URLHostAllowedCharacterSet())

You should escape with

However, do you mean that you would like to send an email with the address, title, and attachment?openURL: does not support attachments, and UIDocumentInteractionController can only specify that the file should be opened in another app, so MFMailComposeViewController is a good idea.


2022-09-29 22:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.