react-native-zeroconf is a comprehensive utility library that enables React Native applications to discover and publish network services using Zeroconf protocols like Bonjour and mDNS. The current stable version is 0.14.0, which was released approximately 3 months ago. It appears to follow an active, though not strictly scheduled, release cadence, with updates addressing platform compatibility, including Android 15+ requirements. It offers cross-platform support for both iOS and Android, providing developers with robust service discovery and publishing capabilities. A key differentiator is its dual Android implementation, allowing selection between the native NSD (Network Service Discovery) API or an embedded DNSSD (mDNSResponder) for potentially broader compatibility. Its active development ensures ongoing support for evolving mobile OS requirements, such as the upcoming Android 15+ page size alignment.
npm install react-native-zeroconfVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to initialize Zeroconf, listen for resolved services, and start/stop scanning for HTTP services. Includes essential cleanup for React components and error handling.
Remove `react-native link` from your installation steps. Autolinking should handle the native module setup automatically. If issues persist, try reinstalling `node_modules` and `pod install` in the `ios` directory.
Add `NSBonjourServices` array (e.g., `<string>_http._tcp.</string>`) and `NSLocalNetworkUsageDescription` string to your `Info.plist`. For more advanced use cases or consistent discovery, apply for the Multicast Networking Entitlement with Apple.
Ensure the required `<uses-permission>` tags are present within the `<manifest>` tag of your `AndroidManifest.xml`.
Upgrade to `react-native-zeroconf@0.14.0` or newer to ensure compatibility with Android 15+ and Google Play requirements.
If encountering unreliable discovery on Android, explicitly specify `'DNSSD'` as the `implType` parameter when calling `scan()`: `zeroconf.scan('http', 'tcp', 'local.', 'DNSSD')`.Test on a physical Android device or configure your Android emulator for multicast support, which usually involves advanced networking setup (e.g., using TAP networking with QEMU).
Always stop the Zeroconf scan and remove listeners when the component unmounts or the app goes into the background. Use React Native's `AppState` API to manage scans based on app foreground/background state. Example: `zeroconf.stop(); zeroconf.removeDeviceListeners();`
For React Native 0.60+, ensure autolinking is working by deleting `node_modules` and `Podfile.lock` (iOS), then `npm install` or `yarn install`, followed by `cd ios && pod install` (for iOS/macOS). Avoid using `react-native link`.
Ensure `import Zeroconf from 'react-native-zeroconf'` is at the top of your file and `const zeroconf = new Zeroconf()` is called before attempting to use its methods. If using Expo, run `npx expo prebuild` to generate native projects or confirm native modules are properly configured.
Verify that `NSBonjourServices` and `NSLocalNetworkUsageDescription` are correctly configured in your `Info.plist`. If the problem persists on iOS 17+, you may need to request the Multicast Networking Entitlement from Apple.
Double-check Android `AndroidManifest.xml` permissions and iOS `Info.plist` entries (`NSBonjourServices`, `NSLocalNetworkUsageDescription`). Ensure devices are on the same Wi-Fi network. On Android, try explicitly using the `DNSSD` implementation for scanning: `zeroconf.scan('http', 'tcp', 'local.', 'DNSSD')`.Implement robust lifecycle management: stop Zeroconf scans (`zeroconf.stop()`) and remove listeners (`zeroconf.removeDeviceListeners()`) when the app moves to the background (using React Native's `AppState` API) or when the component unmounts. Re-initialize and restart scans when the app comes to the foreground.