Home > Software design >  Configure associated domain from .xcconfig
Configure associated domain from .xcconfig

Time:12-21

I have an app with multiple schemes, where I want to have a different associated domain for each scheme.

I have the following .entitlements file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.developer.associated-domains</key>
    <array>
        <string>applinks:$(ASSOCIATED_DOMAIN)</string>
        <string>webcredentials:(ASSOCIATED_DOMAIN)</string>
    </array>
</dict>
</plist>

My .xcconfig files look like this (?mode=developer is only there to verify everything is working and will be removed):

// ...
ASSOCIATED_DOMAIN="my.domain.com?mode=developer"

I tried to verify my link with the following command, but this opens mobile Safari:

xcrun simctl openurl booted 'https://my.domain.com/app/link'

My /.well-known/apple-app-site-association file is accessible and when I inline my domain and remove the $(ASSOCIATED_DOMAIN) the app link works as expected by opening the app instead of Safari. In this case, my .entitlements file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.developer.associated-domains</key>
    <array>
        <string>applinks:my.domain.com?mode=developer</string>
        <string>webcredentials:my.domain.com?mode=developer</string>
    </array>
</dict>
</plist>

Does anybody have a suggestion what might be wrong? Thanks!

CodePudding user response:

Instead of using a variable for the ASSOCIATED_DOMAIN value, consider specifying a separate entitlements file for each of the schemes. In the relevant xcconfig file, this can be done by setting:

CODE_SIGN_ENTITLEMENTS = [location of the file].entitlements
  • Related