Flutter iOS 実機確認 ! Error : iPhone is busy: Preparing iPhone for development

FlutterアプリをiPhoneで実機確認した時のでメモ。 androidの場合実行デバイスの選択で実機も出てくるがiPhoneは出て来ず。 Flutterの設定というよりはiPhoneを開発用で使うときの設定と手順は同じはず。

flutter devices

したらXcode13入れろと出たのでXcode13をインストール

XCode13をインストールした後doctorしたらエラーでた。

flutter doctor
[] Connected device (2 available)
    ! Error: iPhone is busy: Preparing iPhone for development. Xcode will continue when iPhone is finished. (code -10)

iPhoneが開発用に準備中とのこと?なのでしばらく待つ。

    ! Error: iPhone is busy: Fetching debug symbols for iPhone. Xcode will continue when iPhone is finished. (code -10)

またエラー。だけど文言違う。作業中かな。。 XCode -> Window -> Devices and Simulatorsを開く

5分ほど待ったら終わった様子。

flutter doctorでもエラーなくなった。 VSCodeを再起動したら Command + Shift + Pでデバイス表示 出てきたのでrunすると

Could not build the precompiled application for the device.
════════════════════════════════════════════════════════════════════════════════
Building a deployable iOS app requires a selected Development Team with a 
Provisioning Profile. Please ensure that a Development Team is selected by:
  1- Open the Flutter project's Xcode target with
       open ios/Runner.xcworkspace
  2- Select the 'Runner' project in the navigator then the 'Runner' target
     in the project settings
  3- Make sure a 'Development Team' is selected under Signing & Capabilities > Team. 
     You may need to:
         - Log in with your Apple ID in Xcode first
         - Ensure you have a valid unique Bundle ID
         - Register your device with your Apple Developer Account
         - Let Xcode automatically provision a profile for your app
  4- Build or run your project again

For more information, please visit:
  https://flutter.dev/docs/get-started/install/macos#deploy-to-ios-devices

Or run on an iOS simulator without code signing
════════════════════════════════════════════════════════════════════════════════

Error launching application on iPhone.

Provisionning Fileとチームをが必要とのこと。無料でやる場合はとりあえず Xcodeで作成したアプリを実機デバイスでテストする方法ここら辺を参考にしてやればok

Xcodeを開いて 左のナビゲーションのRunner -> target Runner -> Signing & Capabilities

Bundle Identifierがcom.example.flutterとかになっていると、

Failed to register bundle identifier
The app identifier "com.example.flutter" cannot be registered to your development team because it is not available. Change your bundle identifier to a unique string to try again.  

bundle identifierをユニークなのに変えろって言われるので変更する。 そしてtry againすればok

run

OK!