iOS开发Xcode8的log输出“__nwlog_err_simulate_crash simulate crash failed "nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available”怎么办?

iOS开发Xcode8的log输出“__nwlog_err_simulate_crash simulate crash failed
『导言』

亲呐,你有木有升级xcode8?有木有遇到这样的输出,老长了,怎么办?

  • 分析:
升级xcode8后,屏蔽后台的多余的输出log输出:
objc[2126]: Class PLBuildVersion is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x12ce244c) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x12b23b78). One of the two will be used. Which one is undefined.
2017-04-05 11:38:20.033821 DeliciousFoodDemo[2126:87760] [] nw_host_stats_add_src recv too small, received 24, expected 28
2017-04-05 11:38:20.039139 DeliciousFoodDemo[2126:87760] [] ____nwlog_simulate_crash_inner_block_invoke dlopen CrashReporterSupport failed
2017-04-05 11:38:20.039711 DeliciousFoodDemo[2126:87760] [] __nwlog_err_simulate_crash simulate crash failed "nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available"
2017-04-05 11:38:20.041064 DeliciousFoodDemo[2126:87760] [] nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available, dumping backtrace:
        [i386] libnetcore-856.30.16
    0   libsystem_network.dylib             0x032f414d __nw_create_backtrace_string + 123
    1   libnetwork.dylib                    0x043fa7a6 nw_socket_add_input_handler + 3588
    2   libnetwork.dylib                    0x043d56fe nw_endpoint_flow_attach_protocols + 4199
    3   libnetwork.dylib                    0x043d457a nw_endpoint_flow_setup_socket + 581
    4   libnetwork.dylib                    0x043d31ed -[NWConcrete_nw_endpoint_flow startWithHandler:] + 2545
    5   libnetwork.dylib                    0x043f0cf0 nw_endpoint_handler_path_change + 2835
    6   libnetwork.dylib                    0x043f00f6 nw_endpoint_handler_start + 589
    7   libnetwork.dylib                    0x044098c0 nw_endpoint_resolver_start_next_child + 2634
    8   libdispatch.dylib                   0x03092396 _dispatch_call_block_and_release + 15
    9   libdispatch.dylib                   0x030bdcc3 _dispatch_client_callout + 14
    10  libdispatch.dylib                   0x0309a3ae _dispatch_queue_serial_drain + 1619
    11  libdispatch.dylib                   0x0309abc2 _dispatch_queue_invoke + 1109
    12  libdispatch.dylib                   0x0309d5e4 _dispatch_root_queue_drain + 470
    13  libdispatch.dylib                   0x0309d3a6 _dispatch_worker_thread3 + 143
    14  libsystem_pthread.dylib             0x0350e25c _pthread_wqthread + 1050
    15  libsystem_pthread.dylib             0x0350bf56 start_wqthread + 34
解决方法
  • 首先,找到Environment Variable
    • 找到在Xcode的菜单栏,依次进入:
      【product】-【scheme】-【Edit Scheme】-【Run】-【Argument】-【Environment Variable
  • 快捷键操作:
    快捷键【 shift】【command】【< 】
    图.添加设置
  • 然后,点击+添加进行设置
key value
OS_ACTIVITY_MODE disable
iOS开发Xcode8的log输出“__nwlog_err_simulate_crash simulate crash failed
图.设置

动态教程.gif
  • 补充:
  • 遗留问题:还会出现,属于正常现象
Class PLBuildVersion is implemented2017-04-05 11:05:47.616 DeliciousFoodDemo[2090:68216] http://api.2meiwei.com/v1/index/index/
objc[2090]: Class PLBuildVersion is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x18c0b44c) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x18a4cb78). One of the two will be used. Which one is undefined.
2017-04-05 11:05:47.778 DeliciousFoodDemo[2090:68216] 0
iOS开发Xcode8的log输出“__nwlog_err_simulate_crash simulate crash failed
图.xcode8遗留问题.png
  • 问题分析
    意思是PhotoLibraryServices.frameworkAssetsLibraryServices.framework产生了冲突,系统不知道用哪个
    Class PLBuildVersion在框架AssetsLibraryServices和框架PhotoLibraryServices里都有定义。在Objective-C里Class名是唯一。两个同名的Class,Xcode会选择其中一个Class来执行。PLBuildVersion在这两个框架里都是一样的,不影响实际运行。

  • 在xcode8中,屏蔽了一些奇怪的输出之后,又发现了一个。具体啥原因还不是太清楚。但是可以解决这个问题,让其停止打印这个信息。

    info.plist中,添加两个键值对:

|序号|对象|key|value|
|-------|--------|-------|
|1|针对photo|Privacy - Photo Library Usage Description| $(PRODUCT_NAME) photo use //(解释对相册的使用)|
|2|针对camera|Privacy - Camera Usage Description|$(PRODUCT_NAME) camera use //(解释对相机的使用)|

这个方法仅仅解决了photo方面的,好像别的功能(加载WebView)也会有类似的报错。
主要是因为iOS10在用户的隐私方面的改动。
并不影响程序工作,但是还没有找到完全避免的方法!
更新到Xcode新版本之后,这个打印已经没有了。比如:使用的是Xcode 8.2.1。没有这个打印问题!

图.plist设置.png

你可能感兴趣的:(iOS开发Xcode8的log输出“__nwlog_err_simulate_crash simulate crash failed "nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available”怎么办?)