Does changing the default email app affect MFMailComposeViewController usage? - ios

iOS 14 users can change the default email app. What effect, if any, does this have on MFMailComposeViewController? More specifically, it would be ideal if MFMailComposeViewController "just worked" with whatever the default email client was, for example setting recipients, subject, body, etc.
If that isn't possible, I suppose opening a mailto URL will open whatever the default mail app is. Any way to test this before iOS 14 releases?

iOS 14 and its ability to set a default Mail app did not change anything in regards to MFMailComposeViewController API. It is only capable of displaying Mail's compose sheet, so canSendMail() will still return false when they're not using the Mail app.
To better support users who choose to use a different email app, you could open a mailto URL. This will open the default email app and bring up their compose sheet. If no email app is installed, it will present a system alert asking the user if they want to restore Mail from the App Store (unless running in the Simulator). This API doc explains how you can create the URL, including how to specify a subject, body, and additional recipients.
Note that this will leave your app to open the Mail app or other email app. If you'd like to keep users in your app when they're using Mail, you can continue to use MFMailComposeViewController and fall back to mailto when canSendMail() returns false.
If you would like, you could additionally check if you can open the mailto: URL, and if not, present your own messaging to the user. Note this would require you add mailto to your LSApplicationQueriesSchemes in the Info.plist.
I found this post to be helpful as well.
if MFMailComposeViewController.canSendMail() {
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setToRecipients([email])
mail.setSubject(subject)
present(mail, animated: true, completion: nil)
} else {
if let mailURLString = "mailto:\(email)?subject=\(subject)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
let mailURL = URL(string: mailURLString) {
if UIApplication.shared.canOpenURL(mailURL) { //check not needed, but if desired add mailto to LSApplicationQueriesSchemes in Info.plist
view.window?.windowScene?.open(mailURL, options: nil, completionHandler: nil)
} else {
//maybe they like web apps? 🤷‍♂️
//maybe let them copy the email address to the clipboard or something
}
}
}

Related

How to send an email without opening the mail composer iOS swift?

I am working iOS swift project. I want to send a mail with app itself. When the user clicks the submit button inside the app the mail needs to send in background or pop will be present inside the app without navigating into the mail composer.
if MFMailComposeViewController.canSendMail() {
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setToRecipients([ApplicationModel.sharedInstance.mailAddress])
mail.setSubject("Feedback: \(UserDefaults.Id)")
mail.setMessageBody(sendBpodyMessage(), isHTML: false)
present(mail, animated: true)
} else {
if let emailUrl = createEmailUrl(to: ApplicationModel.sharedInstance.mailAddress,
subject: "Feedback", body: sendBpodyMessage()) {
UIApplication.shared.open(emailUrl)
}
}
I refer so many answers that all were saying there is no way and apple did not have this feature. Is it possible or any other way Folks?
Most of them said to use API send into the own server. I will try it if I don’t have any option related to the above question.
Apple will not allow you to send email from the user's account without displaying a mail composer window to the user (for security reasons.) You will have to implement your own mail sending mechanism from your server if you want this (and still won't be able to send email from the user's account.)
It's not that "Apple does not have this feature." It's that it would be a huge security hole. Apple explicitly blocks third parties from sending emails from the user's account except using a mail composer, and WILL NEVER ALLOW IT.
Think about the potential for abuse if it was allowed. A spammer could release a "trojan horse" app like "flappy bird" for free: A fun, popular game. Millions of people download it. Unbeknownst to them, it starts sending out emails from their accounts, attempting to defraud their friends, or the online community at large

How to open message app but not with send messages view in ios swift

I am opening the app by using this code
UIApplication.shared.open(URL(string: "sms:")!, options: [:], completionHandler: nil)
but I only want to open message app not with send message controller can I do it in ios swift
video attached: https://www.sendspace.com/file/j1yijj
I was able to get the following to do what you're asking:
if let url = URL(string: "messages://"), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}
Full disclosure: I have only tested this on iOS 14, and I have not tried submitting it to the App Store to see if Apple approves it or not.
From what I can tell, this isn't possible since the only way to open native iOS apps is through the URL schemes provided by Apple. As far as I'm aware, "sms" is the only URL scheme that opens the Messages app and it always shows the compose message prompt regardless of whether a phone number is provided or not :(

Is there a way to communicate between messages and my iOS app?

I want to pre fill the verification code in my app's textfield once the user gets an SMS for verifying their number. But, due to security concerns, I don't think that feature is available on iOS. Now, I want to achieve something similar to WhatsApp. When I enter my number in WhatsApp, it sends me a verification code as well as a text that reads,"click here to proceed further". On clicking that link, I am redirected to WhatsApp and my mobile verification process is complete. I want to achieve something similar.
Yes, similar kind of thing can be achievable by using DeepLinking. You need to deep link the page to open particular screen of the app through link.
URLSchems also come in handy for this kind of requirement. For that your app has to whitelist the Scheme identifier it's going to use. So that through that URL scheme you OS will open your app. Send a message with URLScheme.
URLScheme looks like this: MyApp://myapp.com?VerificationCode="65636"
Now you need to get that parameter by using following methods:
func application(app: UIApplication, openURL url: NSURL, options: [String: AnyObject]) -> Bool {
scheme = url.scheme
path = url.path
query = url.query
return true
}
Now send that parameter to your server to verify. That's it.

Can a url link be shared from iOS app via FB Messenger without presenting UIActivityViewController dialog and not needing Facebook SDK?

I am wondering if it is possible to share/send a url link and other media from iOS app via Facebook Messenger app without having to open UIActivityViewController's activity sheet first, which in addition shows a number of other apps which can handle the intended data and does not allow to exclude apps only UIActivityTypes. I would like to present a FB Messenger dialog with pre-filled url link immediately after a button tap, so no dialog with multiple other apps.
Facebook documentation suggests we should use FB SDK in such cases: https://developers.facebook.com/docs/sharing/ios#message. But what is beyond me is that iOS seems to have a "native access" to the Messenger app (and other apps), but there is no good API which could facilitate some UI customisation.
Any idea if there is a way to directly open FB Messenger with pre-filled message without needing to present UIActivityViewController's activity sheet or installing FB SDK?
EDIT: Let me clarify, I would like to share a url link or other media, it is not necessary that the message is pre-filled with text.
You can share a link via messenger in this way
let urlStr = String(format: "fb-messenger://share/?link=%#", sharelink!)
let url = NSURL(string: urlStr)
if UIApplication.shared.canOpenURL(url! as URL) {
UIApplication.shared.open(url! as URL, options: [:]) { (success) in
if success {
print("Messenger accessed successfully")
} else {
print("Error accessing Messenger")
}
}
} else {
// show Install Messenger
}
After lots of searching I can confirm that it is not possible to share text or other media via Facebook Messenger without using their FB SDK as they do not provide URL schemes for that.

Send URL with iMessage App

I would like to send a link with my message to allow the user to open the app store to install the app or use a deep link to link into a certain piece of content in my app, similar to the Apple Music iMessage App. I am currently using:
var messagee:MSMessage = message.url = URL(string: "https://itunes.apple.com/us/app/reaction-timer-game/id572319874?ls=1&mt=8")
template.image = game1Image.image!
template.imageTitle = "Game 1"
template.imageSubtitle = "\(bestScore1[0])"
But when I tap on the the image the iMessage app opens instead of the URL. Is this possible and if so, how can I do this?
Should I be sending the URL with this:
let url = URL(string: "urlData")
self.activeConversation?.insertAttachment(url!, withAlternateFilename: "URL", completionHandler: { (error) in
if error != nil {
print("Error")
} else {
print("Sent")
}
})
Thank you
I don't think that's possible. If you try to open any URL or a URL scheme, it will open your main iOS app if you have one.
In my case I wanted to display a web page so what I did is just use a UIWebView instead of opening Safari directly.
iMessage will already display your app link if the recipient doesn't have it installed. This helps app discoverability but you can't automatically open your app in the App Store.

Resources