반응형

서버쪽에서 css소스를 반영했는데 바로 적용이 안되는 문제가 발생해 찾아보니 앱캐시가 문제였다.

 

swift

//원하는 캐시 데이터만 골라서 삭제
let websiteDataTypes = NSSet(array: [WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache, WKWebsiteDataTypeCookies])
let date = NSDate(timeIntervalSince1970: 0)
WKWebsiteDataStore.default().removeData(ofTypes: websiteDataTypes as! Set, modifiedSince: date as Date, completionHandler:{
	//remove callback
})

// 모든 열어본 페이지에 대한 데이터를 모두 삭제
WKWebsiteDataStore.default().fetchDataRecords(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes(), completionHandler: {
    (records) -> Void in
    for record in records{
        WKWebsiteDataStore.default().removeData(ofTypes: record.dataTypes, for: [record], completionHandler: {})
       //remove callback
    }
})

 

 

objective c

    //원하는 캐시데이터 삭제
    NSSet* nSet= [NSSet setWithArray:@[WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache, WKWebsiteDataTypeCookies]];
    NSDate *nDate=[NSDate dateWithTimeIntervalSince1970:0];
    [WKWebsiteDataStore.defaultDataStore removeDataOfTypes:nSet modifiedSince:nDate completionHandler:^{
        //delete callback
    }];
    
    //모든 캐시데이터 삭제
    [WKWebsiteDataStore.defaultDataStore fetchDataRecordsOfTypes:WKWebsiteDataStore.allWebsiteDataTypes completionHandler:^(NSArray<WKWebsiteDataRecord *> * records) {
        for(WKWebsiteDataRecord *record in records){
            [WKWebsiteDataStore.defaultDataStore removeDataOfTypes:record.dataTypes forDataRecords:@[record] completionHandler:^{
                //delete callback
            }];
        }
    }];

 

 

 

위 3개 타입외에도 앱에 들어가있는 아래 타입데이터들도 삭제가 가능하다.

WKWebsiteDataTypeDiskCache,
WKWebsiteDataTypeOfflineWebApplicationCache,
WKWebsiteDataTypeMemoryCache,
WKWebsiteDataTypeLocalStorage,
WKWebsiteDataTypeCookies,
WKWebsiteDataTypeSessionStorage,
WKWebsiteDataTypeIndexedDBDatabases,
WKWebsiteDataTypeWebSQLDatabases,
WKWebsiteDataTypeFetchCache, //(iOS 11.3, *)
WKWebsiteDataTypeServiceWorkerRegistrations, //(iOS 11.3, *)

설명은 아래와같습니다.

WKWebsiteDataTypeCookies

Cookies.

WKWebsiteDataTypeIndexedDBDatabases

IndexedDB databases.

WKWebsiteDataTypeLocalStorage

HTML local storage.

WKWebsiteDataTypeMemoryCache

In-memory caches.

WKWebsiteDataTypeOfflineWebApplicationCache

HTML offline web application caches.

WKWebsiteDataTypeSessionStorage

HTML session storage.

WKWebsiteDataTypeWebSQLDatabases

WebSQL databases.

 

반응형

+ Recent posts