iOS code signing error

I was just stuck with a similar error with the system not being able to access the key to sign with. I had to go into Keychain Access and find the key corresponding to the certificate under login > keys, then click it and under Access Control, select “allow all applications to access this item”.

In case it helps anyone else.