Skip to content
This repository has been archived by the owner on Sep 25, 2021. It is now read-only.

Support opening email links natively #34

Closed
wants to merge 1 commit into from

Conversation

glennfu
Copy link

@glennfu glennfu commented Apr 25, 2016

There's really only 1 way to do native email composition in an iOS app and doing so a much nicer experience to do it than to click on a mailto: link and have it switch you to the Mail app. I don't think there'll ever be a case where someone using turbolinks-ios will prefer it to be the other way.

So here's a PR for taking a mailto: link and converting it to a native email popup. I was inspired reading http://stackoverflow.com/questions/25604552/i-have-real-misunderstanding-with-mfmailcomposeviewcontroller-in-swift-ios8-in to see how to parse an email address and strip out the necessary components.

Note that in testing this, it can't be done on a simulator, you have to use a real device to compose emails. Let me know what you think and if there's anything you'd like me to change/add!

@zachwaugh
Copy link
Contributor

Thanks for the PR! I think this is more an application-specific concern though, and would be out of scope for Turbolinks to handle.

@zachwaugh zachwaugh closed this Apr 26, 2016
@glennfu
Copy link
Author

glennfu commented Apr 26, 2016

Unfortunately I wasn't able to find a way to implement this in my own application WITHOUT adding it directly to Turbolinks. I couldn't figure out how to override the Session's decidePolicyForNavigationAction. Do you have any tips there for how I can do it, or does Turbolinks need some other change to expose this?

@sstephenson
Copy link
Contributor

See the instructions in Changing How Turbolinks Opens External URLs. Implement the session:openExternalURL: method in your Session delegate and perform the mailto: check there.

@glennfu
Copy link
Author

glennfu commented Apr 26, 2016

Wow I really went in all the wrong places looking for that. I don't know how I forgot about it, thanks!

@sstephenson
Copy link
Contributor

No problem!

@berardpb
Copy link

berardpb commented Oct 1, 2016

I might be doing something wrong, but I'm having a problem using the 'session:openExternalURL:' method. I'm trying to handle a mailto link, and, to start, just doing something basic:

func session(session: Session, openExternalURL URL: NSURL) {
        print("opening an external url: " + URL.absoluteString)
        let url = URL.absoluteString
        let url_elements = url.componentsSeparatedByString(":")
        if(url_elements[0] == "mailto"){
            print("we need to mail! to this address: " + url_elements[1])
        }
    }

For some reason, this is not firing when the page first loads. It only fires when I pull-to-refresh. Anyone have an idea as to what might be going on here?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants