Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

System.Exception: Could not save account to KeyChain: -34018 on iOS Simulator 7 OS 10.1 #133

Closed
ericbrunner opened this issue Nov 16, 2016 · 3 comments

Comments

@ericbrunner
Copy link

Hi,
Only on iOS Simulator I get that exception.

iOS Init

AccountStore = AccountStore.Create();

iOS Usage

var account = new Account(user.UserId); account.Properties.Add("token", user.MobileServiceAuthenticationToken); AccountStore.Save(account, TruckerAppKeyStoreKey);

{System.Exception: Could not save account to KeyChain: -34018
at Xamarin.Auth.KeyChainAccountStore.SaveAsync (Xamarin.Auth.Account account, System.String serviceId) [0x000b2] in <54ca90eee8764b32bd8938e52d615b30>:0
at Xamarin.Auth.KeyChainAccountStore.Save (Xamarin.Auth.Account account, System.String serviceId) [0x00000] in <54ca90eee8764b32bd8938e52d615b30>:0
at trucker_rolsped.iOS.Auth.AppleAuth+d__6.MoveNext () [0x004fe] in C:\Source\Workspaces\Main\RCS.MobileApps\TruckerApp\iOS\Auth\AppleAuth.cs:129 }
Data: {System.Collections.ListDictionaryInternal}
HResult: -2146233088
HelpLink: (null)
InnerException: (null)
Message: "Could not save account to KeyChain: -34018"
Source: "Xamarin.Auth"
StackTrace: " at Xamarin.Auth.KeyChainAccountStore.SaveAsync (Xamarin.Auth.Account account, System.String servic…"
TargetSite: {System.Reflection.MonoMethod}

@sushihangover
Copy link

sushihangover commented Nov 16, 2016

@ericbrunner You need to enable "Enable Keychain Access Groups"

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.

ref: http://stackoverflow.com/questions/39487368/xamarin-auth-store-keychain-not-working-after-ios10-upgrade
ref: http://stackoverflow.com/questions/39492752/xamarin-error-code-34018

@ericbrunner
Copy link
Author

ericbrunner commented Nov 17, 2016

@sushihangover Thanks .

According to the 1st SO ref it was enough to add an empty entitlements file to the bundle signing 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>

@moljac
Copy link
Member

moljac commented May 27, 2017

Closing.

References (duplicates):

Analysis

This problem is not Xamarin related: seems like this is bug in iOS 10 simulator and XCode (8.x).

https://forums.developer.apple.com/thread/4743?tstart=0
https://forums.developer.apple.com/thread/51071
https://stackoverflow.com/questions/27752444/ios-keychain-writing-value-results-in-error-code-34018
https://stackoverflow.com/questions/22082996/testing-the-keychain-osstatus-error-34018
https://stackoverflow.com/questions/38456471/secitemadd-always-returns-error-34018-in-xcode-8-in-ios-10-simulator
https://stackoverflow.com/questions/29740952/osstatus-error-code-34018

[Re]Solution / Workaround

If not present create empty Entitlements.plist

<?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>

Entitlements.plist must be added to iOS Bundle Signing options for the iPhoneSimulator|Debug
platform.

iOS App Options/Properties +/ Build / iOS Bundle Signing +/ Custom Entitlements : Entitlements.plist

This will result in following code in *.csproj file:

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\iPhone\Debug</OutputPath>
    <DefineConstants>DEBUG;ENABLE_TEST_CLOUD;</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <ConsolePause>false</ConsolePause>
    <MtouchArch>ARMv7, ARM64</MtouchArch>
    <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
    <MtouchFloat32>true</MtouchFloat32>
    <CodesignKey>iPhone Developer</CodesignKey>
    <DeviceSpecificBuild>true</DeviceSpecificBuild>
    <MtouchDebug>true</MtouchDebug>
    <MtouchProfiling>true</MtouchProfiling>
    <IpaPackageName>
    </IpaPackageName>
  </PropertyGroup>

while default *.csproj file looks like this

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
    <DefineConstants>DEBUG;ENABLE_TEST_CLOUD;</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <CodesignKey>iPhone Developer</CodesignKey>
    <DeviceSpecificBuild>true</DeviceSpecificBuild>
    <MtouchDebug>true</MtouchDebug>
    <MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
    <MtouchFastDev>true</MtouchFastDev>
    <IOSDebuggerPort>50317</IOSDebuggerPort>
    <MtouchLink>None</MtouchLink>
    <MtouchArch>i386, x86_64</MtouchArch>
    <MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
  </PropertyGroup>

NOTE: difference is in this file:

    <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants