Test mode in your app
Your app’s test app has its own key (app_test_…), contacts and data (Test mode); your team makes it with Set up test mode on Testing › Test mode. Nothing in your code changes for it: a staging build sends the test app’s key, against the same address.
A key for each build
Section titled “A key for each build”Keep the key in a build setting, so that each configuration carries its own:
CRM_APP_KEY = app_test_...CRM_APP_KEY = app_...In Info.plist, add a key of your own, CrmAppKey, with the value $(CRM_APP_KEY), and read it as you make the facade:
#if DEBUGprivate let isRelease = false#elseprivate let isRelease = true#endif
@MainActorlet crm = Crm( config: CrmConfig( apiBase: URL(string: "https://app.purrcrm.com")!, appKey: Bundle.main.object(forInfoDictionaryKey: "CrmAppKey") as? String ?? "", appVersion: "1.4.0", releaseBuild: isRelease), auth: .tokens(crmTokens))Find both keys in the App key card on Settings › your app › Developers › Install: switch Live | Test to see the test app’s.
Sign-in
Section titled “Sign-in”The test app checks tokens with its own sign-in. Your staging backend signs with the test app’s identity secret (crm_is_test_…, on Settings › your app › Developers › Sign-in in Test). A staging token sent with the live key, or a live token with the test key, is refused with a sentence saying which, and the SDK does not keep asking for new tokens.
Pushes and email
Section titled “Pushes and email”Pushes go through the test app’s own Firebase key (your staging Firebase project), to the devices your staging build registered: give the staging build that project’s GoogleService-Info.plist. Emails go only to addresses on the test app’s allow-list; the rest wait in the Test outbox.
Knowing which mode you are in
Section titled “Knowing which mode you are in”crm.isTestModesays whether the build talks to the test app: from the app’s public face once PurrCRM has answered, and from the key’s prefix until then. Draw a marker of your own on screen in a test build if you want one; the SDK draws none.CrmConfig.releaseBuildsays whether this is a build your users install: the SDK cannot tell for sure. A release build with a test key, or withdebugon, writes a warning to the log once a launch, and carries on: a staging key in what your users install would put all of them in the test app.
CrmSdk: WARNING: this is a release build with a test app key (app_test_...). …CrmSdk: WARNING: this is a release build with CrmConfig.debug on: …Test phones
Section titled “Test phones”A phone your team makes a test phone (under Testing › Preview on my phone) gets the messages they send it with Try it on my test phone at once, ahead of everything else and never held back.
crm.testPhoneis aCrmValue<Bool>: whether the user signed in is one of your team’s test phones.await crm.checkNow()checks in at once, whatever PurrCRM‘s pace, and answers how many tests arrived (nilwhen it could not ask).
A test is pushed to the phone and checked for at once. Put a “Check for tests now” row on your settings screen, shown only while crm.testPhone.value is true, for a phone whose pushes are off.