// Copyright 2019 The Chromium 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 *)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 { if (@available(iOS 9.0, *)) { NSSet *websiteDataTypes = [NSSet setWithObject:WKWebsiteDataTypeCookies]; WKWebsiteDataStore *dataStore = [WKWebsiteDataStore defaultDataStore]; void (^deleteAndNotify)(NSArray *) = ^(NSArray *cookies) { BOOL hasCookies = cookies.count > 0; [dataStore removeDataOfTypes:websiteDataTypes forDataRecords:cookies completionHandler:^{ result(@(hasCookies)); }]; }; [dataStore fetchDataRecordsOfTypes:websiteDataTypes completionHandler:deleteAndNotify]; } else { // support for iOS8 tracked in https://github.com/flutter/flutter/issues/27624. NSLog(@"Clearing cookies is not supported for Flutter WebViews prior to iOS 9."); } } @end