Search code examples
iosnativescriptpublish

Nativescript tns publish ios not working reliably since Apple enforced 2FA on App Store Connect


I have a Nativescript app which I want to publish to App Store Connect. I am using a CI/CD system setup as such:

  • Step 1: build the app for release using "tns build", it outputs an .ipa file
  • Step 2: run the command "tns publish ios", and uses a specific Apple ID to log in to App Store Connect and upload the .ipa file

This system used to work fine, until Apple started to make 2FA mandatory for all accounts interacting with App Store Connect in March 2021.

Since then, the command "tns publish ios" has been unable to send the binary to App Store Connect, mentioning an authentication error, and prompting me to enable 2FA on the Apple ID I used.

I've completed the following steps to make my CI/CD system work again:

  • enabled 2FA on the specific Apple ID I mentioned earlier
  • set up an application-specific password for this Apple ID which would be used by my CI/CD software
  • used the tool "tns apple-login" from a mac machine to generate a valid session token for this Apple ID
  • added the app-specific password and the session token as parameters to "tns publish ios" following this piece of documentation https://v7.docs.nativescript.org/angular/tooling/docs-cli/publishing/publish-ios

After doing this, I can successfully build and upload an iOS app build on App Store Connect using my CI/CD system... For a few hours. After this happens, I have to regenerate a new session token using "tns apple-login".

It seems the 2FA support for the "tns publish ios" command was an aftertought. I can't imagine having to log-in every time I want to upload a binary is a good long term solution.

Has anyone else had that issue with a Nativescript app ? Any good alternatives for uploading an already built .ipa file to App Store Connect, using a CI/CD system ?


Solution

  • Just out of providing this question with an answer for other wanderers, here's what I did to solve my issues.

    We have since then stopped using tns publish ios, it was clearly designed for manual use. Thankfully there were solutions out there.

    Apple's solution to dealing with 2FA on CI/CD systems is to use the App Store Connect API.

    More info on how it works here: https://developer.apple.com/documentation/appstoreconnectapi

    Additionally, a good alternative to tns publish ios which supports the App Store Connect API for CI/CD systems is Fastlane.

    They have a documentation page for this use case, which I followed: https://docs.fastlane.tools/app-store-connect-api/