Disabling callouts in WKWebView by Paulo Fierro

A few months back I wrote about disabling the ability of a user to zoom a web page presented in a WKWebView. This is custom HTML content being displayed in an enterprise app, not a web site, so its not as nefarious as it sounds.

Another wish was to disable callouts. That's the pop-over that shows up when you long-tap on elements in Mobile Safari. They let you copy text, define a word or share a snippet.

A callout on iPad

A callout on iPad

There's no property on WKWebView that lets us do this, but we can do this similar to how we disabled the ability to zoom the page.

We pass a custom WKUserScript to our web view which creates a style tag and adds some styling which sets both -webkit-user-select and -webkit-touch-callout to none on all elements except input fields and textarea elements.

As always, remember that these powers should only be used for good.

Enabling SSL on SQUARESPACE by Paulo Fierro

In 2014 Google made an announcement stating they would boost sites using HTTPS encryption in search results. Apart from that there are several other great reasons for using HTTPS. This site is hosted on Squarespace and while you could access this via a squarespace.com subdomain, I prefer using my actual domain that I own and control.

After some searching I came across this excellent blog post describing how to get SSL for your Squarespace site using CloudFlare. Its fairly straightforward to set up and doesn't cost a thing.

Introducing Avoid Town by Paulo Fierro

Today we launched Avoid Town for iPhone, which easily lets you know how busy downtown is going to be on a particular day based on the number of cruise ships and passengers that will be arriving.

Avoid Town was made for people living and working on Grand Cayman where lots of ships also means lots of traffic. Check the app before you leave and you’ll be surprised by how much time you save.

Building the app, shooting and editing the promo and putting everything together for launch has been great fun and we've learned a ton.

Hopefully you'll find the app to be as useful as we do :)

Disabling magnification in WKWebView by Paulo Fierro

On a current project we're using the newly introduced (in iOS 8) and mostly awesome WKWebView to show custom HTML content. Now for some very specific reasons I can't get into, we need to disable the pinch-to-zoom gesture for all the pages that are displayed.

Luckily WKWebView has an allowsMagnification property to do just this, but unfortunately this and the other properties that allow you to modify the magnification are only available on OS X.

But all is not lost, we can attach our own custom Javascript to any page that we load. And with a little help from Javascript we can create a meta tag that disables scaling of the viewport and inject it into the document's <head>.

Once we have this Javascript we can create a WKUserScript object which we tell the WKUserContentController to always inject into loaded pages, and pass that controller to a WKWebViewConfiguration object, which is used when we create our WKWebView.

That sounds like a mouthful but its quite straightforward. Paste code the code below into a UIViewController's viewDidLoad method to try it out.

UPDATE: Initially I had written that we were loading arbitrary content from around the web which wasn't strictly the case and also caused a few people to suggest that this was a bad thing. Absolutely 100% agree. However in this specific case we are loading custom content, produced in-house and requires the gesture to be disabled.

Otherwise you probably should never do this.

And the same thing in Swift for funsies:

Embedding Gists on Squarespace by Paulo Fierro

I'm a big fan of Squarespace and the new platform is very well done. There are however a few things now and then that confuse me and one of these is embedding gists from Github.

I thought you'd use an Embed block for this, but for some reason this doesn't work.

The obvious choice?

The obvious choice?

Huh?

Huh?

Instead you have to scroll down (or search for) the Code block and paste the embed script in there.

The not so obvious choice

The not so obvious choice

Not quite as obvious as I thought, but at least it works.

Below is a random gist I use for converting WAV files to CAF for embedding in iOS apps:

The screenshots were edited in Napkin. Its great, you should try it.