Closed glennfu closed 8 years ago
Thanks for the PR! I think this is more an application-specific concern though, and would be out of scope for Turbolinks to handle.
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?
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.
Wow I really went in all the wrong places looking for that. I don't know how I forgot about it, thanks!
No problem!
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?
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!