OpenURLIntent to custom url scheme

Has anyone figured out how to use the new OpenURLIntent intent to open their own app using a custom URL scheme?

I have the following code:

@available(iOS 18, *)
struct BarcodeScannerControlWidget: ControlWidget {
  var body: some ControlWidgetConfiguration {
    StaticControlConfiguration(kind: "scannerIntent") {
      ControlWidgetButton(action: OpenBarcodeScannerIntent()) {
        Label("Scan Barcode", systemImage: "barcode.viewfinder")
      }
    }
    .displayName("Scan Barcode")
  }
}

@available(iOS 18, *)
struct OpenBarcodeScannerIntent: AppIntent {
  static var title: LocalizedStringResource = "Scan Barcode"
  
  func perform() async throws -> some IntentResult & OpensIntent  {
    let url = "myscheme:///barcodeScanner
    let openURLIntent = OpenURLIntent(url)
    return .result(opensIntent: openURLIntent)
  }
}

Running this intent doesn't seem to do anything. If I replace the URL with say "https://www.apple.com", the intent opens up safari with that URL.

I am facing the same issue. Did you find a solution so far? @yqiang

We're facing a very similar issue. We have a URLRepresentableIntent intent that opens a universal link. When it's fired from the ControlWidget, the link only opnes in Safari. But if I run the intent from the Shortcuts app, it works as expected: it opens the app and the app handles the link.

Reported here FB14844990

Have you guys @yqiang @NickYaw found any solution?

Universal Links are the supported mechanism to open your app from an App Intent.

@michaelmix_ls

Reported here FB14844990

Thank you for filing that! Have you tried this on the iOS 18.1 Beta 3? This is resolved, and noted in the Release Notes for that beta:

Fixed: Apps that support universal links might not open normally and instead open the browser when the user navigates to a URL provided by the OpenURLIntent or URLRepresentableIntent APIs. (133764689) (FB14784347)

—Ed Ford,  DTS Engineer

@yqiang , you should write you Intent in the next way (I marked three steps with comments):


@available(iOS 18, *)
struct OpenBarcodeScannerIntent: AppIntent {
  static var title: LocalizedStringResource = "Scan Barcode"

  // 1. add this property to launch the app
  static var openAppWhenRun: Bool { true }
  
  func perform() async throws -> some IntentResult & OpensIntent  {
    let url = "myscheme:///barcodeScanner"
    let openURLIntent = OpenURLIntent(url)
    // 2. open your custom url with help of EnvironmentValues
    await EnvironmentValues().openURL(url)
    // 3. now you don't have to return opensIntent, so just return an empty .result()
    return .result()
  }
}

P.S. tested on iPhone 13 Pro Max with iOS 18.1(release) and Xcode Version 16.1 (16B40)

OpenURLIntent to custom url scheme
 
 
Q