mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
The iOS local-network permission prompt fires on the first local-network access. That used to be the user's "Test" tap in settings, so the prompt appeared mid-request and the first connection attempt always failed. Provoke the prompt at launch instead via an mDNS multicast datagram, so the permission is settled before the user reaches settings. Platform exclusion is handled with a conditional import: web gets a no-op stub (keeping dart:io out of web builds) and the native path no-ops off iOS. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
27 lines
951 B
Dart
27 lines
951 B
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
/// Native implementation of [requestLocalNetworkPermission]. Only iOS has a
|
|
/// local-network permission prompt, so this is a no-op on every other native
|
|
/// platform (Android, desktop).
|
|
///
|
|
/// Sending a datagram toward the mDNS multicast group is enough to make iOS
|
|
/// surface the prompt; nothing needs to be received and no backend has to be
|
|
/// reachable.
|
|
Future<void> requestLocalNetworkPermission() async {
|
|
if (!Platform.isIOS) return;
|
|
|
|
RawDatagramSocket? socket;
|
|
try {
|
|
socket = await RawDatagramSocket.bind(InternetAddress.anyIPv4, 0);
|
|
// 224.0.0.251:5353 is the mDNS group; the send itself is what trips the
|
|
// permission prompt, regardless of whether anything is listening.
|
|
socket.send(const [0], InternetAddress('224.0.0.251'), 5353);
|
|
} catch (e) {
|
|
debugPrint('Local network permission trigger failed: $e');
|
|
} finally {
|
|
socket?.close();
|
|
}
|
|
}
|