Skip to content

Commit 0e5bfc9

Browse files
authored
add clearCookie (#12)
1 parent 2663ad6 commit 0e5bfc9

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ const response = await fetch(window.WebviewProxy.convertProxyUrl(url));
1212
console.debug(response);
1313
```
1414

15+
#### To delete all Cookies use this:
16+
```javascript
17+
window.WebviewProxy.clearCookie();
18+
```
19+
1520
**Make sure you are using a custom scheme with your iOS platform**
1621

1722
This plugin uses the WKURLSchemeHandler provided by WKWebView. It requires the latest version of cordova-ios.

src/ios/WebviewProxy.m

+17
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ @interface WebviewProxy : CDVPlugin {
88

99
@property (nonatomic) NSMutableArray* stoppedTasks;
1010

11+
- (void)clearCookie:(CDVInvokedUrlCommand*)command;
12+
1113
@end
1214

1315
@implementation WebviewProxy
@@ -101,4 +103,19 @@ - (void) stopSchemeTask: (id <WKURLSchemeTask>)urlSchemeTask {
101103
[self.stoppedTasks addObject:urlSchemeTask];
102104
}
103105

106+
- (void) clearCookie:(CDVInvokedUrlCommand*)command {
107+
CDVPluginResult* pluginResult = nil;
108+
109+
WKWebsiteDataStore* dataStore = [WKWebsiteDataStore defaultDataStore];
110+
WKHTTPCookieStore* cookieStore = dataStore.httpCookieStore;
111+
[cookieStore getAllCookies:^(NSArray<NSHTTPCookie *> * cookies) {
112+
for (NSHTTPCookie* _c in cookies)
113+
{
114+
[cookieStore deleteCookie:_c completionHandler:nil];
115+
};
116+
}];
117+
118+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
119+
}
120+
104121
@end

www/WebviewProxy.js

+4
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ WebviewProxy.prototype.convertProxyUrl = function (path) {
1616
return path;
1717
}
1818

19+
WebviewProxy.prototype.clearCookie = function (successCallback, errorCallback) {
20+
cordova.exec(successCallback, errorCallback, "WebviewProxy", "clearCookie", []);
21+
}
22+
1923
module.exports = new WebviewProxy();

0 commit comments

Comments
 (0)