Branch.io: how to switch between live and test environment in iOS

branch ios setup
branch.io tutorial
https branch io dashboard
branch metrics wiki
branch key
branch ios sdk setup
delayinittocheckforsearchads
branch setidentity

As Branch said in its docs:

For more advanced implementations, you may want to specify keys for both Test and Live environments (for example, if you are building a custom switch to automatically select the correct key depending on compiler schemes).

Open your Info.plist file in Xcode, change the branch_key entry to a Dictionary, and create two subentries for your keys:

My question is: How do I build a custom switch to automatically select the correct key depending on compiler schemes? I understand I might use #if DEBUG to define the environment, but I don't understand is where do I tell branch which key it should use? Or branch will simply detect it automatically?

Thank you so much

Alex from Branch.io here: #if DEBUG is the best, approach, and you actually just need to switch out your singleton call. Instead of

let branch: Branch = Branch.getInstance(); // Swift
Branch *branch = [Branch getInstance]; // Objective C

you'll use

let branch: Branch = Branch.getTestInstance(); // Swift
Branch *branch = [Branch getTestInstance]; // Objective C

Branch.io: how to switch between live and test environment in iOS, As Branch said in its docs: For more advanced implementations, you may want to specify keys for both Test and Live environments (for example, if you are  Build high quality user experiences with best-in-class deep linking, all while measuring the complete journey of your users. From desktop to mobile web to native app, at every touchpoint across organic and paid channels, Branch is the platform for mobile growth.

As of May 2018 :

Branch.getTestInstance() is deprecated. Please use below extension to proceed:

extension Branch {
    class var instance:Branch {
        get {
            #if DEBUG
                Branch.setUseTestBranchKey(true)
            #endif
            return Branch.getInstance()
        }
    }
}

iOS, How to switch between live and test environment in iOS. As Branch said in its docs: For more advanced implementations, you may want to  *Testing conducted by Apple in May 2019 using iPhone XS supporting normal peak performance and iPad Pro (11‑inch) with iOS 12.3 and prerelease iPadOS and iOS 13, using third‑party apps repackaged in a preproduction App Store server environment; smaller app update download size based on averages from a collection of the most frequently

You can pass NSString to getInstance. I was using it like that:

if (Debug) {
[Branch getInstance:@"key_test_lalala"];
}

else {
[Branch getInstance:@"key_live_lalala"];
}

In this case you also don't need to have branch_key in plist.

However, as a side note, recently we had a problem that branch links were not working with test key anymore, and the reply from support was that we should not use test keys anymore.

How to switch between live and test environment in iOS – Mobile , Test environment is added so that developers can use it for testing of their app's Branch integration. On Android, when test mode is enabled, the Branch SDK  Create a branch for each environment, including staging and production. Never merge into an environment branch unless you are ready to deploy to that environment. Perform a diff between branches before merging—this can help prevent merging something that wasn't intended, and can also help with writing release notes.

Adding on to Alex Bauer's response, I created an extension to return the proper instance of Branch:

import Branch

extension Branch {
    class var instance:Branch {
        get {
            #if DEBUG
                return Branch.getTestInstance()
            #else
                return Branch.getInstance()
            #endif
        }
    }
}

Usage:

Branch.instance.initSession(launchOptions: launchOptions)

What is the proper way to use test and live environment? – Mobile , By switching the toggle from Live to Test and vice-versa you can change the environment and its settings. Copy key from Account Settings ->  To run this sample on your devices, change the bundle IDs so the apps can be provisioned correctly in your environment: Open this sample with the latest version of Xcode, select the “SimpleWatchConnectivity” target, change the bundle ID to <Your i OS app bundle ID>, and select the right team to let Xcode automatically manage your provisioning profile.

iOS Universal links and App Referrals using BranchIO Integration, Android App links and App Referral using BranchIO Integration By switching the toggle from Live to Test and vice-versa you can change the This might be a case where either of one platform(iOS or Android) is supported names for a different environment like testing, staging, etc, then Branch does not  Use a trusted server to communicate with the App Store. Using your own server lets you design your app to recognize and trust only your server, and lets you ensure that your server connects with the App Store server. It is not possible to build a trusted connection between a user’s device and the App Store directly because you don’t control

Android App links and App Referral using BranchIO Integration, Leanplum's user guides, SDK setup, API docs, and more resources are here to help you get the most out of A/B testing, Campaigns, Messaging, and Analytics. Switch the SDK Environment. We generally rely on SDKs provided by third parties in the project, and these SDKs also provide a test environment. If you want to switch environments in the app, you can't use the above method. What should I do? For example, our "live" module is a referenced SDK, we can do like this:

Branch.io integration, The docs says that it's possible to add both test and live keys in tiapp.xml: for example, if you are building a custom switch How to select the correct key depending on test or production environment #99 I don't have enough knowledge of Titanium to know how well this SDK can support Branch keys per  Python, iOS Swift, Android, Java Develop And Automation Test Tutorials

Comments
  • I found this link helpful: docs.branch.io/apps/ios/#simulate-an-install
  • I suppose that a debug vs release build should consistently use either getTestInstance() or getInstance(). I find debug builds of our app calling Branch.getTestInstance().initSessionWithLaunchOptions(...) when launching, but then using Branch.getInstance() later and suspect that's a problem. Do those instances coexist, do they conflict in any way? Or maybe its ok, maybe the instance that's initialized is the one that gets returned from either get accessor? I'd appreciate confirmation.
  • You need to be consistent about which environment gets used. Branch sees the Live and Test instances as totally separate apps, so the sessions will not be merged and you'll run into bizarre behavior like missing link data and incorrect identities/attribution.
  • Thanks this reminds me how important it is to read EVERY SINGLE DETAIL. :) I had missed the "getTestInstance" portion of the SDK integration guide.
  • Depending on how long ago you read the guide, it might not have existed yet! Glad everything is working now :)