Signing Into Apps on Apple TV Sucks
Apple announced the refresh of the Apple TV in September — it’s first meaningful and most exciting update in years. Tim Cook touted that the future of TV is apps. Steve Jobs said he had “cracked it”.
Whatever “it” is, Steve definitely wasn’t talking about signing into apps.
When the app store was released two weeks ago, I rushed home and downloaded a bunch of apps. I was ready to discover the amazing future that Steve Jobs and Tim Cook had promised. Unfortunately, I couldn’t get past the front door of these apps because I was greeted by screens like this:
For many of these apps, you have to log in before using them. This would have been fine if you could pair a bluetooth keyboard or if Apple updated their Remote app to type in usernames and passwords. Sadly, you can do neither. The only way to input any sort of text is to use the on-screen keyboard — an experience I wouldn’t wish upon the worst of my enemies.
And I’m obviously not the only person feeling this pain.
So far my least favorite game on the new Apple TV is "Enter Your Password."
— Buzz Andersen (@buzz) November 5, 2015
Tangram’s authentication. via Tim Johnsen
It wasn’t all bad though. Apps like ESPN, Youtube, and Tangram recognize how painful this process is and had me enter a pin on a website that would communicate through their servers to log into the app.
While this was less painful, it still felt less than ideal — especially for apps I already had counterparts on my iPhone. In the hour* I spent typing in my Netflix username and password, I couldn’t help but wish I could just open my Netflix iPhone app and have these two apps “talk” to each other and log me in.
I decided to experiment with how that could work. While setting up the Apple TV, all you have to do is hold your iPhone nearby and the Apple TV picks up the same WiFi and password as your phone.
That felt like magic so I tried to emulate it with CoreBluetooth. Unfortunately, CoreBluetooth on the Apple TV seems to have some issues.
Has anyone gotten CoreBluetooth to work on tvOS? None of my CBCentralManagerDelegate discovery funcs are called • rdar://23374935
— Benny Wong (@bdotdub) November 3, 2015
UPDATE: As usual, this was a case of PEBCAK. Thanks to Robert Carlsen for pointing out I was using CBCentralManager incorrectly.
Enter Bonjour.
Bonjour, also known as zero-configuration networking, enables automatic discovery of devices and services on a local network using industry standard IP protocols.
Bonjour has long been part of the Apple ecosystem and is an easy set of tools to use.
We can take advantage of having both devices being on the same network using Bonjour. I built a prototype of what this would look like:
The code ended up being pretty straightforward. I was able to build the above with just NSNetService, NSNetServiceBrowser, and CocoaAsyncSocket. I’ve created a demo project for this: http://github.com/bdotdub/TriplePlay
When we click the login button, the tvOS app starts looking for services that provide a certain “type” — in the example, “_timehop_auth._tcp”.
let browser = NSNetServiceBrowser()
browser.delegate = self
browser.searchForServicesOfType("\_timehop\_auth._tcp", inDomain: "local.")
In the iOS app, we then start a service of the same type.
self.netService = NSNetService(domain: "local.", type: "\_timehop\_auth._tcp.", name: "Timehop Auth", port: port)
self.netService?.delegate = self
self.netService?.publish()
The Bonjour libraries does it’s thing and then we simply write the data to the connection, and voila! The authentication information is exchanged.
let data = “SOME\_AUTH\_TOKEN”.dataUsingEncoding(NSUTF8StringEncoding) newSocket.writeData(data, withTimeout: -1.0, tag: 0)
There are definitely some security implications that would need to be worked out, ie. anyone listening for _timehop_auth._tcp. could find your token, but this should show the basics of the interaction between iOS and tvOS. I’ve written up some alternatives here.
Outside of authentication, there are many more possibilities that Bonjour opens up for tvOS apps and their iOS app counterparts, such as:
- Using the Youtube iOS app to create and manage a playlist that the tvOS app is playing (à la Chromecast)
- For the Airbnb app, being able to zoom in on a specific area on the map with your phone and having the results show up in the tvOS app
- Selecting which stats you want the MLB tvOS app to show alongside the video.
I’m excited about what the future of TV holds. It’s been hard to experience this future because of the terrible experience of using the on-screen keyboard input. I’m hoping more tvOS apps will start taking advantage of the fact that most of it’s users will have an iPhone and their companion apps, and implement solutions that feel seamless and every bit magical.
UPDATE — 2015/11/11: Riz just open sourced Voucher, a library that provides the above functionality!
*= give or take a few minutes
**= or maybe Apple should just build it into Handoff