Launch Apple Mail App from within my own App?

2020-01-26 05:17发布

What I already found is

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto:"]];

But I just want to open the Mail app not only a composer view. Just the mail app in its normal or last state.

Any ideas?

标签: ios email
15条回答
【Aperson】
2楼-- · 2020-01-26 05:38

on swift 2.3: open mailbox

UIApplication.sharedApplication().openURL(NSURL(string: "message:")!)
查看更多
The star\"
3楼-- · 2020-01-26 05:40

You can launch any app on iOS if you know its URL scheme. Don't know that the Mail app scheme is public, but you can be sneaky and try this:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"message:message-id"]];

Props to Farhad Noorzay for clueing me into this. It's some bit of reverse engineering the Mail app API. More info here: https://medium.com/@vijayssundaram/how-to-deep-link-to-ios-7-mail-6c212bc79bd9

查看更多
等我变得足够好
4楼-- · 2020-01-26 05:40

It will open Default Mail App with composer view:

NSURL* mailURL = [NSURL URLWithString:@"mailto://"];
if ([[UIApplication sharedApplication] canOpenURL:mailURL]) {
    [[UIApplication sharedApplication] openURL:mailURL];
}

It will open Default Mail App:

NSURL* mailURL = [NSURL URLWithString:@"message://"];
if ([[UIApplication sharedApplication] canOpenURL:mailURL]) {
    [[UIApplication sharedApplication] openURL:mailURL];
}
查看更多
来,给爷笑一个
5楼-- · 2020-01-26 05:41

You might want to use a scripting bridge. I used this method in my App to directly give the user the option to send e-mail notifications using the built in Mail.app. I also constructed an option to do this directly over SMTP as an alternate.

But since you want to use Mail.app method, you can find more information about how to do that solution by following this:

https://github.com/HelmutJ/CocoaSampleCode/tree/master/SBSendEmail

Good Luck!

查看更多
We Are One
6楼-- · 2020-01-26 05:47

Since the only way to launch other applications is by using their URL schemes, the only way to open mail is by using the mailto: scheme. Which, unfortunately for your case, will always open the compose view.

查看更多
地球回转人心会变
7楼-- · 2020-01-26 05:48

Run your app on a real device and call

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"your@email.com"]];

Note, that this line takes no effect on simulator.

查看更多
登录 后发表回答