The ultimate solution to the “how on Earth do I host and show this Privacy Policy” problem

Introducing TelegraphKit

Oleg Dreyman
4 min readFeb 19, 2021
Screenshot of the web article displayed in the iOS App via TelegraphKit

It’s a well-known fact that app development (like any job) has its fair share of mundane tasks. Tasks like creating Legal pages, support screens, and settings screens, to name a few.

Let’s talk about adding a Privacy Policy. Maybe you already have written it (great work!), now how are you going to display it?

Should you just use a giant UITextView? What if the privacy policy changes? You always need to have your Privacy Policy up to date. It needs to be backend-editable.

Oh no, now what: buying a domain? Hosting a website? Choosing a CMS? For many apps, this is overkill.

I usually try to make these processes as simple and as streamlined as possible. So we usually host our Privacy Policies on Telegra.ph.

Telegraph is an anonymous publishing tool that lets you create richly formatted posts with photos and all sorts of embedded stuff. To create something on Telegraph, it literally takes ten seconds:

No account required. Zero configuration. Open the page, type, press Publish and copy the link. That’s it. (You can edit these pages in the same browser you’ve created them. To make it more robust, you can also link them to your Telegram account).

Introducing TelegraphKit

You could put this in a WKWebView as-is and call it a day, and it would still be a good experience (Telegra.ph pages load incredibly fast). But I went a little bit further.

The goal was for the end result to be simple and convenient for the developers, and delightful for the users. It felt important to present these pages in a way that looked and felt native.

Here’s what I was able to achieve (default Telegra.ph appearance vs. TelegraphKit):

Default Telegra.ph look (left) vs TelegraphKit (right)

Before I go into any details, let me first note that I’ve published this code as a Swift package, and it’s available on GitHub now:

Now, what exactly is it?

Some dark WKWebView magic

Quite a few improvements were made, but these two are the most obvious:

  • Dark mode support
  • System fonts and styles

It really has a native look & feel, which is lovely. And what’s interesting is that even though it looks native, it’s still just WKWebView under the hood! Just modified extensively to make it look just right.

To achieve that, I used a function called evaluateJavaScript to extend and modify the page’s look using HTML Styles. To support dark mode, the code simply reacts to the appearance change by turning on and off the corresponding “dark appearance” style. I’ve discovered this technique in this fantastic article by Daniel Jalkut, and it lies in the core of TelegraphKit.

To be fully satisfied with the look, hours were spent digging through Telegraph’s internal HTML structure with Chrome’s debugger. There was a lot of trial & error in the experiments. In the end, the result was well worth it.

You can check out the usage docs on the GitHub page, but it essentially boils down to this:

import TelegraphKit

let url = URL(string: "<your-telegraph-url>")!
let telegraphVC = TelegraphViewController(url: url)
let nvc = UINavigationController(rootViewController: telegraphVC)
self.present(nvc, animated: true)

TelegraphKit is now my go-to solution to show any informational content I need to create quickly and edit remotely. Beyond using it to display a Privacy Policy, I also use it to display Support pages, Guides, “What’s New” notes, and much more. It’s a highly valuable tool in my toolset that saves me tons of time. Hopefully it will be helpful for you as well!

I’m very excited about launching TelegraphKit, and excited to hear your thoughts and opinions on it!

Please try it out and let me know how it goes! Do you find it useful? Is there anything that you’re missing? Do you want it to have any other features, or to have even more flexibility and customization? Use the comments section below, open a GitHub issue or drop me a line at oleg@dreyman.dev, I’ll be happy to help!

--

--

Oleg Dreyman

iOS development know-it-all. Talk to me about Swift, coffee, photography & motorsports.