xcrun simctl appinfoは、インストール済みアプリ1つを指定して詳細情報を表示するサブコマンドである。

基本的な使い方

appinfo <device> <bundle identifier>の形式で実行する。

$ xcrun simctl appinfo "TIL Appinfo iPhone" com.apple.mobilesafari
{
    ApplicationType = System;
    Bundle = "file:///Library/Developer/CoreSimulator/Volumes/.../MobileSafari.app/";
    CFBundleDisplayName = Safari;
    CFBundleExecutable = MobileSafari;
    CFBundleIdentifier = "com.apple.mobilesafari";
    CFBundleShortVersionString = "26.1";
    DataContainer = "file:///Users/xxx/.../Containers/Data/Application/<UUID>/";
    IsHidden = 0;
    ...
}

出力形式はlistappsと同じNSDictionaryのdescription形式である。 listappsが全アプリの一覧からgrepで該当アプリを絞り込む必要があるのに対し、appinfoは最初から1アプリ分の情報だけを直接取得できる。

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

appinfoは、対象デバイスが起動中でないと実行できない。

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

listappsget_app_containerも同様に、対象デバイスが起動中でないと同じUnable to lookup in current state: Shutdownエラーになる。

存在しないbundle identifierを指定した場合のエラー

デバイスの起動状態に問題がない場合、存在しないbundle identifierを指定すると、状態エラーとは別のエラーになる。

$ xcrun simctl appinfo "TIL Appinfo iPhone" com.til.nonexistent
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=3):
Simulator device failed to lookup application properties for com.til.nonexistent.
No application record found for that bundle identifier
...

デバイスの状態エラー(code=405)とアプリ未発見エラー(code=3)を区別できるため、スクリプトからエラーハンドリングする際の判定材料になる。

listappsに表示されないアプリの情報も取得でき、IsHiddenフィールドで理由が分かる

参考: xcrun simctl listappsでiOSシミュレータのインストール済みアプリ一覧を表示する

AccountAuthenticationDialog.appのような内部サービス用アプリを別のbundle identifierでインストールした場合、launchはできるのにlistappsには表示されない。

appinfoで同じアプリを直接指定すると、listappsに表示されなかった内部サービス用アプリでも情報を取得できる。

$ xcrun simctl listapps "TIL Appinfo iPhone" | grep -c "com.til.hiddenapp"
0

$ xcrun simctl appinfo "TIL Appinfo iPhone" com.til.hiddenapp
{
    ApplicationType = User;
    CFBundleDisplayName = AccountAuthenticationDialog;
    CFBundleIdentifier = "com.til.hiddenapp";
    IsHidden = 1;
    SBAppTags =     (
        hidden
    );
    ...
}

IsHidden = 1というフィールドが立っており、SBAppTagsにもhiddenが含まれている。 通常のユーザーアプリではIsHidden = 0になる。listappsが一覧から除外しているのは、このIsHiddenフラグが立っているアプリとみられる。

なおget_app_containerlistappsと同じくこのアプリのコンテナを取得できず、No such file or directoryエラーになる。 内部サービス用アプリのコンテナパスを知りたい場合は、appinfoBundleDataContainerフィールドが代わりの手段になる。