从我的应用中打开Gmail应用 [英] Open Gmail app from my app
问题描述
我正在尝试从我的应用发送电子邮件。但我想要的是,如果用户在他/她的手机上使用Gmail应用程序,则应使用它发送邮件。如果Gmail应用程序不可用,则应将用户重定向到邮箱。
I'm trying to send an email from my app. But what I want is if user is having Gmail app on his/her phone, then mail should be sent using it. If Gmail app is unavailable then the user should be redirected to Mailbox.
因此,我如何知道用户是否包含Gmail应用程序以及如何将用户重定向到该应用程序。
So how can I know if user contains Gmail app and how can I redirect user to it.
推荐答案
您需要使用自定义URL方案。对于gmail应用程序:
You need to use custom URL Scheme. For gmail application its:
googlegmail://
如果您想在那里撰写邮件,可以在此网址中添加更多参数:
If you want to compose a message there you can add more parameters to this URL:
co?subject=Example&body=ExampleBody
您可以确定是否有任何类型的应用程序使用此代码安装(显然只为其他应用程序替换customURL):
You can determinate if any kind of application is installed using this code (just replace customURL obviously for an other apps):
NSString *customURL = @"googlegmail://";
if ([[UIApplication sharedApplication]
canOpenURL:[NSURL URLWithString:customURL]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:customURL]];
}
else
{
//not installed, show popup for a user or an error
}
这篇关于从我的应用中打开Gmail应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!