Open Gmail app from my app

后端 未结 4 635
长发绾君心
长发绾君心 2020-12-24 02:30

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 the

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-24 03:05

    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
    }  
    

提交回复
热议问题