Relax, I am sure my published app is not on Demo Server đ
Problem:
Regularly I differentiate between Demo and Live URLs for my apps with boolean variable (isDemoServer), may be there are different ways to handle that, but that what I do.
So, every time when I archive my app, I am not sure, if I changed my boolean variable (isDemoServer) to proper value.
Recently I thought if I can fire error when archiving and the boolean value (isDemoServer) with true, it will be great.
My approach is creating file has isDemoServer variable, then reading file content while archiving, and checking isDemoServer value.
Immediately I thought in writing script to handle that, I googled more about that, and I found this great video (letâs tool it By Ahmed Essam, I mostly recommended to watch it), and the video guided me.
My Script
My script with Python, it reads file content line by line, and split line by space then get variable and its value, then check, if isDemoServer is true fire the error
This code has been updated on the repo to be more generic without static dir for the file, so check the repo.
I tested this script using build phases, and it worked fine, but I donât need to use it while building, I need only used it when archiving.
So I tried to set it in Pre-actions at Archive section in App scheme
But when I tried to archive my app, my script didnât execute, so I googled about this issue, then I found this great answer on StackOverflow,
The answer said:
pre- and post-action scripts are not considered part of the build itself; their output is not part of the build log, and a failing script will not cause the build to fail.
Also the answer guid me for solution of my issue:
Make a new âExternal Build Systemâ target, and configure it to run your script.
So I googled again to how make âExternal Build Systemâ target, and make it run my script.
Creating âExternal Build Systemâ target
1- Go to File > New > TargetâŚ, then choose Cross-platform tab, and select External Build System
2- Tap next, type target name, our script is written by Python3, so we should make build run on Python3, so we should set Python3 path to Build tool field
To get Python3 path, open Terminal and type âwhich python3â, because I wrote my script by Python3(if you donât install Python3, check this link)
Configure Checker target
Select Checker target, open Info tab, set Build Tool with Python3 path, and set Arguments with script file name, and finally set Directory with directory of script file.
Configure App scheme
After configuring Checker target, we need to configure App scheme, to make App run script file.
Select App target and click Edit SchemeâŚ
Click plus button to add Checker target.
Select Checker target, then click Add button
After Adding Checker target, uncheck all of phases except Archive phase.
Testing the script
If you tried to build App on demo server e.g isDemoServer with true, it will build successfully, but if you tried to archive it, you will get this error đ đ.
Limitation
There is a limitation in my script, where each line in the configuration file (that contains isDemoServer), has to has a single space between each word.
You can check demo project on GitHub, I hope this script will help you in your projects, and any feedback will be most welcome, Thanks đ.