Upgrade to Pro — share decks privately, control downloads, hide ads and more …

📺

 📺

Introduction to tvOS development, given at try! Swift 2016 in Tokyo. 🇯🇵

Boris Bügling

March 02, 2016
Tweet

More Decks by Boris Bügling

Other Decks in Programming

Transcript

  1. “‘I’d like to create an integrated television set that is

    completely easy to use,’ he told me. [...] ‘It will have the simplest user interface you could imagine. I finally cracked it.’”
  2. STORAGE LIMITATIONS ▸ app is limited to 200 MB ▸

    500 KB of persistent storage (NSUserDefaults) ▸ Use iCloud ▸ Use On-Demand resources
  3. NIBS ! If you don't feel like copy-pasting stuff between

    NIBs ! https://github.com/neonichu/bohne
  4. FOCUS ENGINE UIButton().canBecomeFocused() // == true or false UIButton().focused //

    == true or false UIScreen.mainScreen().focusedView // nil or the view in focus
  5. REACTING TO FOCUS CHANGES func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator)

    context.nextFocusedView // the view which gets the focus context.previouslyFocusedView // the view which had the focus func addCoordinatedAnimations(_ animations: (() -> Void)?, completion completion: (() -> Void)?)
  6. CUSTOMFOCUSVIEW let duration = UIView.inheritedAnimationDuration() UIView.animateWithDuration(duration, animations: { if context.nextFocusedView

    == self { self.backgroundColor = UIColor.redColor() } if context.previouslyFocusedView == self { self.backgroundColor = UIColor.whiteColor() } })
  7. DEBUGGING FOCUS print(view.performSelector("_whyIsThisViewNotFocusable")) e.g. for a UILabel Unmanaged<AnyObject>(_value: ISSUE: This

    view has userInteractionEnabled set to NO. Views must allow user interaction to be focusable. ISSUE: This view returns NO from -canBecomeFocused. )
  8. GOOD PLACES FOR BREAKPOINTS func shouldUpdateFocusInContext(_ context: UIFocusUpdateContext) -> Bool

    func didUpdateFocusInContext(_ context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator)
  9. GESTURES AND BUTTON PRESSES let tapRecognizer = UITapGestureRecognizer(target: self, action:

    "tapped:") let pressTypes = [NSNumber(integer: UIPressType.PlayPause.rawValue)] tapRecognizer.allowedPressTypes = pressTypes; self.view.addGestureRecognizer(tapRecognizer) let swipeRecognizer = UISwipeGestureRecognizer(target: self, action: "swiped:") swipeRecognizer.direction = .Right self.view.addGestureRecognizer(swipeRecognizer)
  10. LOWER-LEVEL API: UIPress Very similar to UITouch-based API in iOS

    func pressesBegan(presses: Set<UIPress>, withEvent event: UIPressesEvent?) func pressesEnded(presses: Set<UIPress>, withEvent event: UIPressesEvent?) func pressesChanged(presses: Set<UIPress>, withEvent event: UIPressesEvent?) func pressesCancelled(presses: Set<UIPress>, withEvent event: UIPressesEvent?)
  11. SIRI REMOTE IS ALSO A GAME CONTROLLER ▸ Profile GCMicroGamepad

    ▸ Touch surface is a dpad ▸ Two action buttons ▸ Motion (GCMotion) ▸ Seems not to work in the simulator
  12. NSNotificationCenter.defaultCenter().addObserverForName(GCControllerDidConnectNotification, object: nil, queue: nil) { (note) in if let

    controller = note.object as? GCController { if let microPad = controller.microGamepad { microPad.dpad.valueChangedHandler = { (_, x, y) in if let paddle = self.childNodeWithName("Paddle") { paddle.position.y += CGFloat(y) } } } } }
  13. 2.27 If your app’s core functionality doesn’t work with the

    Siri remote it will be rejected. The app may, however, provide enhanced functionality in connection with a game controller or other peripheral
  14. A maximum of two game controllers (plus one remote) can

    be connected to an Apple TV at any given time.
  15. CONCLUSION ▸ tvOS works very well ▸ If you know

    UIKit, it's easy to start ▸ Think about interaction
  16. RESOURCES ▸ https://developer.apple.com/tvos/human-interface-guidelines/ ▸ "Ich glotz TV", @avbelow, Macoun 2015

    ▸ https://speakerdeck.com/toco/intro-to-tvos ▸ http://nerds.airbnb.com/tvos-focus-engine/ ▸ https://eternalstorms.wordpress.com/2015/10/05/pair-the-apple- tv-developer-kit-siri-remote-with-xcodes-simulator/