简体   繁体   中英

Configure associated domain from .xcconfig

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM