ios 如何从我自己的应用程序打开 iphone 邮件应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10513226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 18:17:48  来源:igfitidea点击:

How to open iphone mail application from my own application?

iphoneobjective-ciosios4

提问by Faheem Rajput

i am working on signup feature. In this feature when the user create account successfully. i am asking him or her to activate his account. i want to open the mail application of iphone if user say yes. now my question is simple how to open mail application from my own application?

我正在研究注册功能。在用户创建帐户成功时使用此功能。我要求他或她激活他的帐户。如果用户说是,我想打开 iphone 的邮件应用程序。现在我的问题很简单,如何从我自己的应用程序打开邮件应用程序?

回答by adali

#define URLEMail @"mailto:[email protected]?subject=title&body=content"

 NSString *url = [URLEMail stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding ]; 
 [[UIApplication sharedApplication]  openURL: [NSURL URLWithString: url]];

回答by Mick MacCallum

Try this out.

试试这个。

-(void)launchMailAppOnDevice
{
    NSString *recipients = @"mailto:[email protected]?subject=subjecthere";
    NSString *body = @"&body=bodyHere";

    NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
    email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}

回答by Alessandro Pirovano

stringByAddingPercentEscapesUsingEncoding and openURL are deprecated.

stringByAddingPercentEscapesUsingEncoding 和 openURL 已弃用。

Now use this:

现在使用这个:

#define URLEMail @"mailto:[email protected]?subject=title&body=content"

NSString * encodedString = [URLEMail stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];

UIApplication *application = [UIApplication sharedApplication];
    [application openURL:[NSURL URLWithString: encodedString] options:@{} completionHandler:nil];

回答by CaptainRedmuff

Ahoy!

哎呀!

The long and short of it is; you can't.

它的长短是; 你不能。

You can create an email compose view for the purpose of sending emails (see MFMailComposeViewController), but you cannot open applications arbitrarily without a purpose.

您可以创建用于发送电子邮件的电子邮件撰写视图(请参阅MFMailComposeViewController),但您不能无故随意打开应用程序。

See this previous post for clarification: Launch an app from within another (iPhone)

请参阅上一篇文章的说明:从另一个 (iPhone) 中启动应用程序

Really though, it's not much effort for the user to close your app and open Mail so I wouldn't worry too much about it anyway.

不过,实际上,用户关闭您的应用程序并打开邮件并不需要太多努力,因此无论如何我都不会太担心。