Files
oott/frontend/lib/utils/local_network_permission_io.dart
T
rzuastiandClaude Opus 4.8 40a7f3a432 Request iOS local-network permission at app launch
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>
2026-06-07 15:33:06 -04:00

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();
}
}