In IOS App, I can't get the link entered in Associated Domains to open from Safari. It opens to home page

494 views Asked by At

I cannot get the correct url to open from Safari when it prompts me to go to the app. I have my app configured to the home page with WKWebView, and the universal link I set up in Associated Domains is the login page.

In the Associated Domains section of Xcode, I entered: applinks:mydomain.com/login-page. I've tried everything, but when I enter the sub domain in Safari, it always opens to: mydomain.com in the app. I have Associated Domains enabled in my Apple developer account. Here is the code for my apple-app-site-association file, which is in both the root directory and the .well-known directory:

 {
  "applinks": {
    "apps": [],
    "details": [
    {
      "appID": "TEAMID.com.-mydomain.MyDomain",
      "paths": ["login-page"]
    }
    ]
  }
}  

Finally, this is the code I entered in the AppDelagate:

func application(_ application: UIApplication,
                 continue userActivity: NSUserActivity,
                 restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool
{
    // Get URL components from the incoming user activity.
    guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
        let incomingURL = userActivity.webpageURL,
        let components = NSURLComponents(url: incomingURL, resolvingAgainstBaseURL: true) else {
        return false
    }

    // Check for specific URL components that you need.
    guard let path = components.path,
    let params = components.queryItems else {
        return false
    }    
    print("path = \(path)")

    if let albumName = params.first(where: { $0.name == "albumname" } )?.value,
        let photoIndex = params.first(where: { $0.name == "index" })?.value {

        print("album = \(albumName)")
        print("photoIndex = \(photoIndex)")
        return true

    } else {
        print("Either album name or photo index missing")
        return false
    }
}

For some reason, the app is not reading the universal link that I set up. I have researched this high and low, and just can't find the solution. I know I'm leaving something out, but at this point, I don't know what it could be. Can someone please help me?

0

There are 0 answers