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

tvOS App Development

tvOS App Development

toshi0383

April 16, 2016
Tweet

More Decks by toshi0383

Other Decks in Programming

Transcript

  1. TOSHIHIRO SUZUKI > ླ໦ ढ़༟ > @toshi0383 > iOS/Mac/tvOS develper

    > currently at NEXTSCAPE 2 — © Toshihiro Suzuki 2016
  2. TOSHIHIRO SUZUKI > Develops Apps and contribute to OSS >

    Drives go-kart > Drummer > Snowboarder > try! Swift attendee 3 — © Toshihiro Suzuki 2016
  3. TVOS IS A NEW PLATFORM WE CAN USE THE NEWEST

    APIS 4 — © Toshihiro Suzuki 2016
  4. TODAY I WILL SHARE > our daily development and codebase.

    > tvOS specific topics > Readability tips 12 — © Toshihiro Suzuki 2016
  5. THE APP > is kind of like Netflix. > Already

    available on iOS/Android, AndroidTV, TVs > We're middle of development. We're not the owner of the service. 14 — © Toshihiro Suzuki 2016
  6. CARTHAGE $ cat Cartfile github "rs/SDWebImage" "master" github "toshi0383/TVMLKitchen" github

    "cbpowell/MarqueeLabel-Swift" github "duemunk/Async" github "ReactiveX/RxSwift" github "ikesyo/Himotoki" github "ishkawa/APIKit" ~> 1.3 github "realm/realm-cocoa" github "radex/SwiftyUserDefaults" "master" github "malcommac/SwiftDate github "AliSoftware/OHHTTPStubs" I checkin Carthage/Build/tvOS to repo. ! git history data gets larger " Build is fast 17 — © Toshihiro Suzuki 2016
  7. OTHER LIBRARIES > inamiy/DebugLog > Fabric (Crashlytics) > DRM Manager

    SDK (Static Library written in C) 18 — © Toshihiro Suzuki 2016
  8. PLAIN XCTEST > runs on Bitrise on every git-push >

    mostly tests for models > couple of async test > No UITests any more (we've quit) 22 — © Toshihiro Suzuki 2016
  9. SOLUTION /// Calls assertionFailure unless isRunningTests() is true /// This

    is useful in such case like when /// unstable API causes UITests failure. (which happens like always...) /// - parameter msg: func assertionError(msg: String = "") { if !isRunningTests() { assertionFailure(msg) } } 26 — © Toshihiro Suzuki 2016
  10. ISRUNNINGTESTS() /// Detects if app is running xctest /// -

    returns: true if running xctest func isRunningTests() -> Bool { let env = NSProcessInfo.processInfo().environment - if let path = env["XCInjectBundle"] { // Xcode7.2 - return NSString(string: path).pathExtension == "xctest" - } + if let _ = env["XCTestConfigurationFilePath"] { // Xcode7.3 + return true + } if let _ = env["UITest"] { return true } return false } 27 — © Toshihiro Suzuki 2016
  11. "UITEST" ENV VARIABLE /// HogeUITests.swift func setup() { ... let

    app = XCUIApplication() app.launchEnvironment["UITest"] = "" 28 — © Toshihiro Suzuki 2016
  12. MAKEFILE TEST_DESTINATION=-destination "platform=tvOS Simulator,name=Apple TV 1080p,OS=latest" TEST=xcodebuild $(XCODEFLAGS) -scheme $(SCHEME)

    clean test $(TEST_DESTINATION) .PHONY: test beta release archive clean ipa-beta ipa ship test: set -o pipefail $(TEST) 33 — © Toshihiro Suzuki 2016
  13. MAKEFILE archive: ./script/check-xcode-version.sh if [ $? -ne 0 ];then exit

    1;fi ./script/prepare_for_release.sh if [ ! -d $(BUILD_DIR)/script ];then mkdir -p $(BUILD_DIR)/script;fi xcodebuild -project $(PROJECT).xcodeproj -scheme $(SCHEME) \ -destination "generic/platform=tvOS" \ -xcconfig ./config/App-tvOS.xcconfig \ -archivePath $(ARCHIVE_PATH) \ PROVISIONING_PROFILE=$(PROVISIONING_PROFILE) \ -verbose \ archive | xcpretty --color ipa: xcodebuild -exportArchive -archivePath $(ARCHIVE_PATH) -exportPath $(BUILD_DIR) \ -exportOptionsPlist $(EXPORT_OPTION_PLIST) \ PROVISIONING_PROFILE=$(PROVISIONING_PROFILE) \ -destination "generic/platform=tvOS" 34 — © Toshihiro Suzuki 2016
  14. GITHUB RELEASE PAGE fastlane ios upload ipa:$(IPA_PATH) My boss will

    download this app and hand it to testers and customers. 37 — © Toshihiro Suzuki 2016
  15. HOW TO INSTALL A BETA APP TO DEVICE You always

    need a Xcode 38 — © Toshihiro Suzuki 2016
  16. TVOS SPECIFIC TOPICS > Focus Engine > TopShelf > TVML

    > UITabBar << > UITableView << > AVPlayerViewController << 40 — © Toshihiro Suzuki 2016
  17. UITABBAR <UITabBarController: 0x7fb3d5230c70> is trying to set 7 view controllers

    when only 5 view controllers are supported on this platform. Any additional view controllers will not be shown. 41 — © Toshihiro Suzuki 2016
  18. TIPS #2 Use typealias for important types typealias JSON =

    [String: AnyObject] typealias ProductId = String typealias GenreId = String struct Product: Decodable { let productId: ProductId? let productQualityType: ProductQuality? 46 — © Toshihiro Suzuki 2016
  19. TIPS #3 WRITE COMMENT, WRITE TESTS You will forget everything

    in next week. I guarantee. 47 — © Toshihiro Suzuki 2016
  20. TIPS #4 IT'S OKAY TO CODE IN YOUR LANGUAGE. enum

    RequestSortType: Int { case ৽ணॱ = 1, ̑̌Իॱ = 3, ਓؾॱ = 4 } switch sortType { case .৽ணॱ: break case .̑̌Իॱ: break case .ਓؾॱ: break } 48 — © Toshihiro Suzuki 2016
  21. TIPS #5 USE RXSWIFT WHERE NEEDED. func update(force: Bool) ->

    Observable<Void> { return Observable.create { observer in guard force || needsUpdate(self, interval: Constants.APIBatchUpdateInterval) else { observer.onCompleted() return AnonymousDisposable{} } let task = self.updateChannel().bindTo(self.updateTitleList) .subscribeCompleted { observer.onCompleted() self.lastSuccessfulUpdate = NSDate() } return AnonymousDisposable{task.dispose()} } } 49 — © Toshihiro Suzuki 2016
  22. WRAP UP I TALKED ABOUT > our daily development and

    codebase. > tvOS specific topics > Readability tips 50 — © Toshihiro Suzuki 2016
  23. BTW, IF YOU WANT A TVML AND NATIVE HYBRID TVOS

    APP I'VE HEARD OF TVMLKITCHEN. 54 — © Toshihiro Suzuki 2016