@@ -38,7 +38,6 @@ open class HTTPCookieStorage: NSObject {
38
38
39
39
private static var sharedStorage : HTTPCookieStorage ?
40
40
private static var sharedCookieStorages : [ String : HTTPCookieStorage ] = [ : ] //for group storage containers
41
-
42
41
private var cookieFilePath : String !
43
42
private let workQueue : DispatchQueue = DispatchQueue ( label: " HTTPCookieStorage.workqueue " )
44
43
var allCookies : [ String : HTTPCookie ]
@@ -47,7 +46,13 @@ open class HTTPCookieStorage: NSObject {
47
46
allCookies = [ : ]
48
47
cookieAcceptPolicy = . always
49
48
super. init ( )
50
- cookieFilePath = filePath ( path: _CFXDGCreateDataHomePath ( ) . _swiftObject, fileName: " /.cookies. " + cookieStorageName)
49
+ let bundlePath = Bundle . main. bundlePath
50
+ var bundleName = bundlePath. components ( separatedBy: " / " ) . last!
51
+ if let range = bundleName. range ( of: " . " , options: String . CompareOptions. backwards, range: nil , locale: nil ) {
52
+ bundleName = bundleName. substring ( to: range. lowerBound)
53
+ }
54
+ let cookieFolderPath = _CFXDGCreateDataHomePath ( ) . _swiftObject + " / " + bundleName
55
+ cookieFilePath = filePath ( path: cookieFolderPath, fileName: " /.cookies. " + cookieStorageName, bundleName: bundleName)
51
56
loadPersistedCookies ( )
52
57
}
53
58
@@ -72,12 +77,13 @@ open class HTTPCookieStorage: NSObject {
72
77
}
73
78
}
74
79
75
- private func filePath( path: String , fileName: String ) -> String {
80
+ private func filePath( path: String , fileName: String , bundleName : String ) -> String {
76
81
if directory ( with: path) {
77
82
return path + fileName
78
83
}
79
- //if we were unable to create the desired directory, create the cookie file in the `pwd`
80
- return FileManager . default. currentDirectoryPath + fileName
84
+ //if we were unable to create the desired directory, create the cookie file
85
+ //in a subFolder (named after the bundle) of the `pwd`
86
+ return FileManager . default. currentDirectoryPath + " / " + bundleName + fileName
81
87
}
82
88
83
89
open var cookies : [ HTTPCookie ] ? {
0 commit comments