Skip to content

Commit 916186a

Browse files
zhongwuzwfacebook-github-bot
authored andcommitted
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
1 parent de0d7cf commit 916186a

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Libraries/Network/RCTHTTPRequestHandler.mm

+5-6
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,19 @@ - (NSURLSessionDataTask *)sendRequest:(NSURLRequest *)request
6262
if (!_session && [self isValid]) {
6363
// You can override default NSURLSession instance property allowsCellularAccess (default value YES)
6464
// by providing the following key to your RN project (edit ios/project/Info.plist file in Xcode):
65-
// <key>ReactNetworkForceWifiOnly</key> <string>YES</string>
65+
// <key>ReactNetworkForceWifiOnly</key> <true/>
6666
// This will set allowsCellularAccess to NO and force Wifi only for all network calls on iOS
67-
// If you do not want to override default behavior, do nothing or set key with value "NO"
67+
// If you do not want to override default behavior, do nothing or set key with value false
6868
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
69-
NSString *useWifiOnly = [infoDictionary objectForKey:@"ReactNetworkForceWifiOnly"];
69+
NSNumber *useWifiOnly = [infoDictionary objectForKey:@"ReactNetworkForceWifiOnly"];
7070

7171
NSOperationQueue *callbackQueue = [NSOperationQueue new];
7272
callbackQueue.maxConcurrentOperationCount = 1;
7373
callbackQueue.underlyingQueue = [[_bridge networking] methodQueue];
7474
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
75-
// set allowsCellularAccess to NO ONLY if key ReactNetworkForceWifiOnly exists AND string value is "YES"
76-
NSString *compareKeyToForceWifiOnly = @"YES";
75+
// Set allowsCellularAccess to NO ONLY if key ReactNetworkForceWifiOnly exists AND its value is YES
7776
if (useWifiOnly) {
78-
configuration.allowsCellularAccess = ![compareKeyToForceWifiOnly isEqualToString:useWifiOnly];
77+
configuration.allowsCellularAccess = ![useWifiOnly boolValue];
7978
}
8079
[configuration setHTTPShouldSetCookies:YES];
8180
[configuration setHTTPCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];

0 commit comments

Comments
 (0)