blob: eb7c856b250d8eb0c9405dd31fc38f69796eeaa3 [file] [log] [blame]
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "FLTCookieManager.h"
@implementation FLTCookieManager {
}
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
FLTCookieManager *instance = [[FLTCookieManager alloc] init];
FlutterMethodChannel *channel =
[FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/cookie_manager"
binaryMessenger:[registrar messenger]];
[registrar addMethodCallDelegate:instance channel:channel];
}
- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
if ([[call method] isEqualToString:@"clearCookies"]) {
[self clearCookies:result];
} else {
result(FlutterMethodNotImplemented);
}
}
- (void)clearCookies:(FlutterResult)result {
NSSet<NSString *> *websiteDataTypes = [NSSet setWithObject:WKWebsiteDataTypeCookies];
WKWebsiteDataStore *dataStore = [WKWebsiteDataStore defaultDataStore];
void (^deleteAndNotify)(NSArray<WKWebsiteDataRecord *> *) =
^(NSArray<WKWebsiteDataRecord *> *cookies) {
BOOL hasCookies = cookies.count > 0;
[dataStore removeDataOfTypes:websiteDataTypes
forDataRecords:cookies
completionHandler:^{
result(@(hasCookies));
}];
};
[dataStore fetchDataRecordsOfTypes:websiteDataTypes completionHandler:deleteAndNotify];
}
@end