Support RCTNetworking#clearCookies on iOS
Summary: This adds cookie clearing support for iOS to match the existing support on Android. Helpful for resetting the app to a clean state (say, when logging a user out). Closes https://github.com/facebook/react-native/pull/9264 Differential Revision: D3776492 Pulled By: javache fbshipit-source-id: 59ae19ac09d3cf0d0e229cd9e8e30865e65ca96c
This commit is contained in:
parent
1eddd01063
commit
63931b1a68
|
@ -41,6 +41,7 @@ var {
|
||||||
var XHRExampleHeaders = require('./XHRExampleHeaders');
|
var XHRExampleHeaders = require('./XHRExampleHeaders');
|
||||||
var XHRExampleFetch = require('./XHRExampleFetch');
|
var XHRExampleFetch = require('./XHRExampleFetch');
|
||||||
var XHRExampleOnTimeOut = require('./XHRExampleOnTimeOut');
|
var XHRExampleOnTimeOut = require('./XHRExampleOnTimeOut');
|
||||||
|
var XHRExampleCookies = require('./XHRExampleCookies');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert number of bytes to MB and round to the nearest 0.1 MB.
|
* Convert number of bytes to MB and round to the nearest 0.1 MB.
|
||||||
|
@ -432,6 +433,11 @@ exports.examples = [{
|
||||||
render() {
|
render() {
|
||||||
return <XHRExampleOnTimeOut/>;
|
return <XHRExampleOnTimeOut/>;
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
title: 'Cookies',
|
||||||
|
render() {
|
||||||
|
return <XHRExampleCookies />;
|
||||||
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
var styles = StyleSheet.create({
|
var styles = StyleSheet.create({
|
||||||
|
|
|
@ -52,7 +52,7 @@ class RCTNetworking extends NativeEventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
clearCookies(callback: (result: boolean) => any) {
|
clearCookies(callback: (result: boolean) => any) {
|
||||||
console.warn('RCTNetworking.clearCookies is not supported on iOS');
|
RCTNetworkingNative.clearCookies(callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -504,6 +504,20 @@ RCT_EXPORT_METHOD(abortRequest:(nonnull NSNumber *)requestID)
|
||||||
[_tasksByRequestID removeObjectForKey:requestID];
|
[_tasksByRequestID removeObjectForKey:requestID];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RCT_EXPORT_METHOD(clearCookies:(RCTResponseSenderBlock)responseSender)
|
||||||
|
{
|
||||||
|
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
|
||||||
|
if (!storage.cookies.count) {
|
||||||
|
responseSender(@[@NO]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (NSHTTPCookie *cookie in storage.cookies) {
|
||||||
|
[storage deleteCookie:cookie];
|
||||||
|
}
|
||||||
|
responseSender(@[@YES]);
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation RCTBridge (RCTNetworking)
|
@implementation RCTBridge (RCTNetworking)
|
||||||
|
|
Loading…
Reference in New Issue