Reputation: 10204
We're trying to set up an association file for a website that didn't have it before.
We've uploaded the file to https://www.our-website.com/.well-known/apple-app-site-association
(as suggested in the documentation). Unfortunately, it didn't work, the links still open in the browser instead of our app and we can't seem to figure out why.
We tried querying the Apple CDN, and for some reason it returns 404:
$ curl -v https://app-site-association.cdn-apple.com/a/v1/www.our-website.com
>
< HTTP/2 404
< apple-failure-details: {"cause":"invalid character '\u003c' looking for beginning of value"}
< apple-failure-reason: SWCERR00401 Bad JSON content
< apple-from: https://www.our-website.com/.well-known/apple-app-site-association
< apple-try-direct: false
< cache-control: max-age=3600,public
< content-type: text/plain; charset=utf-8
< via: https/1.1 dkvib1-3p-pst-001.ts.apple.com (acdn/153.14426), http/1.1 dkvib1-3p-pac-001.ts.apple.com (acdn/153.14426), https/1.1 dkvib1-3p-pfe-002.ts.apple.com (acdn/153.14426), 1.1 varnish
< cdnuuid: 1741f0c3-efb3-42fa-b574-ae3bfebb13f6-333001418
< expires: Fri, 24 May 2024 10:43:27 GMT
< accept-ranges: bytes
< age: 1693
< date: Fri, 24 May 2024 11:11:25 GMT
< x-cdn: fsly
< x-served-by: cache-bma1670-BMA
< x-cache: hit-stale, hit-fresh, hit-stale, HIT
< x-cache-hits: 0
< x-timer: S1716549085.460891,VS0,VE1
< content-length: 10
<
Not Found
Requesting the association file directly returns 200 though (we tried from different networks, all works fine):
$ https://www.our-website.com/.well-known/apple-app-site-association
< HTTP/2 200
< date: Fri, 24 May 2024 11:03:15 GMT
< content-type: application/json; charset=utf-8
< content-length: 200
< cache-control: no-store
< x-varnish-director: sports_web_pro
< vary: Accept-Encoding,User-Agent
< x-cache: MISS
< x-age: 0
< age: 0
< accept-ranges: bytes
<
(json content here)
According to AASA validator, all is good:
It's been several days already, so hopefully this isn't a caching issue. Previously we also tried hosting the file at https://www.our-website.com/apple-app-site-association
but the result was the same.
Strangely, the diagnostic tool on iPhone (in Settings > Developer) reports that all is A-OK:
This is all thoroughly confusing, especially the failure message: {"cause":"invalid character '\u003c' looking for beginning of value"}
. Is the CDN bot trying to parse the body even after receiving 404? Or is this the cached HTML that was returned at .well-known
when we were trying to host the file at the root? (since '\u003c' is the opening angle bracket).
Anyone has any ideas?
UPDATE: TN3155 suggests running sudo swcutil dl -d www.our-website.com
:
The operation couldn’t be completed. (SWCErrorDomain error 7.)
I have no clue what this error means but I'm finding references to the same cause, invalid character '\u003c' looking for beginning of value
.
UPDATE 2: I haven't posted the content of the file (since I didn't think it was the cause of the issue), but here goes:
{
"applinks": {
"apps": [],
"details": [
{
"appID": "ABCDE12345.com.our-website.www",
"paths": [
"*"
]
}
]
},
"activitycontinuation": {
"apps": [
"ABCDE12345.com.our-website.www"
]
},
"webcredentials": {
"apps": [
"ABCDE12345.com.our-website.www"
]
}
}
The file is quite simple. I have confirmed that it works in the developer mode (when I add applinks:www.our-website.com?mode=developer
to the list of associated domains). We also tried deploying hosting this file to the staging server (at stage-www.our-website.com
, has pretty much the same configuration as the production server) and https://app-site-association.cdn-apple.com/a/v1/stage-www.our-website.com
returns 200, so this must be an issue with the CDN.
Upvotes: 5
Views: 1736
Reputation: 10204
We have found the culprit: the server hosting the association file was wrapping the content of the file in HTML if user agent contained the word "bot" (and returning proper JSON for web browsers and curl). And of course the CDN bot makes the request with User-Agent: AASA-Bot/*
:
curl -A "AASA-Bot/*" https://www.our-website.com/.well-known/apple-app-site-association
<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">{
"applinks": {
"apps": [],
"details": [
{
"appID": "ABCDE12345.com.our-website.www",
"paths": [
"*"
]
}
]
},
"activitycontinuation": {
"apps": [
"ABCDE12345.com.our-website.www"
]
},
"webcredentials": {
"apps": [
"ABCDE12345.com.our-website.www"
]
}
}</pre></body></html>
And that's where the opening angle bracket the bot was complaining about came from.
Once the offending piece of logic was updated, everything worked as expected.
Upvotes: 2
Reputation: 26549
I would try the following diagnostic checks:
application/json
MIME type.Try also the following:
Setting your cache control header to Cache-Control: public, max-age=0
.
Goodluck!
Upvotes: 0