How to debug a Xamarin.iOS app on a physical iOS device
Asked Answered
A

2

13

Apologies, in advance, for this long question, but I have wasted 3 days unsuccessfully trying to set up a Xamarin.iOS development environment that allows me to debug on a physical device (not an iPhone simulator) and I am at a loss for what to try next.

I believe my setup is quite a standard Xamarin configuration:

  • Windows 10 PC running Visual Studio 2015 and Xamarin v4.2.0.703
  • HTC phone USB-connected to the PC for Android debugging (works fine)
  • MacBook running OS X 10.11 with Xamarin Studio v6.1.1 and Xcode v8.0
  • iPhone or iPad USB-connected to the Mac for iOS debugging

I started by creating a Xamarin solution in Visual Studio, which I initially developed and debugged on Android.

To progress to iOS debugging I then set up the Mac with Xcode and Xamarin Studio, enabled it for remote login, and created a dummy Xcode project with the same bundle identifier as my Xamarin.iOS app. I also made an attempt at the rather complicated process of creating a signing identity and provisioning profile for the app, and downloading / installing them on the Mac. This process is so unintuitive (and the visual feedback within Xcode is so poor) that I am not certain that I have done it correctly. However, I am able to run the dummy Xcode project on the iPhone, so I assume it must be OK?

On the Windows PC, the Xamarin > iOS Options pane within Visual Studio settings confirms that Visual Studio is connected to the Mac and the attached iPhone is also listed as a candidate target device, so it seems that everything is set up for on-device debugging.

If I try to debug the app on the iPhone simulator from Visual Studio, it works correctly. However, debugging on the physical iPhone fails with the following unhelpful message:

Xamarin.Messaging.Exceptions.MonotouchException: error MT1006: Could not install the
application '/Users/Tim/Library/Caches/Xamarin/mtbs/builds/Test.iOS/c4f40041b6c58fc579a727bccfc18614/bin/iPhoneSimulator/Debug/TestiOS.app' 
on the device 'Tim’s iPhone': AMDeviceSecureInstallApplicationBundle returned: 0xe8008001.

As a comparison, I also tried debugging directly on the Mac, using Xamarin Studio. Again, the iPhone simulator works OK, but it is impossible to even launch a debug session using the physical device, because the connected iPhone is not listed as a candidate target device for the Debug | iPhone configuration.

If I open project options and navigate to the iOS Debug view, I can see that the platform associated with the Debug configuration is iPhoneSimulator. Changing it to iPhone and saving the configuration it appears work, but the changes are not actually saved. I guess this is the reason my test device is not listed, but I am unclear what I need to do to get Xamarin Studio to accept my changes.

So, after all this experimentation, I am completely lost. It would be helpful to have a complete, robust A-Z tutorial for this setup process but, failing that, any suggestions what I should try next would be very much appreciated.

UPDATE: If I use the Ad-Hoc project configuration (in either Visual Studio or Xamarin Studio) it correctly deploys and launches the app on the device, but doesn't attach the debugger. If I explicitly enable debugging in the Ad-Hoc project configuration, Xamarin Studio ignores it, but Visual Studio then attaches the debugger but doesn't hit any breakpoints. Does this all sound right? Does it offer any clues what I need to change to get the real Debug config to work correctly?

Antiphlogistic answered 21/10, 2016 at 9:57 Comment(4)
It does not sound like you have provisioned your iPhone/iPad: developer.xamarin.com/guides/ios/getting_started/installation/…Hagan
@SushiHangover: Thanks. Using Xcode > Window > Devices, I just checked that there is a provisioning profile installed on the iPhone. I cross-checked the installed profile in my Apple account and it includes my development signing ID and lists 3 devices, one of which is the iPhone that I am trying to debug on.Antiphlogistic
Strange.... We have a pile of Androids that do not work with Xamarin's debugger (but do w/ A.S.), but never had an iOS issue if they are provisioned. What iOS versions are on the iDevices (10?)?Hagan
iPhone 4 with iOS 9.3 and iPhone 5 and 6+ with iOS 10.Antiphlogistic
A
1

For anyone facing a similar problem, the solution that I eventually adopted entailed a 'brute force' approach.

I started by creating a new Xamarin.Forms solution (using the standard Visual Studio template) and removing the unwanted platform projects (UWP and Windows Phone). In this initial state, I verified that it was able to launch debugging on both Android and iOS devices, as well as their respective emulators/simulators. Everything worked correctly, confirming that my Mac setup was correct and also providing me with the exact iOS project configuration that is required for debugging.

At this point, I assumed that a configuration problem must be responsible for my earlier problems, so I exactly replicated every detail of the working configuration in my original solution. Still it refused to debug on iOS.

I then started to suspect that a referenced Nuget package was causing the problem, so I added all of the referenced packages from the original implementation into the new test solution. I expected this to break debugging on iOS, but it didn't.

Finally, I carefully transplanted the entire contents of my original solution (XAML & code-behind files, view models, resources, etc) into the test solution and it continued to debug correctly.

So, in the absence of a viable diagnostic procedure, I effectively solved the problem by rebuilding my solution from the ground up. No code was changed and, to my knowledge, no configuration settings were changed, but the new implementation is now reliably debuggable in all target environments.

Antiphlogistic answered 24/10, 2016 at 15:5 Comment(2)
You might need to set provisioning profile in VS manually in properties of the IOS project, in the iOS Bundle Signing section as described in the following article: developer.xamarin.com/guides/ios/getting_started/installation/… (it's the 10 step)Antlia
FWIW, I had this same problem and "solution" on Android. So maybe a Xamarin thing rather than an iOS/Android thing?Overcompensation
T
3

It is possible, as stated in the documentation: https://developer.xamarin.com/guides/ios/getting_started/installation/device_provisioning/free-provisioning/

(Sorry, I just thought that the current accepted answer fits more to a troubleshooting page, rather than the generic case.)

Triplex answered 17/1, 2021 at 13:0 Comment(0)
A
1

For anyone facing a similar problem, the solution that I eventually adopted entailed a 'brute force' approach.

I started by creating a new Xamarin.Forms solution (using the standard Visual Studio template) and removing the unwanted platform projects (UWP and Windows Phone). In this initial state, I verified that it was able to launch debugging on both Android and iOS devices, as well as their respective emulators/simulators. Everything worked correctly, confirming that my Mac setup was correct and also providing me with the exact iOS project configuration that is required for debugging.

At this point, I assumed that a configuration problem must be responsible for my earlier problems, so I exactly replicated every detail of the working configuration in my original solution. Still it refused to debug on iOS.

I then started to suspect that a referenced Nuget package was causing the problem, so I added all of the referenced packages from the original implementation into the new test solution. I expected this to break debugging on iOS, but it didn't.

Finally, I carefully transplanted the entire contents of my original solution (XAML & code-behind files, view models, resources, etc) into the test solution and it continued to debug correctly.

So, in the absence of a viable diagnostic procedure, I effectively solved the problem by rebuilding my solution from the ground up. No code was changed and, to my knowledge, no configuration settings were changed, but the new implementation is now reliably debuggable in all target environments.

Antiphlogistic answered 24/10, 2016 at 15:5 Comment(2)
You might need to set provisioning profile in VS manually in properties of the IOS project, in the iOS Bundle Signing section as described in the following article: developer.xamarin.com/guides/ios/getting_started/installation/… (it's the 10 step)Antlia
FWIW, I had this same problem and "solution" on Android. So maybe a Xamarin thing rather than an iOS/Android thing?Overcompensation

© 2022 - 2024 — McMap. All rights reserved.