iOS12 + CFNetwork Diagnostic Logging

I had an app that used an UIWebView in iOS 11, and had the following Environmet Variables for debugging networks conections.


Product > Sceheme > Edit Scheme > Environmet Variables > CFNETWORK_DIAGNOSTICS 3


In iOS 12, UIWebView is deprecated so I changed it for an WKWebView.


Now, I can't see any logs in the console about the networks conections.


Is it CFNetwork Diagnostic still available in iOS12?

Answered by DTS Engineer in 333654022

I will install again XCode 9.4.1 to have available the use of

UIWebView
until I find a different approach.

You don’t have to do that. While

UIWebView
is deprecated in the iOS 10 SDK, it still works just fine. There’s absolutely no reason you can’t continue to use
UIWebView
with Xcode 10 and the OSes it supports.

Having said that, if there’s a specific feature that’s missing from

WKWebView
, like the ability to get nice logging, I strongly encourage you to file an enhancement request describing your requirements. In the long term
UIWebView
will be completely supplanted by
WKWebView
, and it’s important that we learn about any missing features before that.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Is it CFNetwork Diagnostic still available in iOS12?

Yes.

Is your specific complaint that it has an effect on

UIWebView
but not
WKWebView
? If so, that’s expected.
WKWebView
does all of its networking in a separate process, and thus is not affected by your environment variables.

In many cases you can get the same effect by hooking your iOS device up to your Mac via USB and using the Console app to look at the iOS device’s system log. I’m not sure how much of the standard CFNetwork diagnostic info that shows, but it’s worth a shot.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thank you for your answer eskimo,



In Xcode 9.4.1 and iOS 11.4, using UIWebView, even in simulator, CFNETWORK_DIAGNOSTICS provides useful verbose information.


Unfortunately, the Console app hooking the iOS device up to the Mac via USB, do not provide any useful system log about about networks connections, just the WKNavigationDelegate protocol methods.


I also tried to use SFSafariViewController with CFNETWORK_DIAGNOSTICS, but I get the following error:


Failed to get remote view controller with error: Error Domain=NSCocoaErrorDomain Code=4097 "Couldn’t communicate with a helper application."


I watched the WWDC 2018 Session 234 Whats new in Safari and Webkit.


In this session, they talked about what you said:


“WKWebView also runs in a completely separate process from the rest of your app.


So, unlike UIWebView, even if your web process is compromised, it won't compromise your app.


If your web view has complex content, you can't accidentally cause your app to stall.


And, even if WKWebView crashes, it's confined to the web view, not the app.


WKWebView can provide security benefits while keeping your apps performant and reliable.”



But I am not sure about this process separation, I found on internet a post called " How to force restart any iOS device with just CSS",


that made any iOS device restart using a WKWebView loading simple HTML, even with iOS12.


I would like to have the same kind of logs that was previously available, so I will install again XCode 9.4.1 to have available the use of UIWebView until I find a different approach.

Accepted Answer

I will install again XCode 9.4.1 to have available the use of

UIWebView
until I find a different approach.

You don’t have to do that. While

UIWebView
is deprecated in the iOS 10 SDK, it still works just fine. There’s absolutely no reason you can’t continue to use
UIWebView
with Xcode 10 and the OSes it supports.

Having said that, if there’s a specific feature that’s missing from

WKWebView
, like the ability to get nice logging, I strongly encourage you to file an enhancement request describing your requirements. In the long term
UIWebView
will be completely supplanted by
WKWebView
, and it’s important that we learn about any missing features before that.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks eskimo, I followed your advice, the bug number is 44941207.

the bug number is 44941207.

Thanks.

One other thing that I forgot to mention is that all of our web views support the Web Inspector. When I work with web views I find that to be a much nicer experience than grovelling through CFNetwork diagnostic logs. Have you played around with Web Inspector? If not, give it a whirl!

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

You are right, in my case I found what I was looking for in SAFARI > Web Inspector (RESOURCES TAB).


But to make it works, I need to change from the url that I found there all the ocurrences of \/ to / to make it works.


Thanks again, I also liked the CFNetwork diagnostic logs. 🙂

iOS12 + CFNetwork Diagnostic Logging
 
 
Q