ios: fix deprecation warning

NSURLConnection sendSynchronousRequest is deprecated since iOS 9. Replace the
method by whjat's currently on RN master, which implements a modern alternative.
pull/4004/head
Saúl Ibarra Corretgé 6 years ago
parent 2c592f61c3
commit 49a0c03ff0
  1. 27
      ios/sdk/src/RCTBridgeWrapper.m

@ -43,16 +43,25 @@ static NSURL *serverRootWithHost(NSString *host) {
}
- (BOOL)isPackagerRunning:(NSString *)host {
NSURL *url
= [serverRootWithHost(host) URLByAppendingPathComponent:@"status"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLResponse *response;
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:NULL];
NSString *status = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
NSURL *url = [serverRootWithHost(host) URLByAppendingPathComponent:@"status"];
NSURLSession *session = [NSURLSession sharedSession];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
__block NSURLResponse *response;
__block NSData *data;
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
[[session dataTaskWithRequest:request
completionHandler:^(NSData *d,
NSURLResponse *res,
__unused NSError *err) {
data = d;
response = res;
dispatch_semaphore_signal(semaphore);
}] resume];
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
NSString *status = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
return [status isEqualToString:@"packager-status:running"];
}

Loading…
Cancel
Save