iOS 10 Simulator can´t use KeyChain

NicoHaslbergerNicoHaslberger ATMember ✭✭
edited November 2016 in Xamarin.iOS

Hey Guys!
Im just trying to access the keychain of the iOS simulator with an Xamarin iOS app.
The code of the keychain access:

`public void Save(string userName, string password, string url, string serviceId)
    {
        var statusCode = SecStatusCode.Success;
        var serializedAccount = password;
        var data = NSData.FromString(serializedAccount, NSStringEncoding.UTF8);

        //
        // Remove any existing record
        //
        var existing = FindAccount(serviceId);

        if (existing != null)
        {
            var query = new SecRecord(SecKind.GenericPassword);
            query.Service = serviceId;

            statusCode = SecKeyChain.Remove(query);
            if (statusCode != SecStatusCode.Success)
            {
                throw new Exception("Could not save account to KeyChain: " + statusCode);
            }
        }

        //
        // Add this record
        //
        var record = new SecRecord(SecKind.GenericPassword);
        record.Account = userName;
        record.Server = url;
        record.Service = serviceId;
        record.Generic = data;
        record.Accessible = SecAccessible.WhenUnlocked;

        statusCode = SecKeyChain.Add(record);

        if (statusCode != SecStatusCode.Success)
        {
            throw new Exception("Could not save account to KeyChain: " + statusCode);
        }`

But the thing is as status code I get "-34018"!
I already tried that: stackoverflow.com/questions/39487368/xamarin-auth-store-keychain-not-working-after-ios10-upgrade
The thing is: when I set the custom entitlements to my Entitlements.plist I get the following error when I try to publish my app to the ios simulator:
"No installed provisioning profiles match the installed iOS signing identities."

Then I tried to create a provision profile in my apple developer account, but I have no idea where I get the UUID for the simulator?

I´m really fustrated at this point, because I tried several solutions I found from github, stackoverflow, bugzilla, etc. but with any success.

What the hack I´m doing wrong?

greetings

Posts

  • Shaun901Shaun901 GBMember

    Having the same problem here.........has anyone managed to solve this ?

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    You should not need the UUID for the simulator, only for devices.

  • TorbjrnRosendahlTorbjrnRosendahl USMember ✭✭

    I also have the problem described at the top of this page. Has anyone actually managed to solve this?

  • TorbjrnRosendahlTorbjrnRosendahl USMember ✭✭

    @Shaun901 and @NicoHaslberger: Finally found a solution here: http://stackoverflow.com/a/40249263/2366321

    Do not add Entitlements.plist to your Debug iPhoneSimulator configuration, instead: Add an Environment Variable to your Debug iPhoneSimulator configuration named ENTITLEMENTS_REQUIRED and set the value to YES. This will cause Xcode to automatically insert an application-identifier entitlement when building.

  • Shaun901Shaun901 GBMember

    Thanks @TorbjrnRosendahl will give that a try

  • KompileraKompilera SEMember

    @TorbjrnRosendahl I'm having this issue as well but can't seem to get this working I think. I'm using Visual Studio on Mac and not windows. Where would do I add this environment variable?

  • TorbjrnRosendahlTorbjrnRosendahl USMember ✭✭

    @Kompilera - Right click on your iOS project in Visual Studio for Mac and select Options, then click the "Run/Configurations/Default tab". There you will find "Environment Variables:"

    Unfortunately, it only seems to work with Xcode 8.1. I have now upgraded to Xcode 8.3.2 and then this workaround does not seem to work anymore.

    However, I managed to get around the problem (again :smile:) by generating a new developer provisioning profile (the current one had expired) and then adding Entitlement.plist to the Debug IPhoneSimulator configuration as described in this thread: https://forums.xamarin.com/discussion/comment/273972

  • KompileraKompilera SEMember

    Thanks @TorbjrnRosendahl, will try it out :smile:

Sign In or Register to comment.