Chenglu Chenglu - 5 months ago 55
iOS Question

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 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:


enter image description here

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!

Answer

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