Appleの公式SwiftUI Tutorialsは品質が高くて俄然やる気が出ます。
ただし今回はビルドができない問題に引っかかったので、その対処法を紹介します。
課題
上記サンプルアプリの完成版プロジェクトを開いて署名し実機テストしようとすると以下のエラーメッセージが出た。
Error Message
WatchKit App doesn't contain any WatchKit Extensions whose WKAppBundleIdentifier matches "com.example.apple-samplecode.LandmarksXXXXXXXXXX.watchkitapp". Verify that the value of WKAppBundleIdentifier in your WatchKit Extension's Info.plist matches the value of CFBundleIdentifier in your WatchKit App's Info.plist.
WatchKit Extensions
のWKAppBundleIdentifier
と
WatchKit App
のCFBundleIdentifier
が一致していないことが問題のよう。
原因
各TargetのBundle Identifierは以下の通り。
*Bundle Identifierは上記画像のように各TargetのSining &Capabilities
から確認可能。
- Landmarks (iOS App):
com.example.apple-samplecode.Landmarks${SAMPLE_CODE_DISAMBIGUATOR}
- WatchLandmarks(WatchOS APP):
com.example.apple-samplecode.Landmarks${SAMPLE_CODE_DISAMBIGUATOR}.watchkitapp
- WatchLandmarks Extension:
com.example.apple-samplecode.Landmarks${SAMPLE_CODE_DISAMBIGUATOR}.watchkitapp.watchkitextension
唐突に出てくる${SAMPLE_CODE_DISAMBIGUATOR}
って誰だよ。
(自分の理解では)AppleのTutorialのような公開プロジェクトは配布時にBundle Identifierに初期値を与えるとみんなで衝突しちゃうから、それを回避するために、Development TeamのID?を加えてユニークな値になるようにしている。
なのに、下記画像のようにInfoタブから確認できるプロパティリストの方ではBundle IdentifierにDevelopment Teamに関連する値が追加されていない。
解決法
- WatchLandmarks(WatchOS APP)の
WKCompanionAppBundleIdentifier
にcom.example.apple-samplecode.Landmarks${DEVELOPMENT_TEAM}
と設定。 - WatchLandmarks Extensionの
NSExtension
>NSExtensionAttributes
>WKAppBundleIdentifier
にcom.example.apple-samplecode.Landmarks${DEVELOPMENT_TEAM}.watchkitapp
と設定。
これでいける。