iOS 10 doesn't print NSLogs

后端 未结 9 1448
情书的邮戳
情书的邮戳 2020-12-04 09:43

Nothing prints from NSLog on Xcode 8.0 beta (8S128d). printf is unchanged

Here\'s my code:

NSLog(@\"hello from NSLog\");
pr         


        
相关标签:
9条回答
  • 2020-12-04 10:09

    For anyone who comes upon this in the future. The reason NSLog doesn't print to syslog in iOS 10 and iOS 11 is due to Apple changing to Unified Logging.

    You can see the WWDC talk about it here: https://developer.apple.com/videos/play/wwdc2016/721/

    Documentation here: https://developer.apple.com/documentation/os/logging

    From 10 on you should be using os_log instead of NSLog.

    How to find the logs on disk: https://www.blackbagtech.com/blog/2017/09/22/accessing-unified-logs-image/

    To summarize, the logs are located in /var/db/diagnostics which can be found for a VM at /Users/USERNAME/Library/Developer/CoreSimulator/Devices/SIMULATOR-GUID/data/var/db/

    Copy all items inside diagnostics and uuidtext into a single folder (don't include the folders diagnostics or uuidtext just what is inside).

    Rename that folder foldername.xarchive.

    Open it in Console.app or use the OSX util log: log show <path to archive> --info --predicate <options>

    0 讨论(0)
  • 2020-12-04 10:12

    It could be that you added the property "OS_ACTIVITY_MODE": "disable" in the Scheme environment variables (to hide OS output from the simulator) and forgot about it, and now are running on a real device.

    In Xcode 8:

    Product -> Scheme -> Edit Scheme -> Run -> Arguments -> Environment Variables
    

    Only add OS_ACTIVITY_MODE and check it(Don't add a value)

    Summary: This is a bug of Xcode 8 + iOS10, we can solve it in this way:

    • When using the simulator, add the Name "OS_ACTIVITY_MODE" and the Value "disable" and check it.

    • When on a real device, only add "OS_ACTIVITY_MODE" and check it(Don't add the Value). You will see the NSLog in the Xcode8 Console.

    0 讨论(0)
  • 2020-12-04 10:12

    the NSlog or print actually is executed but is hidden among lots of other console debug outputs to solve this issue Open Xcode8:

    Product -> Scheme -> Edit Scheme -> Run -> Arguments -> Environment Variables
    

    add "OS_ACTIVITY_MODE" and set the Value to "disable" and check it.

    click close

    xcode9

    add "OS_ACTIVITY_MODE" and set the Value to "default" and check it.

    0 讨论(0)
提交回复
热议问题