如何确定App Transport Security正在阻止哪个URL? [英] How can I figure out which URL is being blocked by App Transport Security?
问题描述
我正在将iOS应用升级到iOS 9,并且我有一些不安全的网址,我需要一些App Transport Security的例外。我添加了我所知道的两个,但现在有一些警告说明:
I'm upgrading an iOS app to iOS 9, and I have some URLs that are not secure, and I need a few exceptions to App Transport Security. I've added the two that I know about, but there are some warnings happening now stating:
App Transport Security阻止了一个明文HTTP (http://)资源加载,因为它不安全。可以通过应用程序的Info.plist文件配置临时例外。
App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
我需要知道哪些URL被阻止,所以我可以添加它们到Info.plist,它们可能是图像或媒体文件。如何让系统记录决定不加载的URL?
I need to know what URLs are being blocked so I can add them to the Info.plist, they're probably images or media files. How can I make the system log the URLs it decided not to load?
推荐答案
编辑注释: @jessedc在下面的评论中指出Apple官方文档的链接如何执行此操作: https://developer.apple.com/library/content/qa/qa1887/_index.html
Editor Note: @jessedc points out in the comments below the link to the official Apple documentation on how to do this: https://developer.apple.com/library/content/qa/qa1887/_index.html
好的,我有一个答案我不喜欢!我仍然非常想要一个更好的。
Okay, I have an answer I don't like! I still very much want a better one.
在我的应用程序中:didFinishLaunchingWithOptions:
方法我添加了行
setenv("CFNETWORK_DIAGNOSTICS", "3", 1);
当我运行应用程序时,在日志中我可以找到如下所示的条目:
When I ran the app then, in the log I can find an entry that looks like this:
2015-07-02 15:27:56.152 MyApp[45041:9125662] CFNetwork diagnostics log file
created at: /Users/micah.hainline/Library/Developer/CoreSimulator/Devices/
11BCA581-5F5F-494D-932A-2ECFCA33EA93/data/Containers/Data/Application/
9ACC6941-8039-4B86-B5E8-A6C66E2AD520/Library/Logs/CrashReporter/CFNetwork_com
.myapp.MyApp_45041.nwlrb.log
我打开那个文件,我有大量的日志条目,关于网络上发生的一切。我在该文件中搜索 kCFErrorDomainCFNetwork
并获取失败网络请求的日志。我可以使用它来查看系统尝试访问的URL,然后可以将该URL添加到App Transport Security的例外中。
When I open that file I have a huge number of log entries about everything that's happened on the network. I search for kCFErrorDomainCFNetwork
in that file and get logs for failed network requests. I can use that to see what URLs the system was trying to hit, and then can add that URL to the exceptions for App Transport Security.
这篇关于如何确定App Transport Security正在阻止哪个URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!