Skip to content
Permalink
Browse files

Change ReactNetworkForceWifiOnly from String to Boolean (#24829)

Summary:
We provided `ReactNetworkForceWifiOnly` in #24242, but it's a string type, actually the value only YES or NO, so let's change it to Boolean type, we can benefit from:
1. Users don't need to type string `YES`, just select bool YES or NO directly by click the button:
<img width="789" alt="image" src="https://user-images.githubusercontent.com/5061845/57634311-a8af7400-75d7-11e9-9f8a-ebf865d672e3.png">

2. Don't need to do string compare.

3. More looks what it should looks, Boolean is the Boolean. :)

cc. cpojer ericlewis .

[iOS] [Changed] - Change ReactNetworkForceWifiOnly from String to Boolean
Pull Request resolved: #24829

Differential Revision: D15323685

Pulled By: cpojer

fbshipit-source-id: c626d048d0cbea46d45f232906fd3ac32a412741
  • Loading branch information...
zhongwuzw authored and facebook-github-bot committed May 14, 2019
1 parent de0d7cf commit 916186a7e6c43b1a1c68652ab82862bcd8fb1e01
Showing with 5 additions and 6 deletions.
  1. +5 −6 Libraries/Network/RCTHTTPRequestHandler.mm
@@ -62,20 +62,19 @@ - (NSURLSessionDataTask *)sendRequest:(NSURLRequest *)request
if (!_session && [self isValid]) {
// You can override default NSURLSession instance property allowsCellularAccess (default value YES)
// by providing the following key to your RN project (edit ios/project/Info.plist file in Xcode):
// <key>ReactNetworkForceWifiOnly</key> <string>YES</string>
// <key>ReactNetworkForceWifiOnly</key> <true/>
// This will set allowsCellularAccess to NO and force Wifi only for all network calls on iOS
// If you do not want to override default behavior, do nothing or set key with value "NO"
// If you do not want to override default behavior, do nothing or set key with value false
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *useWifiOnly = [infoDictionary objectForKey:@"ReactNetworkForceWifiOnly"];
NSNumber *useWifiOnly = [infoDictionary objectForKey:@"ReactNetworkForceWifiOnly"];

NSOperationQueue *callbackQueue = [NSOperationQueue new];
callbackQueue.maxConcurrentOperationCount = 1;
callbackQueue.underlyingQueue = [[_bridge networking] methodQueue];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
// set allowsCellularAccess to NO ONLY if key ReactNetworkForceWifiOnly exists AND string value is "YES"
NSString *compareKeyToForceWifiOnly = @"YES";
// Set allowsCellularAccess to NO ONLY if key ReactNetworkForceWifiOnly exists AND its value is YES
if (useWifiOnly) {
configuration.allowsCellularAccess = ![compareKeyToForceWifiOnly isEqualToString:useWifiOnly];
configuration.allowsCellularAccess = ![useWifiOnly boolValue];
}
[configuration setHTTPShouldSetCookies:YES];
[configuration setHTTPCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];

0 comments on commit 916186a

Please sign in to comment.
You can’t perform that action at this time.