'How do you configure multiple iOS URL Schemes
Is it possible to register multiple URL schemes that are associated with different app ids for the same app. For example I have separate apps per environment of my application each with their own unique bundke id. E.G
com.test.app-dev (testapp-dev://)
com.test.app-qa (testapp-qa://)
com.test.app (testapp://)
If I want to launch the dev app from a url, I would use want to use testapp-dev://
Solution 1:[1]
What I did (in Xcode 12)
Targets -> Your App -> Build Settings -> + -> Add User-Defined setting ->
Setting: URL_SCHEME
Value: yourapp-debug, yourapp, yourapp-test etc. for different schemes.
Targets -> Your App -> Info -> URL Types
URL Schemes: $(URL_SCHEME)
Solution 2:[2]
As @Paulw11 suggested this needed to be done at build time. For each application environment, I have an associated Xcode Scheme. In the build section of the xcode shceme, you can configure a postbuild action. You can execute a shell script as a post build action.
So for example in the com.test.app-dev scheme, there is a post build action that runs this script
/usr/libexec/PlistBuddy -c "set :CFBundleURLTypes:0:CFBundleURLSchemes:0 testapp-dev" "$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
/usr/libexec/PlistBuddy -c "set :CFBundleURLTypes:0:CFBundleURLName com.test.app-dev" "$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
Then in the com.test.app-qa scheme, there is a post build action that runs this script:
/usr/libexec/PlistBuddy -c "set :CFBundleURLTypes:0:CFBundleURLSchemes:0 testapp-qa" "$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
/usr/libexec/PlistBuddy -c "set :CFBundleURLTypes:0:CFBundleURLName com.test.app-qa" "$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
This ensures that the right custom url scheme is registered per application associated with each environment.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Esben von Buchwald |
| Solution 2 | Fergal Rooney |


