RedditTV
Oct 18, 2015
Failed TV App and Thoughts on tvOS
I like to read Reddit on my spare time and I came across a post that talked about possibly making a Reddit TV app for the new upcoming Apple TV. I had also thought that this was a great idea and secretly thought that I would go ahead and tackle that as well.
I got pretty deep into the development of the app before coming across a show-stopping feature blocker that pretty much cripples the app for use in production. I decided that instead of consigning the work to the dustbin that I would put it out there into the world. At least it shows that I was just sitting around with my hands under my pants all this time.
How the App is Structured
The app is structured in a way similar to that of my other apps: There are two viewcontrollers: One shows a menu with a number of videos in a UICollectionView. The other is what is shown when someone actually clicks on a video. This is where we should see a video playing.
In order to make it easier to handle the download and other certain factorized logic, I created two files called UIFactory and URLFactory. The UIFactory never got a chance to do much. In my basketball app mostly what it did was to put together repetitive programmatically generated UIKit visual items like buttons. In this case all it does is generate a randomly selected background color. Because tvOS is so new, we have to do a lot of things from scratch. There are no available CocoaPods, including my normal menagerie of color utility tools. This means you gotta roll up your sleeves and bring your own beers to the party.
The MenuViewController has the UICollectionView, which is instantiated in MenuVC-Coll.swift file. Most of the stuff in the file is ordinary and normal for UICollectionView. However, the interesting thing is the code below.
func collectionView(collectionView: UICollectionView, canFocusItemAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
func collectionView(collectionView: UICollectionView, shouldHighlightItemAtIndexPath indexPath: NSIndexPath) -> Bool {
print("Hello!!! \(channels[indexPath.row])")
return true
}
The code above addresses the focus engine, the newest and most exciting thing about tvOS. Problem is that there are not a lot to read about making it work outside of the rather sparse code provided by Apple. The closest I got to it was this blog post from AirBnB engineering. I think it will help but the gist of what I got is that the tvOS focus engine has a bunch of additional methods that you gotta call so that you can work on the effects that you want to create when someone focuses on the particular cell. This function can then be passed down to the individual cell that is in the Collection.
thumbnail = UIImageView()
thumbnail.adjustsImageWhenAncestorFocused = true
So apparently now the behavior has been set that when the cell is focused on, the thumbnail image expands to indicate that the cursor is on it. Cool default behavior, Apple.
The rest of the app is a pretty simple UICollectionView. I am coming across some sort of bug with the UICollectionViewCell is displaying the wrong thumbnail. This is likely due to the code reusing and recycling a cached image before the image is properly downloaded from the source. I am honestly just too lazy to deal with it.
The Show Stopper
The reason I did not progress with this app is that it cannot play YouTube videos. The usual accepted way to display YT video in an app is to create a UIWebView and have it play the video. This is how the general YT iOS plugin works. The difference is that Apple removed UIWebView from tvOS. This is likely for performance and usage reasons. The only available video player works by using an underlying mp4 file. I don’t have access to that.
I reviewed some StackExchange answers to figure out how to get around this. I came across this thread that discusses using some sort of workaround that cracks open the YouTube link’s stream and accesses the underlying video file. Naturally this is hella against the TOS. Then Apple finally chimed in and said:
There is no support for WebViews on tvOS, and so an iframe implementation will not work. TVML does not offer this capability.
As my former coworker Paul used to say all the time, “Goddammit”. I am sure that at some point that YouTube is going to figure out a way to handle this but until then I am going to leave it as it is. Maybe other people can take a look at it and get something useful out of it.
Thoughts on tvOS
“TVML is Some Scary Shit”
I am no HTML and JS master, okay, so take this with a grain of salt. But I don’t like switching between too many windows and IDEs and right now when I am trying to develop in TVML I am switching between Chrome, XCode, iOS Simulator, TextMate and whatever code samples I have on the screen right now. That is just too much. Does XCode do some sort of support for code highlighting for its TVML language? It doesn’t even format the spacing all that well there. Not my most pleasant coding experience and code completion is not present.
What They Took Out Kinda Makes Sense
I mean it sucks that they took out UIWebView (and I suppose you can make some sort of argument about keeping some crippled version behind on it - and the total list can be found here) but of what else they took out, much of it makes sense to me. For example, they took out UIActionSheet, which is something I had used fairly often but it makes sense to me. How can you manipulate a menu like that with a TV remote? (See below) So it makes sense to dump it.
There’s Still A Lot of Overlap
This is good and I briefly considered turning the tvOS app into an iOS one before going nah and moving on with my life - there is already a redditTV app on the App Store and it’s pretty good. I think if I were to come across a new idea then I would probably find it pretty easy to move back into that world - focus Engine notwithstanding.
Using the iOS Simulator is Infuriating
I think this was the most irritating part of using the whole thing. It pops up fine and all but then in order to navigate around you have to go and click into the menu to find this crappy ass remote so that we can move around the cursor.
You got to hold down the OPTION button and then paw about with the cursor over the digital remote field. “Cursor” is the appropriate term for what it is and the appropriate term for who I am while using it. It does not work for a while and then suddenly does. Then it stops working because the cursor is off the TV remote field. Just … ugh. Is this what it is going to be like with the actual thing?
####Conclusion (or TLDR)
tvOS sounded fun and I had a lot of fun writing what I got through so far. If I can come up with an idea for the future then I would definitely work on the SDK again. I hate that remote. YouTube won’t work without UIWebView so without UIWebView this app doesn’t work.
Share