LoginSignup
20
22

More than 3 years have passed since last update.

iOSコンソールログをWiFi経由で取得する

Last updated at Posted at 2017-01-04

iOSデバイスのコンソールログを、WiFi経由で取得することができます。

長時間のテストでもログを残しておけるため、特定の用途で、重宝します。

以下に、その方法を書き留めておきます。


追記(2021/1/14)

Xcode 12.3より挙動が変わったようです。
1. 以下で、libimobiledevice 1.3.0をインストール

$ brew install libimobiledevice

2. Xcode > Window menu > Devices and Simulators を開く
3. 対象のデバイスをUSB接続する
4. デバイスのシステムダイアログで"Trust(信頼する)"を選択
5. "Connect via network"にチェックマークを入れる
6. USBケーブルを抜く
7. デバイスがUnlock状態で以下のコマンドで<Network>付きのUDIDが出力されることを確認

$ idevice_id -n

※ここで表示されないときは、"Devices and Simulators"で表示されているデバイスを右クリックして、Connect via IP AddressからIP Addressを入力するとつながることがあります。
8. idevicesyslogを実行する。-nオプションを忘れずに。

$ idevicesyslog -n -u <udid>

※デバイスがUnlock状態では接続ができないため、idevicesyslogを実行する際は必ずLock screenを解除しておきましょう。


追記(2019/12/18)

しばらくの間、Wifi経由でidevicesyslogが動作していませんでしたが、ついにcommit 7dbc17fで改善されました!
※macOS Catalina 10.15.2 + libimobiledevice(d04f8ff)で動作を確認しました。

準備(新)

  1. 以下で、libimobiledeviceをインストール 1
$ brew install libimobiledevice --HEAD

こちらも参考にしてください。
2. Xcode > Window menu > Devices and Simulators を開く
3. 対象のデバイスをUSB接続する
4. "Connect via network"にチェックマークを入れる
5. デバイスをPairする。これをしないとERROR: Could not connect to lockdownd: -19となります。

$ idevicepair -u <udid> pair

6. USBケーブルを抜く
7. デバイスがUnlock状態で以下のコマンドでUDIDが出力されることを確認

$ idevice_id -n

8. デバイスのシステムダイアログで"Trust(信頼する)"を選択
9. idevicesyslogを実行する
※デバイスがUnlock状態では接続ができないため、idevicesyslogを実行する際は必ずLock screenを解除しておきましょう。


準備(旧)

  1. 以下で、libimobiledeviceをインストール 1
$ brew install libimobiledevice --HEAD

2. ロック解除済みのiOSデバイスをLightning CableでMacに接続
3. iTunesを開き、iOSデバイスのサマリーを表示
4. "Sync with this iPhone over WiFi(Wi-Fi経由でこのiPhoneと同期)"にチェックを入れて、Apply(適用)ボタンをクリック
5. 以下で接続したいデバイスのUDIDを特定(Lightning Cableは抜かない)

$ idevice_id --list
$ idevice_id -u <device_UDID>

6. Lightning Cableを抜く
7. iTunesからデバイスのサマリーが表示されていることを確認2

ログ取得

以下でログを取得します。

$ idevicesyslog -u <device udid>

[connected]が表示されて、ログが流れ出したら、正常に動作しています。
プロセスは、Ctrl-Cなどで終了します。

ログファイルに落としたい時は、teeコマンドを使うと便利です。

$ idevicesyslog -u <device udid> | tee <logfile>

Trouble shooting

Unable to find utility "clang"

brew install libimobiledevice --HEAD実行時に、

xcodebuild: error: SDK "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk" cannot be located.
xcrun: error: unable to find utility "clang", not a developer tool or in PATH

というビルドエラーが発生したら、以下を実行してください。

$ sudo xcode-select --reset

Error: Could not connect to lockdownd

Error: Could not connect to lockdownd, error code -8

iOS 10以降で、このエラーが発生することがあります。

これは、iOS 10以降で、デバイス接続時に用いるTLSバージョンがアップデートしたためのようです3

よって、以下を実行して、最新のopensslで、libmobiledeviceをビルドし直してください。


$ brew uninstall --ignore-dependencies libimobiledevice
$ brew install openssl
$ openssl --version # OpenSSL 1.0.2 is working well.
$ LD_LIBRARY_PATH=/usr/local/opt/openssl/lib CPATH=/usr/local/opt/openssl/include  brew install libimobiledevice --HEAD

さいごに

libimobiledeviceには、ログ取得の他に、(上記のように)UDIDの取得、アプリ内ディレクトリのマウント、デバイスのペアリング(Trust)など、便利な機能が揃っています。

ぜひ試してみてください。

libimobiledevice
http://www.libimobiledevice.org


  1. macOS El Capitan以降では、brew install libimobiledevice --HEADで最新版をインストールしてください。homebrew-coreで定義されているデフォルトバージョン(v1.2.0)が、2015-01-28のcommit tagであるため、正常に動作しません。 

  2. MacとiOSデバイスは、同じWiFiアクセスポイントに接続しておきましょう。 

  3. https://github.com/libimobiledevice/libimobiledevice/commit/72643b2b83990b9cf97cc84b285b30763d44a72d  

20
22
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
22