@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)
Post
Replies
Boosts
Views
Activity
Hi, Prashant_7.
replace this category in your code:
extension UIView {
func takeSnapshot() -> UIImage? {
let renderer = UIGraphicsImageRenderer(size: frame.size)
let image = renderer.image { _ in drawHierarchy(in: bounds, afterScreenUpdates: true) }
UIGraphicsEndImageContext()
return image
}
}
with this one:
extension UIView {
func takeSnapshot() -> UIImage? {
let format = UIGraphicsImageRendererFormat()
format.preferredRange = .standard
let renderer = UIGraphicsImageRenderer(size: frame.size, format: format)
let image = renderer.image { _ in drawHierarchy(in: bounds, afterScreenUpdates: true) }
UIGraphicsEndImageContext()
return image
}
}