多语言BUG修复
This commit is contained in:
parent
b4b867b7d4
commit
a94e3a8fd7
@ -29,8 +29,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
// SPLoginManager.manager.requestVisitorLogin(completer: nil)
|
||||
SPLoginManager.manager.updateUserInfo(completer: nil)
|
||||
///更新本地多语言
|
||||
SPLocalizedManager.shared.updateLocalizedData(completer: nil)
|
||||
///注册消息通知
|
||||
registerAPNS()
|
||||
|
||||
|
@ -17,29 +17,15 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
guard let windowScene = (scene as? UIWindowScene) else { return }
|
||||
///监听语言切换
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(localizedDidChange), name: SPLocalizedManager.localizedDidChange, object: nil)
|
||||
|
||||
let tabBarController = SPTabBarController()
|
||||
SPAPPTool.mainTabBarController = tabBarController
|
||||
|
||||
let hasOpenApp = UserDefaults.standard.object(forKey: kSPHasBeenOpenedAPPDefaultsKey) as? Bool
|
||||
///引导页
|
||||
let guideVc = SPGuideViewController()
|
||||
|
||||
///监听网路变化
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(reachabilityDidChangeNotification), name: SPNetworkReachabilityManager.reachabilityDidChangeNotification, object: nil)
|
||||
|
||||
window = UIWindow(windowScene: windowScene)
|
||||
if hasOpenApp != true && guideVc.lanuchVC != nil {
|
||||
SPAPPTool.isAppOpen = false
|
||||
guideVc.openAppBlock = {
|
||||
self.handleOpenApp()
|
||||
}
|
||||
window?.rootViewController = guideVc
|
||||
} else {
|
||||
SPAPPTool.isAppOpen = true
|
||||
window?.rootViewController = tabBarController
|
||||
}
|
||||
window?.makeKeyAndVisible()
|
||||
|
||||
|
||||
|
||||
startApp()
|
||||
|
||||
//在线状态统计
|
||||
timer = Timer.scheduledTimer(timeInterval: 60 * 10, target: self, selector: #selector(handleOnLine), userInfo: nil, repeats: true)
|
||||
}
|
||||
@ -84,27 +70,84 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
|
||||
extension SceneDelegate {
|
||||
|
||||
private func startApp() {
|
||||
let localizedManager = SPLocalizedManager.shared
|
||||
|
||||
///设置语言与当前的数据语言不同步时,需要重新获取语言后展示页面
|
||||
if localizedManager.localizedDataLocalizedKey != localizedManager.currentLocalizedKey, let lanuchVC = SPAPPTool.getLanuchViewController() {
|
||||
window?.rootViewController = lanuchVC
|
||||
window?.makeKeyAndVisible()
|
||||
|
||||
SPLocalizedManager.shared.updateLocalizedData { [weak self] finish in
|
||||
guard let self = self else { return }
|
||||
self.setRootVC()
|
||||
}
|
||||
|
||||
} else {
|
||||
SPLocalizedManager.shared.updateLocalizedData(completer: nil)
|
||||
|
||||
setRootVC()
|
||||
}
|
||||
}
|
||||
|
||||
///统计在线状态
|
||||
@objc private func handleOnLine() {
|
||||
SPStatAPI.requestStatOnLine()
|
||||
}
|
||||
|
||||
///打开app
|
||||
@objc private func handleOpenApp() {
|
||||
window?.rootViewController = SPAPPTool.mainTabBarController!
|
||||
window?.makeKeyAndVisible()
|
||||
private func setRootVC() {
|
||||
let hasOpenApp = UserDefaults.standard.object(forKey: kSPHasBeenOpenedAPPDefaultsKey) as? Bool
|
||||
///引导页
|
||||
let guideVc = SPGuideViewController()
|
||||
|
||||
handleOpenAppMessage(webpageURL: nil)
|
||||
|
||||
if hasOpenApp != true && guideVc.lanuchVC != nil {
|
||||
SPAPPTool.isAppOpen = false
|
||||
guideVc.openAppBlock = {
|
||||
self.handleOpenApp()
|
||||
}
|
||||
window?.rootViewController = guideVc
|
||||
window?.makeKeyAndVisible()
|
||||
|
||||
} else {
|
||||
SPAPPTool.isAppOpen = true
|
||||
setTabBarController()
|
||||
}
|
||||
}
|
||||
|
||||
///语言切换
|
||||
@objc private func localizedDidChange() {
|
||||
MJRefreshConfig.default.languageCode = SPLocalizedManager.shared.mjLocalizedKey
|
||||
|
||||
private func setTabBarController() {
|
||||
let tabBarController = SPTabBarController()
|
||||
SPAPPTool.mainTabBarController = tabBarController
|
||||
|
||||
window?.rootViewController = tabBarController
|
||||
window?.makeKeyAndVisible()
|
||||
}
|
||||
|
||||
///打开app
|
||||
@objc private func handleOpenApp() {
|
||||
setTabBarController()
|
||||
|
||||
handleOpenAppMessage(webpageURL: nil)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
extension SceneDelegate {
|
||||
///语言切换
|
||||
@objc private func localizedDidChange() {
|
||||
MJRefreshConfig.default.languageCode = SPLocalizedManager.shared.mjLocalizedKey
|
||||
|
||||
setTabBarController()
|
||||
}
|
||||
|
||||
///监听网络变化
|
||||
@objc private func reachabilityDidChangeNotification() {
|
||||
let localizedData = SPLocalizedManager.shared.localizedData ?? [:]
|
||||
|
||||
if SPNetworkReachabilityManager.manager.isReachable == true && localizedData.isEmpty {
|
||||
///缺少语言数据,重新获取语言数据
|
||||
self.startApp()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,9 @@ class SPNetworkReachabilityManager {
|
||||
if self.isReachable == false {
|
||||
print("++++++有网")
|
||||
self.isReachable = true
|
||||
NotificationCenter.default.post(name: SPNetworkReachabilityManager.reachabilityDidChangeNotification, object: nil)
|
||||
DispatchQueue.main.async {
|
||||
NotificationCenter.default.post(name: SPNetworkReachabilityManager.reachabilityDidChangeNotification, object: nil)
|
||||
}
|
||||
} else {
|
||||
self.isReachable = true
|
||||
}
|
||||
@ -64,7 +66,9 @@ class SPNetworkReachabilityManager {
|
||||
if self.isReachable == true {
|
||||
print("++++++无网")
|
||||
self.isReachable = false
|
||||
NotificationCenter.default.post(name: SPNetworkReachabilityManager.reachabilityDidChangeNotification, object: nil)
|
||||
DispatchQueue.main.async {
|
||||
NotificationCenter.default.post(name: SPNetworkReachabilityManager.reachabilityDidChangeNotification, object: nil)
|
||||
}
|
||||
} else {
|
||||
self.isReachable = false
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ class SPShortModel: SPModel, SmartCodable {
|
||||
var id: String?
|
||||
var all_coins: String?
|
||||
var buy_type: String?
|
||||
var collect_total: String?
|
||||
var collect_total: Int?
|
||||
var sp_description: String?
|
||||
var episode_total: Int?
|
||||
var horizontally_img: String?
|
||||
|
@ -40,7 +40,7 @@ class SPPlayLockView: UIView {
|
||||
let label = UILabel()
|
||||
label.font = .fontRegular(ofSize: 18)
|
||||
label.textColor = .colorFFFFFF()
|
||||
label.text = "movia_video_lock_tip".localized
|
||||
label.text = "movia_video_lock_tip_01".localized
|
||||
return label
|
||||
}()
|
||||
|
||||
|
@ -109,7 +109,8 @@ class SPPlayerControlView: UIView {
|
||||
|
||||
///收藏按钮
|
||||
private lazy var collectButton: UIButton = {
|
||||
let button = createFeatureButton(title: "movia_save".localized, selectedTitle: "movia_added".localized, image: UIImage(named: "collect_icon_01"), selectedImage: UIImage(named: "collect_icon_01_selected"))
|
||||
// let button = createFeatureButton(title: "movia_save".localized, selectedTitle: "movia_added".localized, image: UIImage(named: "collect_icon_01"), selectedImage: UIImage(named: "collect_icon_01_selected"))
|
||||
let button = createFeatureButton(title: "0", image: UIImage(named: "collect_icon_01"), selectedImage: UIImage(named: "collect_icon_01_selected"))
|
||||
button.addTarget(self, action: #selector(handleCollectButton), for: .touchUpInside)
|
||||
return button
|
||||
}()
|
||||
@ -235,7 +236,18 @@ extension SPPlayerControlView {
|
||||
|
||||
let isCollect = !(self.shortModel?.is_collect ?? false)
|
||||
|
||||
SPVideoAPI.requestCollectShort(isCollect: isCollect, shortPlayId: shortPlayId, videoId: videoId) {
|
||||
SPVideoAPI.requestCollectShort(isCollect: isCollect, shortPlayId: shortPlayId, videoId: videoId) { [weak self] in
|
||||
guard let self = self else { return }
|
||||
var count = self.shortModel?.collect_total ?? 0
|
||||
if isCollect {
|
||||
count += 1
|
||||
} else {
|
||||
count -= 1
|
||||
}
|
||||
if count < 0 {
|
||||
count = 0
|
||||
}
|
||||
self.shortModel?.collect_total = count
|
||||
}
|
||||
}
|
||||
|
||||
@ -252,6 +264,7 @@ extension SPPlayerControlView {
|
||||
|
||||
private func updateCollectButtonState() {
|
||||
self.collectButton.isSelected = self.shortModel?.is_collect ?? false
|
||||
self.collectButton.setTitle("\(self.shortModel?.collect_total ?? 0)", for: .normal)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import UIKit
|
||||
|
||||
class SPOrderRecordsPageViewController: SPViewController {
|
||||
|
||||
private lazy var titles: [String] = ["movia_Coin_Record".localized, "VIP Record".localized]
|
||||
private lazy var titles: [String] = ["movia_Coin_Record".localized, "movia_VIP_Record".localized]
|
||||
private lazy var viewControllers: [UIViewController] = {
|
||||
let vc1 = SPCoinOrderRecordViewController()
|
||||
let vc2 = SPVIPOrderRecordViewController()
|
||||
|
@ -13,8 +13,8 @@ class SPConsumptionRecordsCell: SPTableViewCell {
|
||||
didSet {
|
||||
titleLabel.text = "movia_Purchase_Single_Episode".localized
|
||||
timeLabel.text = model?.created_at
|
||||
desLabel.text = "Ep.\(model?.episode ?? "") \(model?.name ?? "")"
|
||||
let episode = String(format: "movia_text_episcode_ios".localized, "\(model?.episode ?? "0")") + "\(model?.name ?? "")"
|
||||
desLabel.text = episode
|
||||
coinLabel.text = "-\(model?.coins ?? 0) " + "movia_profile_Coins".localized
|
||||
}
|
||||
}
|
||||
|
@ -11,25 +11,41 @@ class SPLocalizedManager: NSObject {
|
||||
static let shared = SPLocalizedManager()
|
||||
private let LocalizedUserDefaultsKey = "SPLocalizedManager.LocalizedUserDefaultsKey"
|
||||
private let LocalizedDataUserDefaultsKey = "SPLocalizedManager.LocalizedDataUserDefaultsKey"
|
||||
|
||||
private let LocalizedDataLocalizedKeyUserDefaultsKey = "SPLocalizedManager.LocalizedDataLocalizedKeyUserDefaultsKey"
|
||||
|
||||
///语言列表
|
||||
var languageList: [SPLanguageModel]?
|
||||
|
||||
///多语言数据
|
||||
private lazy var localizedData: [String : String]? = UserDefaults.standard.object(forKey: LocalizedDataUserDefaultsKey) as? [String : String]
|
||||
private(set) lazy var localizedData: [String : String]? = UserDefaults.standard.object(forKey: LocalizedDataUserDefaultsKey) as? [String : String]
|
||||
{
|
||||
didSet {
|
||||
UserDefaults.standard.set(localizedData, forKey: LocalizedDataUserDefaultsKey)
|
||||
UserDefaults.standard.synchronize()
|
||||
}
|
||||
}
|
||||
///当前语言数据对应的key
|
||||
private(set) lazy var localizedDataLocalizedKey: String? = UserDefaults.standard.object(forKey: LocalizedDataLocalizedKeyUserDefaultsKey) as? String
|
||||
{
|
||||
didSet {
|
||||
UserDefaults.standard.set(localizedDataLocalizedKey, forKey: LocalizedDataLocalizedKeyUserDefaultsKey)
|
||||
UserDefaults.standard.synchronize()
|
||||
}
|
||||
}
|
||||
|
||||
// 获取当前语言代码(如果用户未手动设置,则返回系统语言)
|
||||
var currentLocalizedKey: String {
|
||||
get {
|
||||
// return UserDefaults.standard.string(forKey: userDefaultsKey) ?? Locale.preferredLanguages.first ?? "en"
|
||||
return UserDefaults.standard.string(forKey: LocalizedUserDefaultsKey) ?? "en"
|
||||
var key = (UserDefaults.standard.string(forKey: LocalizedUserDefaultsKey) ?? Locale.preferredLanguages.first) ?? "en"
|
||||
if key.contains("zh-Hans") {
|
||||
key = "zh"
|
||||
} else if key.contains("zh-Hant") {
|
||||
key = "zh_hk"
|
||||
} else {
|
||||
let arr = key.components(separatedBy: "-")
|
||||
key = arr.first ?? "en"
|
||||
}
|
||||
return key
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue, forKey: LocalizedUserDefaultsKey)
|
||||
@ -89,6 +105,7 @@ extension SPLocalizedManager {
|
||||
}
|
||||
|
||||
if let localizedData = model.translates {
|
||||
self.localizedDataLocalizedKey = key
|
||||
self.localizedData = localizedData
|
||||
completer?(true)
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user