检查实时应用程序Inspecting Live Applications

Live app 检查适用于企业客户。Live app inspection is available for enterprise customers.

  1. 在 Visual Studio for Mac 或 Visual Studio 中打开任何受支持的应用项目Open any supported app project in Visual Studio for Mac or Visual Studio.
  2. 在调试模式下运行你的应用。Run your app in debug mode.
  3. 在 IDE 工具栏中单击 "检查" 按钮(在 Visual Studio 中,也可以从 "工具" 或 "调试" 菜单中查看 "检查当前应用 ... " 菜单项)。Click the Inspect button in the IDE toolbar (in Visual Studio, the Inspect current app... menu item is also available from the Tools or Debug menu).

将打开一个新的 Xamarin Inspector 客户端窗口,其中包含新的复制提示。A new Xamarin Inspector client window will open, with a fresh REPL prompt.

此窗口出现后,您将获得一个C#可用于执行和评估C#语句和表达式的交互式提示。Once this window appears, you have an interactive C# prompt that you can use to execute and evaluate C# statements and expressions. 这种情况的独特之处在于,在目标进程的上下文中计算代码。What makes this unique is that the code is evaluated in the context of the target process. 在这种情况下,我们将显示针对显示的 iOS 应用程序运行的代码。In this case, we are showing the code running against the iOS application displayed.

对应用程序状态所做的任何更改实际上都发生在目标进程中,因此可以使用C#来更改应用程序的实时运行,也可以检查应用程序的状态。Any changes that you make to the state of the application are actually happening on the target process, so you can use C# to change the application live, or you can inspect the state of the application live.

例如,在 iOS 上,我们可能要查找 UIApplication 委托类,这是我们的主驱动程序(我们在其中存储了大量应用程序状态):For example, on iOS, we might want to locate our UIApplication delegate class, which is our main driver (where we store a lot of the application state):

var del = (MyApp.AppDelegate) UIApplication.SharedApplication.Delegate
del.Database.GetAllCustomers ()
...
del.Database.AddCustomer (...)

(请注意,每次提交都会在多行编辑器中进行。(Note that each submission occurs in a multiline editor. Shift + Enter 将创建一个新行,并且 Cmd + Enter (在 Windows 上Ctrl + Enter)将提交用于计算的代码。Shift + Enter will create a new line, and Cmd + Enter (Ctrl + Enter on Windows) will submit the code for evaluation. Enter 在安全时自动提交。)Enter automatically submits when it is safe.)

若要获取应用程序的可视元素,更方便的方法是使用 "检查" 按钮。A more convenient way to get to the visual elements of your application is by using the "Inspect" button. 按下后,可以通过单击应用程序来选择 UI 元素。Once you press this, you can select a UI element by clicking on your application. 变量 selectedView 将被分配为指向屏幕上的实际元素。The variable selectedView will be assigned to point to the actual element on the screen. 在上面的屏幕截图中,你可以看到我们如何访问并编辑所选 UISearchBar 上的 selectedView.BarTintColorIn the screenshot above, you can see how we accessed and then edited selectedView.BarTintColor on the UISearchBar we had selected.

实时可视化树也非常有用。The live visual tree is also very useful. 它表示视图层次结构的当前快照。It represents the current snapshot of your view hierarchy. 您可以选择要在复制中设置 selectedView 的行,并查看视图的属性值。You can select rows to set selectedView in the REPL and to see the view's property values. 在 Mac 上,可以与分层视图的3D 分离型可视化对象进行交互。On Mac, you can interact with a 3D exploded visualization of the layered views. 在 Windows 上,您可以直观地编辑视图的属性值。On Windows, you can edit a view's property values visually.

已知限制Known Limitations

  • 仅在主显示器上支持 "视图选择"。View selection is only supported on your main display.
  • 属性网格编辑不适用于 Mac,在 Windows 上仅限于几种数据类型。Property grid editing is not available for Mac, and on Windows is limited to a few data types. 使用复制功能进行更强大的编辑。Use the REPL for more powerful editing.
  • 只要在 IDE 中安装并启用了检查器外接程序,我们就会在应用程序在调试模式下启动时将代码注入到您的应用程序中。As long as the Inspector addin/extension is installed and enabled in your IDE, we are injecting code into your app every time it starts in Debug mode. 如果你在应用中发现任何异常行为,请尝试禁用或卸载检查器外接程序/扩展,然后重启 IDE 和重新检查。If you notice any strange behavior in your app, please try disabling or uninstalling the Inspector addin/extension, restarting the IDE, and rechecking. 并请提出错误,告诉我们!And please file bugs to let us know!
  • 如果检查 UI 元素使其不会发生更改,请告知我们,因为这可能表示存在 bug。If inspecting a UI element causes it to change in anyway, please let us know, as this may indicate a bug.