Is there a URL handler for Gmail for iOS to compose a message?
Asked Answered
W

1

6

My iOS application includes sending emails as part of its functionality. MFMailComposeViewController allows in-app composition of an email, with the OS using Mail.app in the background to send the message. However, I want to allow users to send an email with the Gmail app for iOS if they so choose.

Since remote view controllers aren't public API, the only way this would be possible is with a URL handler, but I couldn't find one documented online anywhere. Does anyone know of one? If there is one, is it publicly acknowledged by the Gmail team (i.e. do they consider it public API, or are they using it only between Chrome and Gmail and aren't quite ready to take the wrapping paper off)?

Wershba answered 9/10, 2013 at 20:26 Comment(0)
W
14

Silly me, I didn't finish doing my research. Once I opened up the Gmail app's .ipa and found googlegmail as a listed CFBundleURLTypes in the Info.plist, the web turned up a few great resources for this:

  1. Finding the Gmail URL scheme for iOS
  2. Finding the Gmail URL scheme for iOS: Part 2
  3. handleOpenURL: Shared Interapp Communication! has a searchable list of URL handlers.

Long story short, this worked on my iPhone 5 running iOS 7.0 and Gmail for iOS v2.4.1, and opened a compose pane in the Gmail app, even when the app had been explicitly killed:

googlegmail:///co?subject=Hello&body=Hi

I'm still looking for confirmation that this is considered a public API of Gmail. Does anyone have any knowledge about how the Gmail team feels about this?

Wershba answered 9/10, 2013 at 20:26 Comment(11)
you can add touser also by : googlegmail:///co?subject=&body=&to=touserEarshot
Anyway we can add NSData to this scheme? Such that we can add a zip file?Durative
Great question @DurativeTonneau
This almost made my day -- any way I can send an attachment? I'm willing to stream it, save it in the local filesystem, base-64 encode it, whatever worksTorpor
@slezica no clue, I was just digging around as a third part dev. You could disassemble the app via a jailbroken phone and see what their binary doesWershba
With iOS 14’s third party mail app support there may be more docs on how to do that as well. Worth searching for.Wershba
Just looked at the iOS 14 "be a default mail client" docs: basically nothing there. You'll have to disassemble Gmail to figure out what they support, and remember that it's not an API and can change/break/delete all your email at any time if you use it. (Again: I am not on the Gmail team and do not work for Google, just a random iOS developer.)Wershba
Can we use MFMailComposeViewController for opening gmail as default app.Mcclelland
@MayankVerma very doubtful. Apple would have to change APIs.Wershba
@Wershba I think you are right. MFMailComposeViewController can't be use with third party mail services.Mcclelland
@Wershba I'd love to find out how to simply open Gmail in a specific account - not for composing, just opening the mailbox. The "account" parameter works. But, if it requires "co" for compose, what would work simply for viewing the mail list?Betoken

© 2022 - 2024 — McMap. All rights reserved.