35

I'm using Xamarin.Auth (https://components.xamarin.com/view/xamarin.auth/) to store my credentials, as I've always done.

var accountStore = AccountStore.Create ();
foreach (var account in  accountStore.FindAccountsForService("myAppName"))
    accountStore.Delete (account, "myAppName");

AccountStore.Create().Save(acc, "myAppName");

After the upgrade to iOS 10 I get this error storing credentials:

"Could not save account to KeyChain: -34018"

at Xamarin.Auth.KeyChainAccountStore.Save (Xamarin.Auth.Account account,System.String serviceId) [0x000b2] in <402cf9b3716845b3bdddef581cb33a3e>:0 

Latest version installed 1.2.3.1 The problem seems to persist only on the SIMULATOR

valdetero
  • 4,624
  • 1
  • 31
  • 46
Ziba Leah
  • 2,484
  • 7
  • 41
  • 60

4 Answers4

78

I was digging through the link Pat sent in the comment: bugzilla.xamarin.com/show_bug.cgi?id=43514

And found a helpfull comment by Pavel Sich, he said:

Just make sure you enable the keychain access in Entitlements and select the entitlements for Simulator (Debug) builds too. By default this is not set.

In my xamarin solution, I double clicked the .IOS project to open the options pane, selected IOS Bundle Signing and changed the Platform select box from "iPhone" to "iPhoneSimulator", then set the field Custom Entitlements to my Entitlements.plist. Now it's working fine for me.

Just a note, this is after editing the Entitlement.plist as suggested by Thibault D. in the previous answer.

Hope this helps.

Rafael
  • 929
  • 6
  • 6
  • Thank you very much. I where having trouble with the Facebook iOS SDK on iOS 10 using XCode 8. http://stackoverflow.com/questions/38689631/how-to-use-facebook-ios-sdk-on-ios-10/38799196#38799196 And you solved it. :) – dynamokaj Sep 19 '16 at 17:08
  • Sir, I own you my full gratitude. Thank you very much, it works like a charm! – Ziba Leah Sep 20 '16 at 09:19
  • 1
    Same solution with Visual Studio and Xamarin – ccook Oct 13 '16 at 14:34
  • 1
    Just to note, that you should use full app id with prefix created by apple. You may add it as "$(AppIdentifierPrefix)yourAppId" and it will do the trick http://stackoverflow.com/a/17624005/3507404 – Ingweland Oct 29 '16 at 16:13
  • 1
    Haha thanks, that's weird. I just hit this issue myself today and found this answer and saw my name in it (I had completely forgotten about this issue and my answer). – Thibault D. Nov 11 '16 at 08:11
  • And as explained here: https://forums.developer.apple.com/thread/60617#180567 it's enough that you have an empty Entitlements file. You don't need to enable shared keychain in the entitlements file. – Thibault D. Nov 11 '16 at 08:14
  • I tried the same steps in Xamarin studio but still same issue. – Signcodeindie Feb 17 '17 at 16:04
  • Adding the custom entitlements to the simulator is what worked for me as well. I didn't need to manually `keychain-access-groups` to the Entitlements.plist. – AJ Venturella Dec 14 '17 at 23:49
  • Not Working for me – Intsab Haider Feb 23 '18 at 13:33
14

According to this thread it's enough that you add an empty entitlements file in you bundle singing configuration:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
  ...
  <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
</PropertyGroup>

Empty Entitlements.plist file:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>
valdetero
  • 4,624
  • 1
  • 31
  • 46
Thibault D.
  • 10,041
  • 3
  • 25
  • 56
  • 2
    I Added this to my Entitlements.plist... Same problem! keychain-access-groups MyAppID – Ziba Leah Sep 14 '16 at 10:52
  • Does not work for me either. Been watching this bug... https://bugzilla.xamarin.com/show_bug.cgi?id=43514 – Pat Sep 16 '16 at 16:50
  • 2
    I've edited my answer with instructions regarding how you get the Entitlements file to get used by the build configuration. – Thibault D. Nov 17 '16 at 07:32
2

Set Custom Entitlements in ios project settings enter image description here

Yauhen Sampir
  • 1,989
  • 15
  • 16
1

It seems that when you work on IphoneSimulator even you enabled KeyChain in Entitlements.plist, it still doesnt work and throws this exception. Because Xamarin doesnt seem to have CodesignEntitlements sets for IphoneSimulator configuration as default although it has for Iphone configurations. You have to open your IOS.csproj file and manually add this line

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">

  <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
</PropertyGroup>
Emil
  • 6,411
  • 7
  • 62
  • 112