Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import android.net.nsd.NsdServiceInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.Manifest;
import android.content.pm.PackageManager;
import androidx.core.content.ContextCompat;


import com.balthazargronon.RCTZeroconf.Zeroconf;
import com.balthazargronon.RCTZeroconf.ZeroconfModule;
Expand Down Expand Up @@ -46,6 +50,12 @@ public void scan(String type, String protocol, String domain) {

this.stop();

if (ContextCompat.checkSelfPermission(getReactApplicationContext(), Manifest.permission.CHANGE_WIFI_MULTICAST_STATE) != PackageManager.PERMISSION_GRANTED) {
String error = "Local network permission is not granted. Please request the necessary permission.";
zeroconfModule.sendEvent(getReactApplicationContext(), ZeroconfModule.EVENT_ERROR, error);
return;
}

if (multicastLock == null) {
@SuppressLint("WifiManagerLeak") WifiManager wifi = (WifiManager) getReactApplicationContext().getSystemService(Context.WIFI_SERVICE);
multicastLock = wifi.createMulticastLock("multicastLock");
Expand Down
15 changes: 15 additions & 0 deletions ios/RNZeroconf/RNZeroconf.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#import "RNZeroconf.h"
#import "RNNetServiceSerializer.h"

#import <UIKit/UIKit.h>
#import <CoreFoundation/CoreFoundation.h>

@interface RNZeroconf ()

@property (nonatomic, strong, readonly) NSMutableDictionary *resolvingServices;
Expand All @@ -25,6 +28,18 @@ @implementation RNZeroconf
RCT_EXPORT_METHOD(scan:(NSString *)type protocol:(NSString *)protocol domain:(NSString *)domain)
{
[self stop];

if (@available(iOS 14.0, *)) {
if (CLLocationManager.locationServicesEnabled) {
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
if (status != kCLAuthorizationStatusAuthorizedAlways && status != kCLAuthorizationStatusAuthorizedWhenInUse) {
NSString *error = @"Local network permission is not granted. Please request the necessary permission.";
[self reportError:@{@"message": error}];
return;
}
}
}

[self.browser searchForServicesOfType:[NSString stringWithFormat:@"_%@._%@.", type, protocol] inDomain:domain];
}

Expand Down