Skip to content

Instantly share code, notes, and snippets.

@wullink-ps
Last active May 7, 2018 13:59
Show Gist options
  • Select an option

  • Save wullink-ps/6f24c01517c4da0a0dc4c905f16466c5 to your computer and use it in GitHub Desktop.

Select an option

Save wullink-ps/6f24c01517c4da0a0dc4c905f16466c5 to your computer and use it in GitHub Desktop.
public async Task<string> GetResultAsync()
{
var scanner = new MobileBarcodeScanner();
Result result = await scanner.Scan();
RestoreCameraSettings();
return result?.Text;
}
private void RestoreCameraSettings()
{
var devices = AVCaptureDevice.DevicesWithMediaType(AVMediaType.Video);
AVCaptureDevice captureDevice = null;
foreach (var device in devices)
{
if (device.Position == AVCaptureDevicePosition.Back)
{
captureDevice = device;
}
}
if (captureDevice == null)
{
return;
}
if (captureDevice.LockForConfiguration(out NSError err))
{
if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0) && captureDevice.AutoFocusRangeRestrictionSupported)
{
captureDevice.AutoFocusRangeRestriction = AVCaptureAutoFocusRangeRestriction.None;
}
captureDevice.UnlockForConfiguration();
}
}
@mhdamn

mhdamn commented May 7, 2018

Copy link
Copy Markdown

isn't that a little bit of code violation to use the xamarin.ios in portable project.?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment