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

时间:2021-10-10 21:26:17

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的邮件应用。现在我的问题是如何从我自己的应用程序中打开邮件应用程序?

4 个解决方案

#1


47  

#define URLEMail @"mailto:sb@sw.com?subject=title&body=content"

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

#2


12  

Try this out.

试试这个。

-(void)launchMailAppOnDevice
{
    NSString *recipients = @"mailto:myemail@gmail.com?subject=subjecthere";
    NSString *body = @"&body=bodyHere";

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

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

#3


4  

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.

实际上,用户关闭你的应用程序和打开邮件并不是很大的努力,所以我不会太担心它。

#4


2  

stringByAddingPercentEscapesUsingEncoding and openURL are deprecated.

不赞成使用stringbyaddpercent来逃避usingencoding和openURL。

Now use this:

现在用这个:

#define URLEMail @"mailto:sb@sw.com?subject=title&body=content"

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

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

#1


47  

#define URLEMail @"mailto:sb@sw.com?subject=title&body=content"

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

#2


12  

Try this out.

试试这个。

-(void)launchMailAppOnDevice
{
    NSString *recipients = @"mailto:myemail@gmail.com?subject=subjecthere";
    NSString *body = @"&body=bodyHere";

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

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

#3


4  

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.

实际上,用户关闭你的应用程序和打开邮件并不是很大的努力,所以我不会太担心它。

#4


2  

stringByAddingPercentEscapesUsingEncoding and openURL are deprecated.

不赞成使用stringbyaddpercent来逃避usingencoding和openURL。

Now use this:

现在用这个:

#define URLEMail @"mailto:sb@sw.com?subject=title&body=content"

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

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