Skip to content

Commit

Permalink
fix(IOS): Live Reload
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanSe Dussan authored and JuanSe Dussan committed Oct 25, 2019
1 parent 1455bfe commit aa44375
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions ios/RNWifi.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@

@interface WifiManager () <CLLocationManagerDelegate>
@property (nonatomic,strong) CLLocationManager *locationManager;
@property (nonatomic) BOOL solved;
@end
@implementation WifiManager

- (instancetype)init {
self = [super init];
if (self) {
NSLog(@"RNWIFI:Init");
self.solved = YES;
if (@available(iOS 13, *)) {
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
Expand Down Expand Up @@ -121,21 +123,25 @@ + (BOOL)requiresMainQueueSetup
// Need request LocationPermission or HotSpot or have VPN connection
// https://forums.developer.apple.com/thread/117371#364495
[self.locationManager requestWhenInUseAuthorization];
self.solved = NO;
[[NSNotificationCenter defaultCenter] addObserverForName:@"RNWIFI:authorizationStatus" object:nil queue:nil usingBlock:^(NSNotification *note)
{
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse ||
[CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways){
NSString *SSID = [self getWifiSSID];
if (SSID){
resolve(SSID);
return;
if(self.solved == NO){
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse ||
[CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways){
NSString *SSID = [self getWifiSSID];
if (SSID){
resolve(SSID);
return;
}
NSLog(@"RNWIFI:ERROR:Cannot detect SSID");
reject(@"cannot_detect_ssid", @"Cannot detect SSID", nil);
}else{
reject(@"ios_error", @"Permission not granted", nil);
}
NSLog(@"RNWIFI:ERROR:Cannot detect SSID");
reject(@"cannot_detect_ssid", @"Cannot detect SSID", nil);
}else{
reject(@"ios_error", @"Permission not granted", nil);
}

// Avoid call when live-reloaded app
self.solved = YES;
}];
}else{
NSString *SSID = [self getWifiSSID];
Expand Down

0 comments on commit aa44375

Please sign in to comment.