Xamarin.Forms: Debug on iPhoneSimulator

1.3k views Asked by At

I'm trying to debug a simple new Xamarin.Forms application on the IPhoneSimulator. I'm using Windows, and I'm paired to a macbook in my network.

The Xamarin.Forms template runs fine, but when I'm calling the Xamarin.Essentials.SecureStorage API

var timer = new Timer(5000);
timer.Elapsed += async (sender, e) => {
    timer.Stop();
    await SecureStorage.SetAsync("message", "Hello world");
};

I'm getting the following error:

System.Exception: Error adding record: MissingEntitlement

So I edit my Entitlements.plist and enabled the KeyChain entitlement. Tried to debug again, still the same error. So I go to project properties > iOS Bundle Signing and set the Custom entitlements to my Entitlements.plist. This somehow switches the scheme to Manual Provisioning.

Could not find any available provisioning profiles for MyApplication.iOS on iOS

So I did what this answer said: https://stackoverflow.com/a/51615262/8941307. Now I'm still getting the MissingEntitlement exception.

When I remove the Custom Entitlements and switch back to Automatic Provisioning, I'm able to run the app again, but off course without the SecureStorage.

Do I need to have a $ 99 subscription to test these features like SecureStorage on the IPhoneSimulator? Would this work when using a physical iPhone?

EDIT

I'm able to debug the sample project from XCode from my macbook on my iPad (physical), but apparently I can't get it working with Visual Studio for Mac on my iPad. I'm getting the following error:

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(3,3): Error: Could not find any available provisioning profiles for Helloworld.iOS on iOS.

What am I still missing in VSMac? Also I already trusted my developer account on my iPad, hence why I'm able to run the sample from XCode.

I've used XCode 12.1, located at /Applications/Xcode.app

2

There are 2 answers

3
Lucas Zhang On BEST ANSWER

You could create a free Apple Account for testing .

1. Sign into Xcode with personal apple account

  1. Start Xcode on your Mac
  2. Choose the Xcode → Preferences menu and navigate to the Account pane
  3. Click the +-button in the bottom-left corner and choose Apple ID
  4. Log in with your Apple ID email address and password .

You now have access to your Developer Account in Xcode . The developer account you added is called “Personal Team”, which should show up in the list on the right.

2. Run Apps on real device

Make sure your iPhone (or iPad) is connected to your Mac via USB. When your iPhone prompts you to confirm connecting to your Mac, tap Trust.

Then, in Xcode, choose the Window → Devices and Simulators menu. Select your iPhone from the list, and then click the Enable Device for Development button. (Depending on the context, this may not be a necessary step.) It’s also smart to enable the Connect via network option, which lets you debug apps on your iPhone without connecting via USB.

Now you can test your code with Auto Provisioning both on simulator and real device .

0
Pieterjan On

Very weird, but I played around with the settings of my project.

I followed the instructions in the following link: https://learn.microsoft.com/nl-be/xamarin/ios/get-started/installation/device-provisioning/free-provisioning?tabs=windows#limitations. This ensures that an app is deployed on your ipad, using XCode, with the same app-id you'll eventually use in Visual Studio. You need to have the same Bundle Identifier as the one you'll eventually use in Xamarin.iOS.

After this, I've used the following settings in my iOS project:

iOS Bundle Signing settings Visual Studio

According to this link I also ensured I am signed in. After this, I had to restart my Visual Studio For Windows, and I was able to debug on my iPad from my PC.