我希望使用Xamarin开发一个可以打开iPhone背面的LED的简单灯。我如何才能做到这一点?

我想象有一个我可以使用的API,但是无法在Xamarin中找到LED /手电筒的示例。

最佳答案

尝试使用以下代码打开手电筒:

var device = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video);
if (device == null)
{
    return;
}

NSError error = null;
device.LockForConfiguration(out error);
if (error != null)
{
    Debug.WriteLine(error);
    device.UnlockForConfiguration();
    return;
}
else
{
    if (device.TorchMode != AVCaptureTorchMode.On)
    {
        device.TorchMode = AVCaptureTorchMode.On;
    }
    device.UnlockForConfiguration();
}

使用AVCaptureTorchMode.Off关闭手电筒

09-30 14:53
查看更多