Ank*_*hah 20 uiapplication ios
我正在尝试从我的应用发送电子邮件.但我想要的是如果用户在他/她的手机上使用Gmail应用程序,则应使用它发送邮件.如果Gmail应用不可用,则应将用户重定向到邮箱.
那么我怎么知道用户是否包含Gmail应用程序以及如何将用户重定向到该应用程序.
gha*_*shi 29
正如这里所解释的,如果您使用的是iOS9 +,请不要忘记添加googlegmail到LSApplicationQueriesSchemes您的info.plist
然后,你可以做同样的接受答案(下面是我的swift 2.3版本):
let googleUrlString = "googlegmail:///co?subject=Hello&body=Hi"
if let googleUrl = NSURL(string: googleUrlString) {
// show alert to choose app
if UIApplication.sharedApplication().canOpenURL(googleUrl) {
if #available(iOS 10.0, *) {
UIApplication.sharedApplication().openURL(googleUrl, options: [:], completionHandler: nil)
} else {
UIApplication.sharedApplication().openURL(googleUrl)
}
}
}
Run Code Online (Sandbox Code Playgroud)
Grz*_*ski 22
您需要使用自定义URL方案.对于gmail应用程序:
googlegmail://
Run Code Online (Sandbox Code Playgroud)
如果要在那里撰写邮件,可以向此URL添加更多参数:
co?subject=Example&body=ExampleBody
Run Code Online (Sandbox Code Playgroud)
您可以使用此代码确定是否安装了任何类型的应用程序(只需将customURL替换为其他应用程序):
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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9123 次 |
| 最近记录: |