Debugging the random
The idea behind Rewatch is to suggest you a random episode you’ve already watched. The algorithm behind it is not very good right now: there isn’t one. Well there is one, but it only selects one random episode without taking into consideration that maybe you hated that episode or that maybe you watched it yesterday. Today I wanted to talk about an issue I had when a friend came to me with a layout issue on a very specific Breaking Bad episode.
The problem when your application displays random content is that it’s really hard to reproduce bugs. That’s why I came with a feature to be able to reproduce this kind of issue.
URL Scheme
The first thing I needed to be able to do was opening a very specific episode in the application without shaking my phone too many time. The obvious solution was adding an URL scheme into the application.
To be honest this scheme was already available in the application as part of the Betaseries authentication workflow. I only had to handle a new URL:
This worked well but there was still one issue: I had to know the episode id. Betaseries comes with a really nice API console but it wasn’t really fun to query a bunch of endpoints to retrieve the id of the episode I wanted to display in Rewatch.
Sharing sheet
Knowing that the issue would happen again, I needed a way to quickly retrieve the URL that would reopen the application on a specific episode. I ended up working on the sharing feature of an episode sooner than expected. The idea was to be able to share this URL and add it to my home screen.
The problem is that you cannot do that. That’s a sharing activity only available to Safari. I considered for a while making this feature available on the Rewatch website but my Rails skills being what they are (non-existant), I figured it would be easier to manage it directly within the application.
Embedding an HTTP Server
One of my favorite iOS application is Workflow, a tool that allows you to create a specific chain of actions to achieve a goal. They came with a way to make workflows directly available on your home screen so you could trigger them in one tap, which is awfully convenient if you have a lot of them.
Right after I told them what an awesome feature it was, I implemented the same in Rewatch. So that when you selected the “Generate Deeplink” activity in the sharing sheet, a few things would happen:
- A local HTTP server would be started
- A local URL handled by this server would be opened in Safari. This URL would redirect to a static page so that we don’t need the server to be up to view it. I used Swifter for the server and Mustache to handle the heavy lifting.
I simply had to make this page available on my home screen via the Safari sharing sheet.
Hiding the feature
Of course I don’t want to make this feature available to all the users. Not that it’s risky or anything but I doesn’t provide any value. That’s why I added a checkbox in the settings panel so you’ll need to be actually looking for something before finding it.
Today I’m really convinced that this feature was slightly overkill and that I could have shipped Rewatch 1.0 without it. It was fun and interesting to work on it nonetheless.
I’ll end this post with a quick reminder that Rewatch is open-source and that I’m available on twitter if you’re curious about something!