@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)
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: