15

I have added universal links into my iOS application

messages http://somesite.com/message/list/ >> opens the app to messages 
review   http://somesite.com/review/add/   >> opens the app to review 
place    http://somesite.com/place/add/    >> opens the app to place 
photo    http://somesite.com/photo/add/    >> opens the app to photo

all working as expected, my question is : how to exclude paths or urls, in a way that it never even opens the app?

for example

somepage   http://somesite.com/somepagelink   >> SHOULDN'T OPEN APP, it must show up in the browser.

the apple app site association file

{
    "applinks": 
    {
        "details": [
        {
            "paths": ["*", "NOT /somepagelink/*"],
            "appID": "ID1.myApp"
        }, 
        {
            "paths": ["*", "NOT /somepagelink/*"],
            "appID": "ID2.myApp"
        }],
        "apps": []
    },
    "activitycontinuation": 
    {
        "apps": ["ID1.myApp","ID2.myApp"]
    }
}

is this the correct way to exclude a path?

"NOT /somepagelink/*"
DeyaEldeen
  • 10,847
  • 10
  • 42
  • 75

2 Answers2

28

Yes, your syntax is correct but:

The Apple documentation states, that the order of the statement is important.

Because the system evaluates each path in the paths array in the order it is specified—and stops evaluating when a positive or negative match is found—you should specify high priority paths before low priority paths.

The first statement it evaluates in your file is the star "*" which signals "yes, every URL is allowed". Then it will end and open the app.

So maybe try it the other way round?

"paths": ["NOT /somepagelink/*", "*"],

EDIT

IMPORTANT: This is from the comments given below, apart from changes in AASA. You have to reinstall the app for every change to the apple-app-site-association file. It could definitely be a CDN problem if you are using one of those

Mr. Pyramid
  • 3,855
  • 5
  • 32
  • 56
Blackvenom
  • 667
  • 6
  • 13
  • the problem still is there, I excluded the path and it still clickable, i have removed the app and reinstalled, same same, the super weird thing is, when i make the whole apple-app-site-association empty, the app still opens the links normally, could it be the cdn ? – DeyaEldeen Apr 25 '17 at 16:05
  • 9
    You have to reinstall the app for every change to the `apple-app-site-association` file. It could definitely be a CDN problem, if you are using one of those – Alex Bauer Apr 25 '17 at 16:46
  • this should be wiki :) – えるまる Nov 19 '19 at 16:43
  • @AlexBauer should every user reinstall app or it takes some time to refresh? – えるまる Nov 19 '19 at 16:46
  • I have the same issue as others in the comment. My `paths` array is just the following: `["NOT /subpath/negative/*", "/subpath/*"]`. All subpaths under `/subpath/negative/` are still opened in the app and I reinstalled the app, restarted the phone but this path is still matched. – vinczemarton Feb 07 '22 at 18:24
  • @vinczemarton me too! Did you ever figure it out? – mesqueeb Oct 09 '22 at 16:29
  • @mesqueeb we messed about with it a lot and it seems the parsing is utterly broken, I will share it as a separate answer on how it finally worked – vinczemarton Oct 10 '22 at 12:31
3

It was not a CDN problem at our end. It turns out negative paths can be defined in multiple ways. Specifying them BOTH ways helped.

Let's say we have an app where:

  • The main domain should NOT be opened under the app
  • Everything under /customer should be opened in the app, except
  • Everything under /customer/not_included should NOT be opened in the app

The final apple-app-site-association file is:

{
  "applinks": {
    "apps": [],
    "details": [
      {
        "appIDs": [
          "[APPID]"
        ],
        "appID": "[APPID]",
        "components": [
          {
            "/": "/customer/not_included/*",
            "exclude": true,
            "comment": "not_included exluded"
          },
          {
            "/": "/customer",
            "exclude": true,
            "comment": "Customer exluded"
          },
          {
            "/": "/customer/",
            "exclude": true,
            "comment": "Customer exluded"
          },
          {
            "/": "/customer/*",
            "comment": "Customer sub pages included"
          }
        ],
        "paths": [
          "NOT /customer/not_included/*",
          "NOT /customer",
          "NOT /customer/",
          "/customer/*"
        ]
      }
    ]
  },
  "webcredentials": {
    "apps": [
      "[APPID]"
    ]
  }
}

In your case the important part is that there are both NOT path and exclude: true components which look redundant but if we left out any of them the logic seem to have broken.

vinczemarton
  • 7,756
  • 6
  • 54
  • 86