XAML Spy 3
As of version 3, Xamarin iOS apps are first-class citizens in the XAML Spy world. All features previously available to Windows apps, are now available to iOS apps, including browsing the visual tree, exploring and editing visual properties at runtime, etc. XAML Spy supports Xamarin iOS apps build with the Unified API.
XAML Spy support for iOS targets developers that are using Windows to develop iOS apps, preferably using Visual Studio. XAML Spy integrates deeply with Visual Studio and provides a great user experience when spying iOS apps at runtime. See also the Visual Studio user guide to learn more about the features that XAML Spy brings to Visual Studio. The use of Visual Studio is not required, but highly recommended.
Xamarin iOS for Visual Studio allows iOS apps to be written and tested on Windows computers, with a networked Mac providing the build and deployment service. XAML Spy requires a Windows computer. When deploying an iOS app to the iOS simulator on a Mac, XAML Spy uses remote debugging to connect to the XAML Spy service running on the Windows computer. Make sure XAML Spy and the firewall are configured to allow remote debugging. See the remote debugging documentation for more details.
In order to spy an iOS app, a small XAML Spy client library needs to be referenced by the app. The client library includes a communication protocol for connectivity with the XAML Spy Windows service, and exposes a set of services that enables querying the app for a wide variety of data. Among others this includes read/write access to the live visual tree, and access to the full property set of any visual that is located in the user interface
To be discoverable by XAML Spy, the client library needs to connect to the XAML Spy Windows service on start of the app. In order to deliver a smooth and frictionless experience, setting up the connection is completely automated. Other than referencing the client library, there is no need to manually alter the app to enable XAML Spy.
The XAML Spy client library is distributed using the NuGet package XamlSpy. The NuGet package installs a MSBuild targets file, which automatically adds a reference to the XAML Spy client library when a debug build occurs. The targets file includes a task that locates the main entrypoint of the iOS app, and adds a piece of code to initiate XAML Spy functionality. Whenever XAML Spy is unable to locate or modify the entrypoint of an iOS, a build error will occur. If that's the case, you may need to resort to manually setting up the XAML Spy connection.
Next to modifying the entrypoint class, XAML Spy adds the custom assembly attribute PoweredByXamlSpy to the app. Adding this attribute allows for easy detection whether XAML Spy is enabled for an app, or not.
It is important to understand that XAML Spy does not modify the project, nor any of its source files. It does create temporary source files in the obj folder of your project, and instructs the compiler to include these files in the compilation process.
XAML Spy is configured to enable itself only when an app is build in debug mode. When building an app in release mode, XAML Spy is not enabled. Spying an app is typically used in a debug scenario, you would not want to deploy your app with XAML Spy enabled. Next to that, submitting an app to the store with XAML Spy included does violate the store policies, and will cause your app submission to be rejected.
Enabling XAML Spy by simply referencing a NuGet package covers most scenarios. For maximum flexibility, it is also possible to manually reference and bootstrap the XAML Spy client library. An in-depth explanation on how to achieve that can be found in the How to connect manually tutorial.