Open Gmail app from my app
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
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
}
Setup for iOS9+
As explained here, if you're on iOS9+, don't forget to add googlegmail
to LSApplicationQueriesSchemes
on your info.plist
Code to open GMail
Then, you can do the same as the accepted answer (below is my swift 2.3 version):
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)
}
}
}