M3: QR scanner only on physical devices (simulator camera session hangs first frame on iOS)
This commit is contained in:
parent
698f140169
commit
432b94fcbe
1 changed files with 31 additions and 20 deletions
|
|
@ -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 _manual = new() { Placeholder = "PC 주소 (예: 192.168.0.223:52100)", Keyboard = Keyboard.Url };
|
||||||
private readonly Entry _manualToken = new() { Placeholder = "토큰 (QR 못 쓸 때)", IsPassword = true };
|
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 Label _status = new() { Text = "PC 앱에서 '기기 연결'을 누르고 QR 을 스캔하세요", HorizontalOptions = LayoutOptions.Center, Margin = new Thickness(0, 12) };
|
||||||
private readonly ZXing.Net.Maui.Controls.CameraBarcodeReaderView _scanner;
|
|
||||||
|
|
||||||
public ConnectPage()
|
public ConnectPage()
|
||||||
{
|
{
|
||||||
Title = "연결";
|
Title = "연결";
|
||||||
|
|
||||||
_scanner = new ZXing.Net.Maui.Controls.CameraBarcodeReaderView
|
// 시뮬레이터는 카메라 하드웨어가 없어 세션 시작이 첫 프레임을 막음(UIApplication hang) → 실기기에서만 스캐너
|
||||||
|
View scannerArea = new Label
|
||||||
{
|
{
|
||||||
HorizontalOptions = LayoutOptions.Fill,
|
Text = "📷 시뮬레이터 — 수동 입력을 이용하세요",
|
||||||
HeightRequest = 320,
|
HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Center,
|
||||||
Options = new ZXing.Net.Maui.BarcodeReaderOptions
|
HorizontalTextAlignment = TextAlignment.Center, HeightRequest = 120,
|
||||||
{
|
BackgroundColor = Colors.Black, TextColor = Colors.LightGray,
|
||||||
Formats = ZXing.Net.Maui.BarcodeFormats.TwoDimensional,
|
|
||||||
AutoRotate = true,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
_scanner.BarcodesDetected += (s, e) =>
|
if (DeviceInfo.Current.DeviceType == DeviceType.Physical)
|
||||||
{
|
{
|
||||||
var text = e.Results?.FirstOrDefault()?.Value;
|
var scanner = new ZXing.Net.Maui.Controls.CameraBarcodeReaderView
|
||||||
if (string.IsNullOrEmpty(text)) return;
|
|
||||||
MainThread.BeginInvokeOnMainThread(() =>
|
|
||||||
{
|
{
|
||||||
if (ApiClient.Instance.Configure(text))
|
HorizontalOptions = LayoutOptions.Fill,
|
||||||
|
HeightRequest = 320,
|
||||||
|
Options = new ZXing.Net.Maui.BarcodeReaderOptions
|
||||||
{
|
{
|
||||||
_status.Text = "✅ 연결됨";
|
Formats = ZXing.Net.Maui.BarcodeFormats.TwoDimensional,
|
||||||
_scanner.IsDetecting = false;
|
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 = "수동 연결" };
|
var connectBtn = new Button { Text = "수동 연결" };
|
||||||
connectBtn.Clicked += (_, _) =>
|
connectBtn.Clicked += (_, _) =>
|
||||||
|
|
@ -53,7 +64,7 @@ public sealed class ConnectPage : ContentPage
|
||||||
Content = new VerticalStackLayout
|
Content = new VerticalStackLayout
|
||||||
{
|
{
|
||||||
Padding = 20, Spacing = 10,
|
Padding = 20, Spacing = 10,
|
||||||
Children = { _status, _scanner, _manual, _manualToken, connectBtn, forgetBtn }
|
Children = { _status, scannerArea, _manual, _manualToken, connectBtn, forgetBtn }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue