Open UIViewController when QR Code is scanned

Hi developers,

I have a question if it is possible to open in my application not main window but a specific ViewController, when application is installed but not running.

When the application is running in background and I scan QR code, then specific ViewController is opened over SceneDelegate and method 'userActivity'. But this does not work when the application is only installed, but not running.

The Appstore link is here: https://apps.apple.com/us/app/don%C3%A1tor/id6473955033

Thank you for the post. I recommend reading into Universal Links. If a QR code opens to a URL, it will prompt the user to open the camera and scan the QR code, which will then open Safari or the default browser. If the QR code opens to a registered Universal Link, the app installed with the URL will handle the URL.

The application does not require to be running to be opened via a registered Universal Link. It suffices to register the link with the application, and the server must be appropriately configured.

Here are some resources to implement all that:

https://developer.apple.com/documentation/xcode/supporting-universal-links-in-your-app

Also, please read the troubleshooting as configuration is the most important for everything to work:

https://developer.apple.com/documentation/technotes/tn3155-debugging-universal-links

Hope this helps.

Albert Pascual
  Worldwide Developer Relations.

Sorry. My application supports Universal Links already. In case the application is running on the background and I scan a QR Code then application is executed and shows the proper window like here:

See scene code here:

    func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {

        debugPrint("scenes: continue userActivity: \(userActivity)")
        guard userActivity.activityType == NSUserActivityTypeBrowsingWeb else {
            debugPrint("Different type then expected")
            return
        }
        
        // Confirm that the NSUserActivity object contains a valid NDEF message.
        let ndefMessage = userActivity.ndefMessagePayload
        if ndefMessage.records.count == 1 && ndefMessage.records[0].typeNameFormat == .empty {
            debugPrint("scene continue userActivity from Camera: \(userActivity.webpageURL!)")
            guard let navigationController = window?.rootViewController as? UINavigationController else {
                return
            }
            
            navigationController.popToRootViewController(animated: true)
            let donatorViewController = navigationController.topViewController as? DonatorViewController
            donatorViewController?.checkCameraURL(cameraURL: userActivity.webpageURL!)
        } else if ndefMessage.records.count > 0 && ndefMessage.records[0].typeNameFormat != .empty {
            debugPrint("scenes: continue userActivity from NFC Chip: \(userActivity.webpageURL!)")
            // Confirm that the NSUserActivity object contains a valid NDEF message.
            let ndefMessage = userActivity.ndefMessagePayload
            // Send the message to `MessagesTableViewController` for processing.
            guard let navigationController = window?.rootViewController as? UINavigationController else {
                return
            }
            
            navigationController.popToRootViewController(animated: true)
            let donatorViewController = navigationController.topViewController as? DonatorViewController
            donatorViewController?.addMessage(msgFromUserActivity: ndefMessage)
        }
                
        return
    }

But the question is:

  1. The application is installed and not running even in background.
  2. I will scan QR code. The application is opened but the code func scene userActivity is not called.

Thanks.

Open UIViewController when QR Code is scanned
 
 
Q