5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

tvOSAdvent Calendar 2017

Day 21

Apple TVからHDMIケーブルを抜くとアプリはどうなるの?

Last updated at Posted at 2017-12-20

こんにちは。
小ネタです。

はじめに

以下のようにApple TVからHDMIケーブルを抜いた場合どうなるのでしょうか?

  1. tvOSネイティブアプリを動かす
  2. アプリ使用中にApple TVからHDMIケーブルを抜く

HDMIケーブルを抜くと applicationWillResignActive が呼ばれる

下記コードを使った実験から、HDMIケーブルを抜くと applicationWillResignActive が呼ばれることがわかりました。

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        print("\(Date()), \(#function)")
        return true
    }

    func applicationWillResignActive(_ application: UIApplication) {
        print("\(Date()), \(#function)")
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        print("\(Date()), \(#function)")
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        print("\(Date()), \(#function)")
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        print("\(Date()), \(#function)")
    }

    func applicationWillTerminate(_ application: UIApplication) {
        print("\(Date()), \(#function)")
    }
}

実行当時のログ。

2017-12-10 01:41:41 +0000, application(_:didFinishLaunchingWithOptions:) // アプリ起動
2017-12-10 01:41:42 +0000, applicationDidBecomeActive                    // アプリ起動の流れで didBecomeActive が呼ばれた
2017-12-10 01:41:44 +0000, applicationWillResignActive                   // アプリが画面に映ったあとにHDMIケーブルを抜いた
2017-12-10 01:41:55 +0000, applicationDidBecomeActive                    // HDMIケーブルを挿してSiriリモートのボタンを押した

まとめ

tvOSのネイティブアプリを実行中にHDMIケーブルを外した場合、applicationWillResignActive が呼ばれることを紹介しました。

5
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?