-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: Swift VisionKit APIs #2994
Comments
The runtime repo doesn't contain any GUI related component. System.Native only contains native binding for fundamental stuff that needs cross-platform support. It can't be consumed out of the repo. Apple OS-specific binding lives in https://github.com/xamarin/xamarin-macios . The tooling for swift binding is currently in develop at https://github.com/dotnet/runtimelab/tree/feature/swift-bindings . Xamarin-macios should then consume the binding tooling when it becomes stable. |
@MicahKimel Thanks for reaching out. We are currently working on a tool that generates C# bindings from an input Swift framework, such as It is still in the experimental phase and is not officially supported. You can definitely contribute in two ways:
I assume this code snippet is a proposal for how it could be used from C#, but I didn't find the callback method. Could you provide the Swift code snippet that you want to implement? Based on this, we can determine if this is something the tool already supports and decide on the next steps. |
Thanks @kotlarmilos! I'll check out the repo! Should something like this be implemented in Here's some swift code to go along with the above C# api, import Vision
import VisionKit
@objc(DataScannerViewController)
public class ScanControllerWrapper : NSObject, DataScannerViewControllerDelegate
{
private var viewController: DataScannerViewController
private var scannerCallback: ((_ codes: [String]) -> Void)? = nil
private var scannerUpdateCallback: ((_ codes: [String]) -> Void)? = nil
@objc
@MainActor override init()
{
let supportedBarcodes = VNDetectBarcodesRequest.init().symbologies
let viewController = DataScannerViewController.init(recognizedDataTypes:[.barcode(symbologies:supportedBarcodes)])
self.viewController = viewController
super.init()
self.viewController.delegate = self
}
@objc
public func getViewController() -> UIViewController
{
return self.viewController
}
private func handleBarcodeCallback(barcodes: [RecognizedItem], callback: ((_ codes: [String]) -> Void)?)
{
if(callback != nil)
{
let scannedBarcodes: [String] = barcodes.map
{ (item) -> String in
switch(item)
{
case .barcode(let barcode):
return barcode.payloadStringValue ?? "<barcode not read>"
default:
return "<not a barcode>"
}
}
callback!(scannedBarcodes)
}
}
public func dataScanner(_ dataScanner: DataScannerViewController, didAdd addedItems: [RecognizedItem], allItems: [RecognizedItem])
{
handleBarcodeCallback(barcodes: addedItems, callback: self.scannerCallback)
}
public func dataScanner(_ dataScanner: DataScannerViewController, didUpdate updatedItems: [RecognizedItem], allItems: [RecognizedItem])
{
handleBarcodeCallback(barcodes: updatedItems, callback: self.scannerUpdateCallback)
}
@objc
@MainActor public func setScanCallback(callback: @escaping ([String]) -> Void)
{
self.scannerCallback = callback
}
@objc
@MainActor public func setScanUpdatedCallback(callback: @escaping ([String]) -> Void)
{
self.scannerUpdateCallback = callback
}
@objc
@MainActor public func startScan()
{
try? // NOTE: hides errors
self.viewController.startScanning()
}
@objc
@MainActor public func stopScan()
{
self.viewController.stopScanning()
}
} |
Correct. Ideally, we run the tooling to generate the bindings instead of adding a manual bindings.
The generated bindings call into the native library. The tooling consumes .ABI.json file which is a result of
Thanks, I will run the tooling and check what we can supported atm. |
Background and motivation
Currently swift bindings for CryptoKit have been implemented, I would like to work on contributing the native swift VisionKit api. This could turn into a rather large project, but to start I would like to implement the DataScannerViewController for barcode scanning in C# MAUI.
Apple is continually adding swift native packages to iOS, if MAUI plans to stay relevant and up to date with new iOS features objective c headers for swift native packages need to be added to runtimes anyways.
Where are the native swift bindings going to be put? Should they go in https://github.com/dotnet/runtime/tree/ec118c7e798862fd69dc7fa6544c0d9849d32488/src/native/libs/System.Native?
API Proposal
API Usage
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: