pwa-builder / PWABuilder

The simplest way to create progressive web apps across platforms and devices. Start here. This repo is home to several projects in the PWABuilder family of tools.
https://docs.pwabuilder.com
Other
2.69k stars 282 forks source link

Universal Links on iOS don't seem to work #2614

Closed tlhunter closed 2 years ago

tlhunter commented 2 years ago

Describe the bug When a link to the domain that is associated with my PWA is opened, iOS does switch focus to my app. However, the app doesn't load the URL that was opened. Instead, it remains on the screen that was last opened in the app. I believe the Swift app delegate function isn't being called.

URL to app

To Reproduce

  1. Install Radar Chat
  2. Generate an Auth Email
  3. Click the button at the end of the email
  4. Application opens in default view, user is not logged in

Expected behavior

  1. Install Radar Chat
  2. Generate an Auth Email
  3. Click the button at the end of the email
  4. Application opens the auth view and redirects, user is logged in

Screenshots The associated domain is configured:

Screen Shot 2022-02-10 at 12 47 25 PM

Additional info (please complete the following information):

Additional context

While debugging, I updated AppDelegate.swift to print when a handoff happens. In the simulator, clicking links to the app does switch to the app, but again, the URL isn't received AND the print calls aren't made:

      // Handle deep links into our app.
      // See https://developer.apple.com/documentation/xcode/supporting-universal-links-in-your-app
      func application(_ application: UIApplication,
             continue userActivity: NSUserActivity,
             restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
        print("Received a link possibly")
        // Ensure we're trying to launch a link.
        guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
            let incomingURL = userActivity.webpageURL else {
            return false
        }
        print("Received a link: \(incomingURL)")

        // Handle it inside our web view.
        let handledRequest = URLRequest(url: incomingURL)
        RadarChat.webView.load(handledRequest)
        return true
      }
ghost commented 2 years ago

Hello tlhunter, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will investigate the issue and help solve it ASAP. Other community members may also look into the issue and provide feedback 🙌

tlhunter commented 2 years ago

After reading the Universal Links documentation a few more times, I realized the file needs to be served with Content-Type: application/json. This isn't the default case on any server since such detection usually depends on file extension. I went and updated the header. Apple takes up to 48 hours to update its cache so it will take a couple days to confirm if this changes anything.

For the curious, to update the header for a PWA hosted on Netlify, add this to a file named netlify.toml:

[[headers]]
  for = "/.well-known/apple-app-site-association"
  [headers.values]
    Content-Type = "application/json"

Apple also offers a webpage for verifying some of this stuff: App Search API Validation Tool. When attempting to check my domain the final bit fails:

Link to Application

Action required Could not extract required information for Universal Links. Learn how to implement the recommended Universal Links.

Error no apps with domain entitlements. The entitlement data used to verify deep link dual authentication is from the current released version of your app. This data may take 48 hours to update.

I think this is the smoking gun that there's an issue with the server configuration. Hopefully, within 48 hours, the caches will update and this will work. Once that's done I'll close out this ticket and maybe this issue will serve as a form of documentation.

tlhunter commented 2 years ago

After further research, I do suspect the header change don't actually affect universal links. I'm seeing that other services don't necessarily follow the content type guidelines:

tlhunter commented 2 years ago

It looks like I generated the app via PWA Builder before this commit had landed... https://github.com/pwa-builder/pwabuilder-ios/commit/bce0d1fd0e4f275853a5c0821a6b2244405f2cde

tlhunter commented 2 years ago

Ah, that was the problem. The code I was using was from an old version of PWA Builder. I generated the app again and copied the newer SceneDelegate.swift file over the older one. Universal links now seem to work.