title: OSStatus error:[-34018] Internal error when a required entitlement isn't present error on device
body: <p>I am trying to implement keychain sharing using KeyChainAccess. I have build two very basic applications: App One that writes a string to a shared keychain, and App Two that reads the data from the shared keychain and displays it.</p>
  
  <p>My code for App One:</p>
  
  <pre><code>    override func viewDidLoad() {
      super.viewDidLoad()
  
      //save item to keychain
      let keychain = Keychain(service: "app.test", accessGroup: "xxxxx.xxxxx.xxxxx.Keychain-Sharing")
  
      do {
          try keychain.set("Some Data Set in app one", key: "sharedData")
          print("Success")
          label.text = "Success"
      }
      catch let error {
          print("Keychain write failed: \(error)")
          label.text = "Keychain write failed: \(error)"
      }
  
  }
  </code></pre>
  
  <p>My code for App Two that reads and displays from the shared keychain:</p>
  
  <pre><code>override func viewDidLoad() {
      super.viewDidLoad()
  
      //load item from keychain
      let keychain = Keychain(service: "app.test", accessGroup: "xxxxx.xxxxx.xxxxx.Keychain-Sharing")
  
      let data = try? keychain.get("sharedData")
  
      print("Data from Keychain: \(data ?? "nil")")
  
      label.text = "Data from Keychain: \(data ?? "nil")"
  }
  </code></pre>
  
  <p>This is a very basic example just to try the concept, however what I am finding is that when I run it using Xcode's simulator on my Mac it behaves as expected, I run the first app - it succeeds, I then run the second app and the correct string is displayed.</p>
  
  <p>When I then try to run it on a device (by plugging my device into my Mac and changing the run location I receive the following error when trying to write and read from the shared keychain:</p>
  
  <pre><code>   OSStatus error:[-34018] Internal error when a required entitlement isn't present, client has neither application-identifier nor keychain-access-groups entitlements.
  </code></pre>
  
  <p>I have checked my entitlements file and I can see that they are included in both applications:</p>
  
  <p><a href="https://i.stack.imgur.com/mNMF1.png" rel="noreferrer"><img src="https://i.stack.imgur.com/mNMF1.png" alt="enter image description here"></a></p>
  
  <p>And the entitlements files is referenced correctly in the build settings:
  <a href="https://i.stack.imgur.com/Bw9p8.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Bw9p8.png" alt="enter image description here"></a></p>
  
  <p>Also when I hover over my provisioning profile it tells me that they are included:</p>
  
  <p><a href="https://i.stack.imgur.com/3BRgX.png" rel="noreferrer"><img src="https://i.stack.imgur.com/3BRgX.png" alt="enter image description here"></a></p>
  
  <p>Is this what is allowing it to run successfully in the Xcode simulator? and what am I missing to get it to run on the handset? I think this is something to do with my certificates / profiles but I am fairly new to this so I am not certain as to exactly what I need / missing or what to check?</p>
  
  <p>Can anyone help or point me in the right direction?</p>