title: AWSMobileClient iOS SDK - Failing to obtain identity id when getting AWS credentials
body: <p>I have an iOS Swift project using the AWSMobileClient SDK (v2.9.9) installed with Cocoapods.</p>
  
  <p>There is one problematic method that is used quite frequently in the app:</p>
  
  <pre class="lang-swift prettyprint-override"><code>AWSMobileClient.sharedInstance().getAWSCredentials { (credentials, error) in ... }
  </code></pre>
  
  <p>and there is a specific fatal error that occurs:</p>
  
  <blockquote>
    <p>Obtaining an identity id in another thread failed or didn't complete
    within 5 seconds.</p>
  </blockquote>
  
  <p>On some devices, it works fine 90% of the time and only usually occurs after a sequence of steps - e.g. sign in, log out, sign in again (the method is called after sign in). </p>
  
  <p>However, recently on a new device that I've been testing on it has appeared <strong>every single time</strong>.</p>
  
  <p>There was another Stack question <a href="https://stackoverflow.com/questions/45171644/awscognito-login-blocked-1-time-after-logout-obtaining-an-identity-id-in-anot">here</a> that suggested that another AWS SDK operation may be running in parallel when <code>getAWSCredentials</code> is called - but after reviewing my code I'm fairly sure this isn't the case.</p>
  
  <p>I've also tried running this method on the failing device to see if it would give any clues:</p>
  
  <pre class="lang-swift prettyprint-override"><code>AWSMobileClient.sharedInstance().getIdentityId().continueWith { task -&gt; Any? in ... }
  </code></pre>
  
  <p>and returns with this error:</p>
  
  <blockquote>
    <p>Fetching identity id on another thread failed. Please retry by calling
    <code>getIdentityId()</code> method.</p>
  </blockquote>
  
  <p>I've spent hours looking through my own code and the stack traces that led to the error and am at a dead end with thoughts on how to solve or even debug this further.</p>
  
  <p>Hopefully someone will be able to suggest something to help me - thanks! :)</p>