简体   繁体   English

如何在 Xcode 6 (iOS 8) 模拟器上使用 Charles Proxy?

[英]How to use Charles Proxy on the Xcode 6 (iOS 8) Simulator?

It seems that the directory for the iOS Simulator has changed. iOS 模拟器的目录似乎已更改。 It used to be in ~/Library/Application\\ Support/iPhone\\ Simulator/ and now it's in ~/Library/Developer/CoreSimulator/Devices/ .它曾经在~/Library/Application\\ Support/iPhone\\ Simulator/ ,现在在~/Library/Developer/CoreSimulator/Devices/

Update: Charles 3.9.3+ has a built-in function to configure your iOS Simulators (ie installing the Charles SSL Certificate).更新: Charles 3.9.3+有一个内置功能来配置你的 iOS 模拟器(即安装 Charles SSL 证书)。 This can be found in the Help menu within the Charles application.这可以在 Charles 应用程序的帮助菜单中找到。 ( Help > SSL Proxying > Install Charles Root Certificate in iOS Simulators ) Help > SSL Proxying > Install Charles Root Certificate in iOS Simulators

The following applies to Charles 3.9.2:以下适用于 Charles 3.9.2:

Download the configuration shell script from the Charles Proxy website .Charles Proxy 网站下载配置 shell 脚本 Then, replace the script with the following, and run it on your Mac:然后,将脚本替换为以下内容,并在您的 Mac 上运行它:

#/bin/bash
install() {
if [ -f "$SQLITEDBPATH" ]; then
cp -n "$SQLITEDBPATH" "$SQLITEDBPATH.charlesbackup"
sqlite3 "$SQLITEDBPATH" <<EOF
INSERT INTO "tsettings" VALUES(X'189B6E28D1635F3A8325E1E002180DBA2C02C241',X'3123302106035504030C1A436861726C65732050726F78792053534C2050726F7879696E6731243022060355040B0C1B687474703A2F2F636861726C657370726F78792E636F6D2F73736C3111300F060355040A0C08584B3732204C74643111300F06035504070C084175636B6C616E643111300F06035504080C084175636B6C616E64310B3009060355040613024E5A',X'3C3F786D6C2076657273696F6E3D22312E302220656E636F64696E673D225554462D38223F3E0A3C21444F435459504520706C697374205055424C494320222D2F2F4170706C652F2F44544420504C49535420312E302F2F454E222022687474703A2F2F7777772E6170706C652E636F6D2F445444732F50726F70657274794C6973742D312E302E647464223E0A3C706C6973742076657273696F6E3D22312E30223E0A3C61727261792F3E0A3C2F706C6973743E0A',X'3082045E30820346A003020102020101300D06092A864886F70D01010505003081913123302106035504030C1A436861726C65732050726F78792053534C2050726F7879696E6731243022060355040B0C1B687474703A2F2F636861726C657370726F78792E636F6D2F73736C3111300F060355040A0C08584B3732204C74643111300F06035504070C084175636B6C616E643111300F06035504080C084175636B6C616E64310B3009060355040613024E5A3020180F31383939313233313132303030305A170D3338303932343033313930355A3081913123302106035504030C1A436861726C65732050726F78792053534C2050726F7879696E6731243022060355040B0C1B687474703A2F2F636861726C657370726F78792E636F6D2F73736C3111300F060355040A0C08584B3732204C74643111300F06035504070C084175636B6C616E643111300F06035504080C084175636B6C616E64310B3009060355040613024E5A30820122300D06092A864886F70D01010105000382010F003082010A02820101008349587455EFB272E397A31D3B52D9B13115C93F320766D2D451117F45C40285506027079ED439CABB94D44F1AE136EB1E79BF77ABE43345AD1D436809CF9E035C439272F3CA917DCADD7FBD0E3929F1A345F0B89096130BBD116F8D3AB5655789B7B0831325BD22903F198DA6BDDA30C08DFD17CE9AB51C48555264307BCF789A2B6C48DF4ECAF3EA2C092EE737AD8F397900AC03303BFE2AE43549030A7866CB6FE9B04B9F6EC498B4E7369E99B45491BF093858A77C72F8ADC818E018D413265E39446BE514F78EB57A23AA88F630776F861A9163E04AD38EE8A5C9219D0FC23F6B9A6324455DEA6F4A6A251ECA1FA3D6288CB89FD12A2062A3A015A56F250203010001A381BC3081B9300F0603551D130101FF040530030101FF307706096086480186F842010D046A136853534C2050726F7879696E6720697320656E61626C656420696E20436861726C65732050726F78792E20506C6561736520766973697420687474703A2F2F636861726C657370726F78792E636F6D2F73736C20666F72206D6F726520696E666F726D6174696F6E2E300E0603551D0F0101FF040403020204301D0603551D0E04160414BB27F4CB2EB6DBB058101BBD803F38D208D76129300D06092A864886F70D010105050003820101000041F935F30B209E56360F7E3D9C30314A213323C47EDCEA1467600A50FFE4E8E39DFCA8C8D34463C34745FF04C870F1DF28BB772DB0CF1BCA677B70842C742BC6D5FB00559AD643C6BF2C95BD0B855A961D7D6A3EADA9C642E9A789474C4AD838C6F732D8D859548D30829DF7A32D098FE3F00147DAF08C0B37DD597184C1E27A61EA42050C73994E809013CB21E37BF84BF923BCEFEA6164FD28AB9058CCC48F1F486FC1C47EBD8A9C933F542401B11F36A003E47B141A41C7B326D18D023E11EDB445699AA44800254EA33F174FD5EB1CCCE6A09365751FF905988C06315B5575067BF65EC24CAD1A6A601846D1D2F51F1F420A2762990B044000619D1C84');
EOF
fi
}

for SQLITEDBPATH in ~/Library/Developer/CoreSimulator/Devices/*/data/Library/Keychains/TrustStore.sqlite3; do
    echo $SQLITEDBPATH
    install
done

echo "The Charles SSL CA Certificate has been installed for the iPhone Simulator"

Some things to note:一些注意事项:

  • you must open Charles before launching the simulator.您必须在启动模拟器之前打开 Charles。 If you close Charles, network requests will fail until you restart the simulator如果关闭 Charles,网络请求将失败,直到您重新启动模拟器
  • you will need to do this every time you "Reset Content and Settings..." on the simulator每次在模拟器上“重置内容和设置...”时都需要执行此操作
  • For Xcode 5: if you're looking to setup Charles Proxy on Xcode 5 and earlier, you don't need to modify the original script.对于 Xcode 5:如果您希望在 Xcode 5 及更早版本上设置 Charles Proxy,则无需修改原始脚本。 Just download it from the Charles website and run it as-is只需从 Charles 网站下载并按原样运行即可

I just tested Charles over Xcode 7 / iOS9 simulator.我刚刚通过 Xcode 7 / iOS9 模拟器测试了 Charles。 Just a few pointers I want to add if you're having trouble:如果您遇到问题,我想补充几点:

  • Make sure " Enable Mac OS proxy " and " Use HTTP Proxy " are checked under Charles' Proxy |确保在 Charles' 代理下选中“启用 Mac OS 代理”和“使用 HTTP 代理” | Proxy Settings;代理设置; and optionally check " Enable Mac OS X proxy at startup " if you don't want to do this step every time you start Charles.如果您不想在每次启动 Charles 时都执行此步骤,还可以选择选中“启动时启用 Mac OS X 代理”。
  • If your Automatic Proxy Configuration (and/or Auto Proxy Discovery ) is set in your System Preferences |如果您的自动代理配置(和/或自动代理发现)设置在您的系统偏好设置 | Network, you need to uncheck it lest Charles' Web Proxy (HTTP) and Secure Web Proxy (HTTPS) will not take effect.网络,您需要取消选中它以免 Charles 的 Web 代理 (HTTP) 和安全 Web 代理 (HTTPS) 不会生效。
  • If your company requires proxy server independent of Charles, you need to manually replicate the settings inside Charles lest they are overridden by Charles and you won't be able to access the internet.如果您的公司需要独立于 Charles 的代理服务器,您需要手动复制 Charles 内部的设置,以免它们被 Charles 覆盖而您将无法访问互联网。 Make note of the proxy URL and port numbers before starting Charles.在启动 Charles 之前记下代理 URL 和端口号。 Transcribe these Web Proxy and Secure Web Proxy settings under Charles' Proxy |在 Charles' Proxy 下转录这些Web 代理安全 Web 代理设置 | External Proxy Settings.外部代理设置。
  • " Enable SSL Proxying " and add your endpoint on the list, via Charles' Proxy | 启用 SSL 代理”并通过 Charles 的代理将您的端点添加到列表中 | SSL Proxying Settings. SSL 代理设置。
  • " Install Charles Root Certificate in iOS Simulator " via Charles' Help | 在 iOS 模拟器中安装 Charles 根证书”通过 Charles 的帮助 | SSL Proxying menu. SSL 代理菜单。
  • And yeah, make sure Charles is setup and started first before you start the simulator.是的,请确保在启动模拟器之前先设置并启动 Charles。
  • Finally for now, disable ATS during development until we hear more from Apple.最后,在开发过程中禁用 ATS,直到我们听到更多来自 Apple 的消息。

According to charles documentation根据查尔斯文件

The iOS Simulator should use the system proxy settings. iOS 模拟器应使用系统代理设置。 If it doesn't, please try quitting and restarting the iOS Simulator.如果没有,请尝试退出并重新启动 iOS 模拟器。 As of Xcode 6 it appears to be important that Charles is running and set as the Mac OS X system proxy before you run the iOS Simulator.从 Xcode 6 开始,在运行 iOS 模拟器之前,Charles 正在运行并设置为 Mac OS X 系统代理似乎很重要。

Read Here 在这里阅读

So just quit your simulator, open charles and then run the app again.所以只需退出你的模拟器,打开查尔斯,然后再次运行应用程序。 After that you can track your network calls.之后,您可以跟踪您的网络呼叫。

NOTE: Your network calls will fail if you quit Charles.注意:如果您退出 Charles,您的网络呼叫将失败。 So you will need to either quit the simulator and run it again or open Charles again.因此,您需要退出模拟器并再次运行它或再次打开 Charles。

Another way to do it is to browse to the certificate http://charlesproxy.com/charles.crt on the device另一种方法是浏览到设备上的证书http://charlesproxy.com/charles.crt

which will present you with the screen:这将向您展示屏幕:

安装证书提示屏幕

Update for iOS 9: You have to disable App Transport Security to use Charles! iOS 9 更新:您必须禁用 App Transport Security 才能使用 Charles!

http://www.charlesproxy.com/documentation/using-charles/ssl-certificates/ http://www.charlesproxy.com/documentation/using-charles/ssl-certificates/

I didnt see the configuration shell script on that page.我没有在该页面上看到配置 shell 脚本。 I did the following and it worked for me:我做了以下工作,它对我有用:

http://raptureinvenice.com/getting-the-charles-debugging-proxy-to-work-with-ios-and-genymotion/ http://raptureinvenice.com/getting-the-charles-debugging-proxy-to-work-with-ios-and-genymotion/

Check this out:看一下这个:

As of Charles v3.9.3 there is an item in the Help menu, "Install Charles CA SSL Certificate in iOS Simulators", which will automatically install Charles's SSL CA certificate in your iOS Simulators.从 Charles v3.9.3 开始,帮助菜单中有一项“在 iOS 模拟器中安装 Charles CA SSL 证书”,它将自动在您的 iOS 模拟器中安装 Charles 的 SSL CA 证书。

Alternatively, you can change your code so that NSURLConnection accepts any SSL certificate.或者,您可以更改您的代码,以便 NSURLConnection 接受任何 SSL 证书。 Please see the question and answer on Stack Overflow: How to use NSURLConnection to connect with SSL for an untrusted cert?请参阅 Stack Overflow 上的问答: How to use NSURLConnection to connect with SSL for an untrusted cert?

You can check it on this link: http://www.charlesproxy.com/documentation/faqs/ssl-connections-from-within-iphone-applications/您可以在此链接上查看: http : //www.charlesproxy.com/documentation/faqs/ssl-connections-from-within-iphone-applications/

The 'Install Charles Root Certificate in iOS simulators' does not work in the current version of CharlesProxy (3.11) with Xcode 7 / iOS 9 simulators. “在 iOS 模拟器中安装 Charles 根证书”在当前版本的 CharlesProxy (3.11) 和 Xcode 7 / iOS 9 模拟器中不起作用。

Instead, use the 'Install Charles Root Certificate on a Mobile Device or Remote Browser...' option.相反,请使用“在移动设备或远程浏览器上安装 Charles 根证书...”选项。 This will give you a url for the certificate.这将为您提供证书的 URL。

If you open this url in Safari in the simulator, you will then be given the option to install the certificate.如果您在模拟器中的 Safari 中打开此 url,您将获得安装证书的选项。

You still then need to disable app transport security.然后您仍然需要禁用应用程序传输安全。 I don't understand why this is necessary when you have the certificate installed;我不明白为什么当你安装了证书时这是必要的; I guess CharlesProxy does not use sufficiently large keys/signatures.我猜 CharlesProxy 没有使用足够大的密钥/签名。

Steps for iOS simulator. iOS模拟器的步骤。

  • Install Charles - download安装 Charles -下载
  • Charles Menu -> Proxy -> Enable Mac Proxy Charles 菜单 -> 代理 ->启用 Mac 代理
  • Charles Menu -> Tools -> Proxy -> Proxy Settings -> MacOS -> Check all the check boxes Charles Menu -> Tools -> Proxy -> Proxy Settings -> MacOS -> 勾选所有复选框
  • Install Charles Certificate in iOS simulators在 iOS 模拟器中安装 Charles 证书
  • Charles Menu -> Help -> SSL Proxying -> Install Charles Ceritificate in iOS Simulators Charles 菜单 -> 帮助 -> SSL 代理 -> 在 iOS 模拟器中安装 Charles 证书
  • Enable Charles Certificate in iOS Simulators在 iOS 模拟器中启用 Charles 证书
  • iOS Simulators Setttings -> General -> About -> Certificate Trust Settings -> Switch On iOS 模拟器设置 -> 常规 -> 关于 -> 证书信任设置 ->开启
  • If traffic does not appear, Run Charles before simulator如果没有出现流量,在模拟器之前运行Charles

Steps for iPhone/iPad. iPhone/iPad 的步骤。

  • Open desktop Charles app (Mac/Windows)打开桌面 Charles 应用程序 (Mac/Windows)
  • Goto Charles Menu -> Help -> SSL Proxying -> Install Charles Ceritificate on a Mobile device or Remote browser -> Select -> popup appear with below steps `转到 Charles 菜单 -> 帮助 -> SSL 代理 -> 在移动设备或远程浏览器上安装 Charles 证书 -> 选择 -> 出现以下步骤的弹出窗口 `

    Configure your device to use Charles as its HTTP Proxy on 192.168.0.100:8888 , then browser to chls.pro/ssl to download and install the certificate.将您的设备配置为在192.168.0.100:8888上使用 Charles 作为其 HTTP 代理,然后浏览器到chls.pro/ssl下载并安装证书。

  • Goto iPhone settings -> Wifi -> click selected wifi -> Http proxy -> Configure proxy -> select Manual -> Give server as 192.168.0.100 and port as 8888 -> Save转到 iPhone 设置 -> Wifi -> 单击选定的 wifi -> Http 代理 -> 配置代理 -> 选择手动-> 将服务器设置为 192.168.0.100 并将端口设置为 8888 ->保存

  • Goto iPhone browser -> Load chls.pro/ssl -> It will show below popup `转到 iPhone 浏览器 -> 加载chls.pro/ssl -> 它将显示在弹出窗口下方`

    The website is trying to download a configuration profile.该网站正在尝试下载配置文件。 Do you want to allow this?你想允许吗? Ignore button and Allow button忽略按钮和允许按钮

  • Click Allow button -> It will download the profile单击“允许”按钮 -> 它将下载配置文件

  • Goto iPhone Settings -> General -> Profiles -> Downloaded Profile -> Select the Charles Proxy profile -> Install转到 iPhone 设置 -> 常规 -> 配置文件 -> 下载的配置文件 -> 选择 Charles 代理配置文件 ->安装
  • Goto iPhone Settings -> General -> About -> Certificate Trust Settings -> Enable - Charles Proxy CA certificate转到 iPhone 设置 -> 常规 -> 关于 -> 证书信任设置 ->启用- Charles 代理 CA 证书
  • Now we can track the iPhone app calls in desktop Charles app现在我们可以在桌面 Charles 应用程序中跟踪 iPhone 应用程序调用

在 Charles 开始为我修复它之后(重新)启动模拟器。

For those who struggling with untrusted connections on Xcode 9 beta's simulators:对于那些在 Xcode 9 beta 模拟器上遇到不受信任的连接问题的人:

I don't know if install script works or not but you are able to install charles' cert in same way as on physical device - through Safari.我不知道安装脚本是否有效,但您可以通过 Safari 以与在物理设备上相同的方式安装查尔斯的证书。

Last step that is needed (of course after installing certificate either through script or via Safari): Go to Simluator's settings -> general -> about -> Certificate trust settings -> Charles Proxy Custom Root... -> enable 💥需要的最后一步(当然在通过脚本或通过 Safari 安装证书之后):转到 Simluator 的设置 -> 常规 -> 关于 -> 证书信任设置 -> Charles Proxy Custom Root... -> 启用 💥

To me, this is what worked.对我来说,这就是有效的。

I did same thing as we do in device.我做了和我们在设备中做的一样的事情。

  1. Open safari and browse chls.pro/ssl打开 safari 并浏览 chls.pro/ssl
  2. Accept and install the certificate接受并安装证书
  3. Go to Settings/About/Trust certificates and trust the charles certificate.转到设置/关于/信任证书并信任查尔斯证书。

I have to do this on 3 simulator instances, as XCUI automation testing can spin 3.我必须在 3 个模拟器实例上执行此操作,因为 XCUI 自动化测试可以旋转 3 个。

It works for me after go to safari (simulator) and visit the URL:转到 safari(模拟器)并访问 URL 后,它对我有用:

chls.pro/ssl 

Before I had to Install charles root certificate in iOS simulators (Charles: help/SSLproxying)在我不得不在 iOS 模拟器中安装查尔斯根证书之前(查尔斯:帮助/SSLproxying)

regards问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM