diff --git a/Dai-Hentai.xcodeproj/project.pbxproj b/Dai-Hentai.xcodeproj/project.pbxproj
index 36d230bf..4d42d747 100644
--- a/Dai-Hentai.xcodeproj/project.pbxproj
+++ b/Dai-Hentai.xcodeproj/project.pbxproj
@@ -995,7 +995,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 10.2;
+ IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
@@ -1046,7 +1046,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 10.2;
+ IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
@@ -1064,10 +1064,12 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
+ CURRENT_PROJECT_VERSION = 20200703;
DEVELOPMENT_TEAM = XLP7NJ2T65;
INFOPLIST_FILE = "Dai-Hentai/Info.plist";
- IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ MARKETING_VERSION = 3.11;
PRODUCT_BUNDLE_IDENTIFIER = "tw.daidouji.Dai-Hentai";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
@@ -1087,10 +1089,12 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
+ CURRENT_PROJECT_VERSION = 20200703;
DEVELOPMENT_TEAM = XLP7NJ2T65;
INFOPLIST_FILE = "Dai-Hentai/Info.plist";
- IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ MARKETING_VERSION = 3.11;
PRODUCT_BUNDLE_IDENTIFIER = "tw.daidouji.Dai-Hentai";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
diff --git a/Dai-Hentai/Info.plist b/Dai-Hentai/Info.plist
index e4152b3f..50ba9934 100644
--- a/Dai-Hentai/Info.plist
+++ b/Dai-Hentai/Info.plist
@@ -15,9 +15,9 @@
CFBundlePackageType
APPL
CFBundleShortVersionString
- 3.9
+ $(MARKETING_VERSION)
CFBundleVersion
- 20190922
+ $(CURRENT_PROJECT_VERSION)
Fabric
APIKey
diff --git a/Dai-Hentai/Models/ExCookieChecker/ExCookie.swift b/Dai-Hentai/Models/ExCookieChecker/ExCookie.swift
index b6013b82..4eb5c25e 100644
--- a/Dai-Hentai/Models/ExCookieChecker/ExCookie.swift
+++ b/Dai-Hentai/Models/ExCookieChecker/ExCookie.swift
@@ -7,42 +7,43 @@
//
import Foundation
+import WebKit
class ExCookie: NSObject {
// MARK: - Property
- private static let url = URL(string: "https://e-hentai.org")!
+ private static let ehDomain = ".e-hentai.org"
+ private static let exDomain = ".exhentai.org"
// MARK: - Static Function
@objc static func isExist() -> Bool {
- var isExist = false
- guard let cookies = HTTPCookieStorage.shared.cookies(for: url) else {
- return isExist
- }
- for cookie in cookies {
- if let expiresDate = cookie.expiresDate, cookie.name == "ipb_pass_hash" {
- if NSDate().compare(expiresDate) != .orderedAscending {
- isExist = false
- } else {
- isExist = true
- }
- }
+ if isCookiesInStorage() {
+ return true
}
- if isExist {
- replace()
- }
- return isExist
+ findCookiesInWKDataStore()
+
+ return false
}
@objc static func clean() {
+
+ // 一般的 request 用的 cookies 放在 HTTPCookieStorage
let shared = HTTPCookieStorage.shared
for cookie in shared.cookies ?? [] {
shared.deleteCookie(cookie)
}
+
+ // WKWebView 的 cookie 放在 WKWebsiteDataStore
+ WKWebsiteDataStore.default().fetchDataRecords(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes()) {
+ $0.forEach {
+ WKWebsiteDataStore.default().removeData(ofTypes: $0.dataTypes, for: [$0]) {
+ }
+ }
+ }
}
@objc static func manuallyAddCookie(exKey: String) {
@@ -65,7 +66,7 @@ class ExCookie: NSObject {
continue
}
- properties[.domain] = ".e-hentai.org" // 將同樣的Cookie也添加到表站
+ properties[.domain] = ehDomain // 將同樣的Cookie也添加到表站
if let newCookie = HTTPCookie(properties: properties) {
HTTPCookieStorage.shared.setCookie(newCookie)
}
@@ -75,27 +76,74 @@ class ExCookie: NSObject {
// MARK: - Private Static Function
private static func replace() {
- guard let cookies = HTTPCookieStorage.shared.cookies(for: url) else {
- return
+ WKWebsiteDataStore.default().httpCookieStore.getAllCookies { (cookies) in
+ cookies.filter { $0.domain == ehDomain }.forEach { (cookie) in
+ if var newProperties = cookie.properties {
+ newProperties[.domain] = exDomain
+
+ if let newCookie = HTTPCookie(properties: newProperties) {
+
+ // 一般的 request 用的 cookies 放在 HTTPCookieStorage
+ HTTPCookieStorage.shared.setCookie(newCookie)
+
+ // WKWebView 的 cookie 放在 WKWebsiteDataStore
+ WKWebsiteDataStore.default().httpCookieStore.setCookie(newCookie, completionHandler: nil)
+ }
+ }
+ }
+ }
+ }
+
+ private static func createCookie(name: String, value: String) -> HTTPCookie {
+ return HTTPCookie(properties: [
+ .domain: exDomain,
+ .name: name,
+ .value: value,
+ .path: "/",
+ .expires: Date(timeInterval: 157784760, since: Date())
+ ])! // 5年後過期
+ }
+
+ private static func isCookiesInStorage() -> Bool {
+ var isInStorage = false
+
+ guard
+ let cookies = HTTPCookieStorage.shared.cookies?.filter({ $0.domain == exDomain }),
+ !cookies.isEmpty else {
+
+ return isInStorage
}
for cookie in cookies {
- guard var properties = cookie.properties else {
- continue
+ if let expiresDate = cookie.expiresDate, cookie.name == "ipb_pass_hash" {
+ if NSDate().compare(expiresDate) != .orderedAscending {
+ isInStorage = false
+ } else {
+ isInStorage = true
+ }
}
+ }
+ return isInStorage
+ }
+
+ private static func findCookiesInWKDataStore() {
+ WKWebsiteDataStore.default().httpCookieStore.getAllCookies { (cookies) in
- properties[.domain] = ".exhentai.org"
- if let newCookie = HTTPCookie(properties: properties) {
- HTTPCookieStorage.shared.setCookie(newCookie)
+ var isInDataStore = false
+ cookies.filter { $0.domain == ehDomain }.forEach { (cookie) in
+ if cookie.name == "ipb_pass_hash", let expiresDate = cookie.expiresDate {
+ if Date().compare(expiresDate) != .orderedAscending {
+ isInDataStore = false
+ } else {
+ isInDataStore = true
+ }
+ }
+ }
+
+ if isInDataStore {
+ replace()
}
}
}
- private static func createCookie(name: String, value: String) -> HTTPCookie {
- return HTTPCookie(properties: [.domain: ".exhentai.org",
- HTTPCookiePropertyKey.name: name,
- HTTPCookiePropertyKey.value: value,
- HTTPCookiePropertyKey.path: "/",
- HTTPCookiePropertyKey.expires: Date(timeInterval: 157784760, since: Date())])! // 5年後過期
- }
}
diff --git a/Dai-Hentai/ViewControllers/CheckPageViewController/CheckPageViewController.swift b/Dai-Hentai/ViewControllers/CheckPageViewController/CheckPageViewController.swift
index 52d39ddb..09c69bc1 100644
--- a/Dai-Hentai/ViewControllers/CheckPageViewController/CheckPageViewController.swift
+++ b/Dai-Hentai/ViewControllers/CheckPageViewController/CheckPageViewController.swift
@@ -8,6 +8,7 @@
import Foundation
import UIKit
+import WebKit
class CheckPageViewController: UIViewController {
@@ -41,8 +42,8 @@ class CheckPageViewController: UIViewController {
return
}
// 開一個頁面
- let webView = UIWebView(frame: view.bounds)
- webView.loadRequest(URLRequest(url: url))
+ let webView = WKWebView(frame: view.bounds)
+ webView.load(URLRequest(url: url))
view.addSubview(webView)
}
diff --git a/Dai-Hentai/ViewControllers/LoginViewController/LoginViewController.swift b/Dai-Hentai/ViewControllers/LoginViewController/LoginViewController.swift
index 3ddbb65f..b11265cd 100644
--- a/Dai-Hentai/ViewControllers/LoginViewController/LoginViewController.swift
+++ b/Dai-Hentai/ViewControllers/LoginViewController/LoginViewController.swift
@@ -8,6 +8,7 @@
import Foundation
import UIKit
+import WebKit
class LoginViewController: UIViewController {
@@ -41,8 +42,8 @@ class LoginViewController: UIViewController {
// 開一個登入網頁
if let url = URL(string: "https://forums.e-hentai.org/index.php?act=Login&CODE=01") {
let request = URLRequest(url: url)
- let webView = UIWebView(frame: view.bounds)
- webView.loadRequest(request)
+ let webView = WKWebView(frame: view.bounds)
+ webView.load(request)
view.addSubview(webView)
}
diff --git a/Dai-Hentai/ViewControllers/SettingViewController/ListAndAPIStatus/SettingViewController+ListAndAPIStatus.m b/Dai-Hentai/ViewControllers/SettingViewController/ListAndAPIStatus/SettingViewController+ListAndAPIStatus.m
index e52fc590..975a9747 100644
--- a/Dai-Hentai/ViewControllers/SettingViewController/ListAndAPIStatus/SettingViewController+ListAndAPIStatus.m
+++ b/Dai-Hentai/ViewControllers/SettingViewController/ListAndAPIStatus/SettingViewController+ListAndAPIStatus.m
@@ -60,6 +60,8 @@ - (UIViewController *)checkViewControllerBy:(NSString *)reuseIdentifier {
}
- (void)displayListAndAPIStatus {
+ BOOL cookieExist = [ExCookie isExist];
+
@weakify(self);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@strongify(self);
@@ -73,7 +75,7 @@ - (void)displayListAndAPIStatus {
[self statusCheck:HentaiParserTypeEh listLabel:self.ehListCheckLabel apiLabel:self.ehAPICheckLabel];
// 如果沒有 cookies, 則直接設定字樣
- if (![ExCookie isExist]) {
+ if (!cookieExist) {
[self localStatus:LocalStatusTypeExNotLogin listLabel:self.exListCheckLabel apiLabel:self.exAPICheckLabel];
}
// 測試 ex 是否正常