16

We're using separate databases for production and development for our iOS application, and we're testing via TestFlight. The problem is TestFlight distributing the application in release mode.

How can I configure the project so that it distributes the application in development mode?

Or should I actually set different build identifiers for release and development and then have two applications in TestFlight?

What's normally being done?

Anurag Sharma
  • 4,276
  • 2
  • 28
  • 44
eirikvaa
  • 1,070
  • 1
  • 13
  • 24

1 Answers1

10

Summary of solution

I suggest you to add a value in build settings. You set it to PRODUCTION only when you build your production version.

Just use an #if statement to check if the PRODUCTION is set


In my app (I use Batch for push notifications)

I have 2 versions of the same app. one free with ads, one paid without ads. I just set like this in the free version:

Active Compilation Conditions Setting

And like this in the paid version:

enter image description here

And finally I use it in code =]

    // MARK: Batch.
    #if FREE
        #if DEBUG
            print("Batch FREE - DEBUG mode")
            Batch.start(withAPIKey: "-MY FREE VERSION DEBUG KEY-") // dev
        #elseif RELEASE
            print("Batch FREE - RELEASE mode")
            Batch.start(withAPIKey: "-MY FREE VERSION RELEASE KEY-") // live
        #endif
    #elseif PAID
        #if DEBUG
            print("Batch PAID - DEBUG mode")
            Batch.start(withAPIKey: "-MY PAID VERSION DEBUG KEY-") // dev
        #elseif RELEASE
            print("Batch PAID - RELEASE mode")
            Batch.start(withAPIKey: "-MY PAID VERSION RELEASE KEY-") // live
        #endif
    #endif
    // Register for push notifications
    BatchPush.registerForRemoteNotifications()

In your case it will be manual due.

You set PRODUCTION in Active Compilation Conditions only when building to production. and then add this code:

#if PRODUCTION
    // Connect to production database
#else
    // Connect to test database
#endif
Yitzchak
  • 3,303
  • 3
  • 30
  • 50
  • Thank you for taking the time to write up a response. The thing is, I'm able to distinguish between production and debug mode, but the problem is that builds distributed with TestFlight are marked as *release*. This means users testing the TestFlight version will use the production database. I'm wondering if there's a way to distinguish between apps released to the App Store and apps distributed via TestFlight. Or maybe I'm misunderstanding you? – eirikvaa Nov 06 '17 at 19:59
  • as i said, you add a custom flag when you build to app store. and you don't need to touch code because the preprocessing "if" will handle it. the flag is not apple default flags... you can set and remove it any time. and just check in code if its set – Yitzchak Nov 06 '17 at 20:09
  • Do you have a separate target for each of the two version of you application? – eirikvaa Nov 06 '17 at 20:13
  • 1
    you may also want to try to create 2 schemes. one for test flight and one for app store. you set "Production" flag only for app store scheme and then you upload each scheme without touching anything – Yitzchak Nov 06 '17 at 20:14
  • Ok, I will try that! Thank you so much for taking the time to help me. Will report back :) – eirikvaa Nov 06 '17 at 20:15
  • 1
    cool, i just posted that YES, I have two targets (its optional in your case but very convenient) – Yitzchak Nov 06 '17 at 20:15
  • You definitely pointed me in the correct direction, and because of the comments above, I'll mark this as the correct answer. – eirikvaa Nov 07 '17 at 19:03
  • for anyone else out there looking for an answer: the key word is `scheme`: you can define and edit a scheme for debug which you can archive and deploy in testflight, then do the same for a release scheme. Schemes can be found right next to de target device field. – DoruChidean Oct 03 '19 at 08:10
  • This was super helpful! I had to add the flag in "Preprocessor Macros" instead of "Active Compilation Conditions" – Jack Bridger Jan 25 '22 at 15:21