Apple recently released the tvOS SDK, which helps developers build applications for the new Apple TV which will be shipping late October this year. Since we at Contentful want to help you bring your content to every screen, this article will give you a brief overview of building apps for bigger, Apple TV-powered screens.
Like watchOS, tvOS is a variant of iOS, which is especially evident from its version number,
9.0, analogous to the just released iOS 9. Unlike on the watch, though, we can actually build truly native apps without hacks. The TV apps are using
UIKit directly, and lower-level graphics frameworks like Metal or OpenGL ES are also available.
The major difference between tvOS and iOS is the interaction model: the Apple TV apps are controlled with a remote, not a finger. tvOS introduces focus model: the user can switch the focus from one view to another and perform actions on the selected view.
A few additions have been made to the UIKit to deal with focusing views:
UIButton().canBecomeFocused() // == true or false UIButton().focused // == true or false UIScreen.mainScreen().focusedView // nil or the view in focus
First, you would need to get the beta of Xcode 7.1, because of the tight coupling of components Apple does these days. I would recommend using xcode-install for this task, as it makes the management of multiple Xcodes much more pleasant and it performs an additional code-sign check as well. You can also download it manually from the Developer Portal, though.
$ [sudo] gem install xcode-install $ export XCODE_INSTALL_USER=developer-apple-id $ export XCODE_INSTALL_PASSWORD=developer-apple-id-password $ xcode-install install '7.1 beta 2'
I am also assuming you are using CocoaPods to get the Contentful SDK, because there is no binary build for the tvOS branch, yet. If you wish, you can also integrate it manually. You will need a Podfile like this at the moment, as forks or special podspecs are needed for the dependencies as well:
platform :tvos, '9.0' use_frameworks! target 'tvful' do pod 'ContentfulDeliveryAPI', :git => 'https://github.com/contentful/contentful.objc.git', :branch => 'tvos' pod 'AFNetworking', :git => 'https://github.com/neonichu/AFNetworking.git', :branch => 'tvos' pod 'ISO8601DateFormatter', :podspec => 'vendor/ISO8601DateFormatter.podspec.json', :inhibit_warnings => true end
You will also need a Gemfile to use a development version of CocoaPods:
source 'https://rubygems.org' gem 'cocoapods', :git => 'https://github.com/CocoaPods/CocoaPods.git', :branch => 'master' gem 'cocoapods-core', :git => 'https://github.com/CocoaPods/Core.git', :branch => 'master' gem 'xcodeproj', :git => 'https://github.com/CocoaPods/Xcodeproj.git', :branch => 'master'
Time to install pods using bundler:
$ bundle install $ bundle exec pod install
It is generally a good practice to start using bundler for any RubyGems required in your development setup, as it allows consistent versioning and an easier installation experience for new developers on your team.
If you need other dependencies for your TV apps which haven't been updated yet, you can either create forks or use cocoapods-expert-difficulty plugin for ignoring the platform specification from the podspec. Be aware, though, that some Pods might not work or may require source code changes – hence the name.
After setting up the tvOS development environment you can use the Contentful SDK in the same way as on any other platform – with the exception that some of the UIKit helper classes are not available. You can find a full example project on GitHub, which helps skipping some of the manual setup. The example project just shows a list of images inside a collection view, using the data from the Contentful gallery sample app.