[[UIApplication sharedApplication] openURL:url] not working on mailto
*Hack warning*: This is not an elegant or nice solution, so feel free to berate me for damage to your eyes 🙂
If you are using PhoneGap with iPhone, then you have noticed that external urls don’t open unless you modify
shouldStartLoadWithRequest, This works fine with http:// and https:// urls, but I’ve noticed that it didn’t work with tel: or mailto: links. Despite millions of posts on the internet saying it ‘should’ work. I found a horrible hack that avoids this problem, by creating a HTML page on my server, with the content:
<script language=”javascript”> function getParameterByName(name) { name = name.replace(/[\[]/, “\\\[“).replace(/[\]]/, “\\\]”); var regexS = “[\\?&]” + name + “=([^&#]*)”; var regex = new RegExp(regexS); var results = regex.exec(window.location.search); if(results == null) return “”; else return decodeURIComponent(results[1].replace(/\+/g, ” “)); } var url = getParameterByName(“url”); window.location.href=url; </script>
Which, very simply, means that you can send a user to http://yourserver.com/link.html?url=mailto:me@me.com – sending the user to safari, then the mail client immediately afterwards.
Feel free to throw up your lunch now.