Home > Uncategorized > [[UIApplication sharedApplication] openURL:url] not working on mailto

[[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.

 

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: