WatchKit発表!! | piceのブログ

piceのブログ

IT関係のニュース、関連情報をご紹介します。

こんにちは、piceです。


久しぶりの更新になってしまい、すみません。


Apple Watchの開発キット「WatchKit」が発表されたので、早速


触ってみました。


ポイントは


Xcode6.2betaでプロジェクト作成後「File」→「New」→「Target」でApple Watchのところの「Watch App」を選択。

②「~(アプリ名)WatchKit Extension」のInterfaceController、「~(アプリ名)Watch App」のInterface.storyboardを編集。
(今回”~”の部分は「WatchKitSample」としました)

③「▶(ビルド)」ボタン横の「Set the active scheme」と表示が出るところで、「~(アプリ名)Watch App」のschemeを選択、iPhone5以降のシミュレータを選択し、「▶(ビルド)」ボタンを押下。

④iOSシミュレータが起動したら、iOS Simulator側で「Hardware」→「External Displays」→「Apple Watch」を選択。

こうすると、Apple Watchのシミュレータが起動し、作成したアプリが起動します。今回のサンプルコードは以下のようにしました

****************************************************
class InterfaceController: WKInterfaceController {

    override init(context: AnyObject?) {
        // Initialize variables here.
        //実際に編集したのは"WKInterfaceDate()"のみです。
        WKInterfaceDate()
        super.init(context: context)
       
        // Configure interface objects here.
        NSLog("%@ init", self)
    }

    override func willActivate() {
        // This method is called when watch view controller is about to be visible to user
        super.willActivate()
        NSLog("%@ will activate", self)
    }

    override func didDeactivate() {
        // This method is called when watch view controller is no longer visible
        NSLog("%@ did deactivate", self)
        super.didDeactivate()
    }

}

****************************************************

上記のコードでビルドすると、実行結果は以下のようになりました。

これからApple Watchのアプリも開発していければと思います。