title: Xcode: push notifications to build on device work but not to TestFlight/App Store install on same device
body: <p>I've realized that I can test push notifications in development and prod builds on local devices- but they don't work with real installs from TestFlight/App Store.</p>
  
  <p>I think this has to do with Xcode's signing of builds vs. archives, but I cannot figure out what to do to fix my current configuration. I use the Xcode auto signing, FYI.</p>
  
  <p>I use Mixpanel for event tracking and notifications, which also lets me confirm the device token is being retrieved successfully. I have my production push certificate uploaded there.</p>
  
  <p>If I have a build running on my device, I can grab the token from a log message and send a push to it (using my prod push certificate) with a different utility called Pusher- this works perfectly. </p>
  
  <p>However, if I download my app from TestFlight or the App Store, start it, get the resulting token from Mixpanel, and send another notification via Mixpanel, it never shows up. Going back to Pusher, if I attempt a push with the token from Mixpanel, I get an <code>APN invalid token</code> error. </p>
  
  <p>Both of these tokens were grabbed the same way- immediately after the user agrees to notifications or the push plugin finishes setup. They were also grabbed on the same code- but one from a running Xcode build, the other from an archive on the TestFlight.</p>
  
  <p>Project setup- I have the Push switch set to on in the Xcode Capabilities menu, and I've generated push certs for dev and production (well, 2 for prod by accident. I figured it was fine):</p>
  
  <p><a href="https://i.stack.imgur.com/cSU7l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cSU7l.png" alt="certs"></a></p>
  
  <p>I also have the Distribution and Dev provisioning profiles created. This is where my question lies- I read that Xcode doesn't use the Distribution profile you create until archiving, and uses it's own until then if you have Automatic Signing selected in the code signing settings. </p>
  
  <p>Is that why I have 2 profiles here? The one I created shows as Active &amp; also lists Push Notifications under services if I expand the entry below:</p>
  
  <p><a href="https://i.stack.imgur.com/WF2tQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WF2tQ.png" alt="provisioning profiles"></a></p>
  
  <p>The cert my production provisioning profile is signed with is an iOS Distribution certificate that matches the team I have selected for signing:</p>
  
  <p><a href="https://i.stack.imgur.com/GylZE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GylZE.png" alt="signing info"></a></p>
  
  <p>While writing this up I realized that maybe my release build settings, specifically signing, were wrong. I though they should also be using my <code>Iphone Distribution: MyCompany Inc (USA)</code> certificate (instead of the default <code>iOS Developer</code> identity), since my Distribution provisioning profile is signed with that same certificate. Unfortunately this doesn't seem to work either.</p>
  
  <p>If my build settings look like this (or if I select the generic <code>iOS Distribution</code> from the dropdown for Release identity):</p>
  
  <p><a href="https://i.stack.imgur.com/fXanR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fXanR.png" alt="build settings"></a></p>
  
  <p>I can't actually build- I get an error that there are conflicting provisioning settings. If I use the <code>iPhone Distribution: MyCompany Inc (USA)</code> certificate just in the <code>Release</code> line (not the <code>Any iOS SDK</code> line), I can create an archive, but I see the same behavior.</p>
  
  <p>I thought for sure this was it, since I've been using my MyCompany Inc (USA) development team for provisioning when validating/uploading archives. </p>
  
  <p>I also tried turning off automatic signing and setting the debug and release profiles to the dev and prod provisioning profiles I made in the Apple Developer site. No luck there either.</p>
  
  <p>Just to come full circle- this is the archive summary information I see when using automatic signing:</p>
  
  <p><a href="https://i.stack.imgur.com/1OBpX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1OBpX.png" alt="archive info"></a></p>
  
  <p>This is correct, right? The identity listed was used to sign the selected provisioning profile, so that should be all I need as far as proper signing, right? Given the other setup, of course.</p>
  
  <p>I'm completely stumped at this point- how am I supposed to configure signing for archives?</p>