From 432b94fcbe87330c6a61aeca85e6a1a3d351bfe4 Mon Sep 17 00:00:00 2001 From: Yun Chan Date: Sat, 15 Aug 2026 17:06:11 +0900 Subject: [PATCH] M3: QR scanner only on physical devices (simulator camera session hangs first frame on iOS) --- VideoDownloader.Mobile/Pages.cs | 51 ++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/VideoDownloader.Mobile/Pages.cs b/VideoDownloader.Mobile/Pages.cs index 03d968c..50f5ee0 100644 --- a/VideoDownloader.Mobile/Pages.cs +++ b/VideoDownloader.Mobile/Pages.cs @@ -9,35 +9,46 @@ 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 { - HorizontalOptions = LayoutOptions.Fill, - HeightRequest = 320, - Options = new ZXing.Net.Maui.BarcodeReaderOptions - { - Formats = ZXing.Net.Maui.BarcodeFormats.TwoDimensional, - AutoRotate = true, - }, + Text = "📷 시뮬레이터 — 수동 입력을 이용하세요", + HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Center, + HorizontalTextAlignment = TextAlignment.Center, HeightRequest = 120, + BackgroundColor = Colors.Black, TextColor = Colors.LightGray, }; - _scanner.BarcodesDetected += (s, e) => + if (DeviceInfo.Current.DeviceType == DeviceType.Physical) { - var text = e.Results?.FirstOrDefault()?.Value; - if (string.IsNullOrEmpty(text)) return; - MainThread.BeginInvokeOnMainThread(() => + var scanner = new ZXing.Net.Maui.Controls.CameraBarcodeReaderView { - if (ApiClient.Instance.Configure(text)) + HorizontalOptions = LayoutOptions.Fill, + HeightRequest = 320, + Options = new ZXing.Net.Maui.BarcodeReaderOptions { - _status.Text = "✅ 연결됨"; - _scanner.IsDetecting = false; - } - }); - }; + Formats = ZXing.Net.Maui.BarcodeFormats.TwoDimensional, + AutoRotate = true, + }, + }; + scanner.BarcodesDetected += (s, e) => + { + var text = e.Results?.FirstOrDefault()?.Value; + if (string.IsNullOrEmpty(text)) return; + MainThread.BeginInvokeOnMainThread(() => + { + if (ApiClient.Instance.Configure(text)) + { + _status.Text = "✅ 연결됨"; + 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 } } }; }