diff --git a/Examples/UIExplorer/js/XHRExample.ios.js b/Examples/UIExplorer/js/XHRExample.ios.js index 053bad559..75cb09d40 100644 --- a/Examples/UIExplorer/js/XHRExample.ios.js +++ b/Examples/UIExplorer/js/XHRExample.ios.js @@ -41,6 +41,7 @@ var { var XHRExampleHeaders = require('./XHRExampleHeaders'); var XHRExampleFetch = require('./XHRExampleFetch'); var XHRExampleOnTimeOut = require('./XHRExampleOnTimeOut'); +var XHRExampleCookies = require('./XHRExampleCookies'); /** * Convert number of bytes to MB and round to the nearest 0.1 MB. @@ -432,6 +433,11 @@ exports.examples = [{ render() { return ; } +}, { + title: 'Cookies', + render() { + return ; + } }]; var styles = StyleSheet.create({ diff --git a/Libraries/Network/RCTNetworking.ios.js b/Libraries/Network/RCTNetworking.ios.js index 80418c3e8..fca6351dd 100644 --- a/Libraries/Network/RCTNetworking.ios.js +++ b/Libraries/Network/RCTNetworking.ios.js @@ -52,7 +52,7 @@ class RCTNetworking extends NativeEventEmitter { } clearCookies(callback: (result: boolean) => any) { - console.warn('RCTNetworking.clearCookies is not supported on iOS'); + RCTNetworkingNative.clearCookies(callback); } } diff --git a/Libraries/Network/RCTNetworking.m b/Libraries/Network/RCTNetworking.m index d5823b241..19efc1aad 100644 --- a/Libraries/Network/RCTNetworking.m +++ b/Libraries/Network/RCTNetworking.m @@ -504,6 +504,20 @@ RCT_EXPORT_METHOD(abortRequest:(nonnull NSNumber *)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 @implementation RCTBridge (RCTNetworking)