xcrun simctl icloud_syncは、シミュレータデバイスに対してiCloud同期を即座にトリガーするサブコマンドである。

基本的な使い方

icloud_sync <device>の形式で実行する。 デバイスが起動中で、かつiCloudアカウントが設定済みであれば成功する。

$ xcrun simctl icloud_sync "TIL Icloud Sync iPhone"

エラーがなければ何も出力されず、終了コードは0になる。

対象デバイスは起動中(Booted)である必要がある

シャットダウン状態のデバイスに対して実行すると、他の多くのサブコマンドと同様にエラーになる。

$ xcrun simctl shutdown "TIL Icloud Sync iPhone"
$ xcrun simctl icloud_sync "TIL Icloud Sync iPhone"
An error was encountered processing the command (domain=com.apple.CoreSimulator.SimError, code=405):
Unable to lookup in current state: Shutdown

iCloudアカウントが設定されていないデバイスでは常に失敗する

新規作成したシミュレータのようにiCloudアカウントが1つも設定されていない状態でicloud_syncを実行すると、明確なエラーになる。

$ xcrun simctl icloud_sync "TIL Icloud Sync iPhone"
An error was encountered processing the command (domain=BRCloudDocsErrorDomain, code=153):
Simulator device failed to trigger iCloud sync.
Underlying error (domain=BRCloudDocsErrorDomain, code=153):
	The operation couldn’t be completed. (BRCloudDocsErrorDomain error 153.)

このエラーの原因は、xcrun simctl spawn <device> log stream --predicate 'process == "bird"'でiCloud同期を担うデーモンbirdのログを確認すると分かる。

[iCloudDriveCore] [DEBUG] Loaded 0 system icloud accounts with error: (null)
[iCloudDriveCore] [INFO] (Logged out): reply(...)
[iCloudDriveCore] [WARNING] Returning error because iCloud Drive not supported

birdは「0個のiCloudアカウントを読み込んだ」「ログアウト状態」と記録している。 iCloudアカウント未設定のためiCloud Driveがサポート外と判定され、同期リクエストが即座に拒否される。