M3: QR scanner only on physical devices (simulator camera session hangs first frame on iOS)

This commit is contained in:
Yun Chan 2026-08-15 17:06:11 +09:00
parent 698f140169
commit 432b94fcbe

View file

@ -9,13 +9,22 @@ public sealed class ConnectPage : ContentPage
private readonly Entry _manual = new() { Placeholder = "PC 주소 (예: 192.168.0.223:52100)", Keyboard = Keyboard.Url };
private readonly Entry _manualToken = new() { Placeholder = "토큰 (QR 못 쓸 때)", IsPassword = true };
private readonly Label _status = new() { Text = "PC 앱에서 '기기 연결'을 누르고 QR 을 스캔하세요", HorizontalOptions = LayoutOptions.Center, Margin = new Thickness(0, 12) };
private readonly ZXing.Net.Maui.Controls.CameraBarcodeReaderView _scanner;
public ConnectPage()
{
Title = "연결";
_scanner = new ZXing.Net.Maui.Controls.CameraBarcodeReaderView
// 시뮬레이터는 카메라 하드웨어가 없어 세션 시작이 첫 프레임을 막음(UIApplication hang) → 실기기에서만 스캐너
View scannerArea = new Label
{
Text = "📷 시뮬레이터 — 수동 입력을 이용하세요",
HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Center,
HorizontalTextAlignment = TextAlignment.Center, HeightRequest = 120,
BackgroundColor = Colors.Black, TextColor = Colors.LightGray,
};
if (DeviceInfo.Current.DeviceType == DeviceType.Physical)
{
var scanner = new ZXing.Net.Maui.Controls.CameraBarcodeReaderView
{
HorizontalOptions = LayoutOptions.Fill,
HeightRequest = 320,
@ -25,7 +34,7 @@ public sealed class ConnectPage : ContentPage
AutoRotate = true,
},
};
_scanner.BarcodesDetected += (s, e) =>
scanner.BarcodesDetected += (s, e) =>
{
var text = e.Results?.FirstOrDefault()?.Value;
if (string.IsNullOrEmpty(text)) return;
@ -34,10 +43,12 @@ public sealed class ConnectPage : ContentPage
if (ApiClient.Instance.Configure(text))
{
_status.Text = "✅ 연결됨";
_scanner.IsDetecting = false;
scanner.IsDetecting = false;
}
});
};
scannerArea = scanner;
}
var connectBtn = new Button { Text = "수동 연결" };
connectBtn.Clicked += (_, _) =>
@ -53,7 +64,7 @@ public sealed class ConnectPage : ContentPage
Content = new VerticalStackLayout
{
Padding = 20, Spacing = 10,
Children = { _status, _scanner, _manual, _manualToken, connectBtn, forgetBtn }
Children = { _status, scannerArea, _manual, _manualToken, connectBtn, forgetBtn }
}
};
}