How can I get the console logs from the iOS Simulator?

前端 未结 13 1596
感情败类
感情败类 2020-11-27 09:24

I want to see what happens in the iOS Simulator if I\'m not testing the app in Xcode.

For example, if I open a link in the Safari simulator, see what happens in the

13条回答
  •  不知归路
    2020-11-27 09:46

    You should not rely on instruments -s. The officially supported tool for working with Simulators from the command line is xcrun simctl.

    The log directory for a device can be found with xcrun simctl getenv booted SIMULATOR_LOG_ROOT. This will always be correct even if the location changes.

    Now that things are moving to os_log it is easier to open Console.app on the host Mac. Booted simulators should show up as a log source on the left, just like physical devices. You can also run log commands in the booted simulator:

    # os_log equivalent of tail -f
    xcrun simctl spawn booted log stream --level=debug
    
    # filter log output
    xcrun simctl spawn booted log stream --predicate 'processImagePath endswith "myapp"'
    xcrun simctl spawn booted log stream --predicate 'eventMessage contains "error" and messageType == info'
    
    # a log dump that Console.app can open
    xcrun simctl spawn booted log collect
    
    # open location where log collect will write the dump
    cd `xcrun simctl getenv booted SIMULATOR_SHARED_RESOURCES_DIRECTORY`
    

    If you want to use Safari Developer tools (including the JS console) with a webpage in the Simulator: Start one of the simulators, open Safari, then go to Safari on your mac and you should see Simulator in the menu.

    You can open a URL in the Simulator by dragging it from the Safari address bar and dropping on the Simulator window. You can also use xcrun simctl openurl booted .

提交回复
热议问题