mirror of
https://github.com/Finb/Bark.git
synced 2025-12-08 21:36:01 +00:00
添加捐赠功能
This commit is contained in:
parent
1f7360a164
commit
9e1578ed0a
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
import CrashReporter
|
import CrashReporter
|
||||||
import IQKeyboardManagerSwift
|
import IQKeyboardManagerSwift
|
||||||
|
import SwiftyStoreKit
|
||||||
import UIKit
|
import UIKit
|
||||||
import UserNotifications
|
import UserNotifications
|
||||||
|
|
||||||
@ -114,6 +115,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
|
|||||||
bar.backIndicatorTransitionMaskImage = UIImage(named: "back")
|
bar.backIndicatorTransitionMaskImage = UIImage(named: "back")
|
||||||
bar.tintColor = BKColor.grey.darken4
|
bar.tintColor = BKColor.grey.darken4
|
||||||
|
|
||||||
|
// 内购
|
||||||
|
SwiftyStoreKit.completeTransactions { _ in }
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1068,6 +1068,40 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"donate" : {
|
||||||
|
"extractionState" : "manual",
|
||||||
|
"localizations" : {
|
||||||
|
"en" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "Donate"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"zh-Hans" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "捐赠"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"donateOK" : {
|
||||||
|
"extractionState" : "manual",
|
||||||
|
"localizations" : {
|
||||||
|
"en" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "🤝"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"zh-Hans" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "小意思~"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"done" : {
|
"done" : {
|
||||||
"extractionState" : "manual",
|
"extractionState" : "manual",
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
@ -2160,12 +2194,12 @@
|
|||||||
"en" : {
|
"en" : {
|
||||||
"stringUnit" : {
|
"stringUnit" : {
|
||||||
"state" : "translated",
|
"state" : "translated",
|
||||||
"value" : ""
|
"value" : "Do not enter or enter the old Key"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tr" : {
|
"tr" : {
|
||||||
"stringUnit" : {
|
"stringUnit" : {
|
||||||
"state" : "translated",
|
"state" : "needs_review",
|
||||||
"value" : ""
|
"value" : ""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -2492,6 +2526,40 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"successfulDonation" : {
|
||||||
|
"extractionState" : "manual",
|
||||||
|
"localizations" : {
|
||||||
|
"en" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "Successful donation"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"zh-Hans" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "成功捐赠"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"thankYouSupport" : {
|
||||||
|
"extractionState" : "manual",
|
||||||
|
"localizations" : {
|
||||||
|
"en" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "Thank you for your kind support"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"zh-Hans" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "谢谢你的慷慨支持"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"timeHourAgo" : {
|
"timeHourAgo" : {
|
||||||
"extractionState" : "manual",
|
"extractionState" : "manual",
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
|
|||||||
@ -10,6 +10,8 @@ import Material
|
|||||||
import RxCocoa
|
import RxCocoa
|
||||||
import RxDataSources
|
import RxDataSources
|
||||||
import RxSwift
|
import RxSwift
|
||||||
|
import SVProgressHUD
|
||||||
|
import SwiftyStoreKit
|
||||||
import UIKit
|
import UIKit
|
||||||
import UniformTypeIdentifiers
|
import UniformTypeIdentifiers
|
||||||
|
|
||||||
@ -36,7 +38,7 @@ class MessageSettingsViewController: BaseViewController<MessageSettingsViewModel
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
private var headers: [String?] = []
|
private var headers: [String?] = []
|
||||||
private var footers: [String?] = []
|
private var footers: [MessageSettingSectionFooterProtocol?] = []
|
||||||
|
|
||||||
override func makeUI() {
|
override func makeUI() {
|
||||||
self.title = NSLocalizedString("settings")
|
self.title = NSLocalizedString("settings")
|
||||||
@ -45,6 +47,24 @@ class MessageSettingsViewController: BaseViewController<MessageSettingsViewModel
|
|||||||
tableView.snp.makeConstraints { make in
|
tableView.snp.makeConstraints { make in
|
||||||
make.edges.equalToSuperview()
|
make.edges.equalToSuperview()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 捐赠内购没有任何逻辑,就不往 ViewModel 里放了,在这里处理一下得了
|
||||||
|
self.tableView.rx.modelSelected(MessageSettingItem.self).asObservable().compactMap { item in
|
||||||
|
if case .donate(_, let productId) = item {
|
||||||
|
return productId
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}.subscribe(onNext: { [weak self] productId in
|
||||||
|
SVProgressHUD.show()
|
||||||
|
SwiftyStoreKit.purchaseProduct(productId) { result in
|
||||||
|
SVProgressHUD.dismiss()
|
||||||
|
if case .success = result {
|
||||||
|
let alert = UIAlertController(title: NSLocalizedString("successfulDonation"), message: NSLocalizedString("thankYouSupport"), preferredStyle: .alert)
|
||||||
|
alert.addAction(UIAlertAction(title: NSLocalizedString("donateOK"), style: .default, handler: nil))
|
||||||
|
self?.present(alert, animated: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).disposed(by: rx.disposeBag)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 导入、导出操作枚举
|
/// 导入、导出操作枚举
|
||||||
@ -270,7 +290,19 @@ extension MessageSettingsViewController: UITableViewDelegate {
|
|||||||
guard self.footers.count > section, let footer = self.footers[section] else { return UIView() }
|
guard self.footers.count > section, let footer = self.footers[section] else { return UIView() }
|
||||||
|
|
||||||
let footerView = SettingSectionFooter()
|
let footerView = SettingSectionFooter()
|
||||||
footerView.titleLabel.text = footer
|
footerView.titleLabel.text = footer.title
|
||||||
|
if let footerUrl = footer.url, let url = URL(string: footerUrl) {
|
||||||
|
footerView.titleLabel.numberOfLines = 0
|
||||||
|
footerView.titleLabel.minimumScaleFactor = 0.5
|
||||||
|
footerView.titleLabel.adjustsFontSizeToFitWidth = true
|
||||||
|
|
||||||
|
// 点击跳转
|
||||||
|
let tap = UITapGestureRecognizer()
|
||||||
|
footerView.addGestureRecognizer(tap)
|
||||||
|
tap.rx.event.asControlEvent().subscribe(onNext: { [weak self] _ in
|
||||||
|
self?.navigationController?.present(BarkSFSafariViewController(url: url), animated: true, completion: nil)
|
||||||
|
}).disposed(by: footerView.rx.disposeBag)
|
||||||
|
}
|
||||||
return footerView
|
return footerView
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -169,7 +169,13 @@ class MessageSettingsViewModel: ViewModel, ViewModelType {
|
|||||||
donateSettings.append(.donate(title: NSLocalizedString("continuousSupport"), productId: "bark.continuousSupport.18"))
|
donateSettings.append(.donate(title: NSLocalizedString("continuousSupport"), productId: "bark.continuousSupport.18"))
|
||||||
settings.append(
|
settings.append(
|
||||||
SectionModel(
|
SectionModel(
|
||||||
model: MessageSettingSection(header: "Donate"),
|
model: MessageSettingSection(
|
||||||
|
header: NSLocalizedString("donate"),
|
||||||
|
footer: MessageSettingSectionFooter(
|
||||||
|
title: "LICENSED APPLICATION END USER LICENSE AGREEMENT",
|
||||||
|
url: "https://www.apple.com/legal/internet-services/itunes/dev/stdeula/"
|
||||||
|
)
|
||||||
|
),
|
||||||
items: donateSettings
|
items: donateSettings
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -242,7 +248,27 @@ enum MessageSettingItem {
|
|||||||
case donate(title: String, productId: String)
|
case donate(title: String, productId: String)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protocol MessageSettingSectionFooterProtocol {
|
||||||
|
var title: String? { get }
|
||||||
|
var url: String? { get }
|
||||||
|
}
|
||||||
|
|
||||||
|
extension String: MessageSettingSectionFooterProtocol {
|
||||||
|
var title: String? {
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
|
||||||
|
var url: String? {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct MessageSettingSectionFooter: MessageSettingSectionFooterProtocol {
|
||||||
|
var title: String?
|
||||||
|
var url: String?
|
||||||
|
}
|
||||||
|
|
||||||
struct MessageSettingSection {
|
struct MessageSettingSection {
|
||||||
var header: String?
|
var header: String?
|
||||||
var footer: String?
|
var footer: MessageSettingSectionFooterProtocol?
|
||||||
}
|
}
|
||||||
|
|||||||
1
Podfile
1
Podfile
@ -31,6 +31,7 @@ def pods
|
|||||||
pod 'DropDown'
|
pod 'DropDown'
|
||||||
|
|
||||||
pod 'PLCrashReporter'
|
pod 'PLCrashReporter'
|
||||||
|
pod 'SwiftyStoreKit'
|
||||||
end
|
end
|
||||||
|
|
||||||
target 'Bark' do
|
target 'Bark' do
|
||||||
|
|||||||
@ -50,6 +50,7 @@ PODS:
|
|||||||
- SVProgressHUD/Core (= 2.3.1)
|
- SVProgressHUD/Core (= 2.3.1)
|
||||||
- SVProgressHUD/Core (2.3.1)
|
- SVProgressHUD/Core (2.3.1)
|
||||||
- SwiftyJSON (5.0.2)
|
- SwiftyJSON (5.0.2)
|
||||||
|
- SwiftyStoreKit (0.16.1)
|
||||||
|
|
||||||
DEPENDENCIES:
|
DEPENDENCIES:
|
||||||
- CryptoSwift
|
- CryptoSwift
|
||||||
@ -75,6 +76,7 @@ DEPENDENCIES:
|
|||||||
- SnapKit
|
- SnapKit
|
||||||
- SVProgressHUD
|
- SVProgressHUD
|
||||||
- SwiftyJSON
|
- SwiftyJSON
|
||||||
|
- SwiftyStoreKit
|
||||||
|
|
||||||
SPEC REPOS:
|
SPEC REPOS:
|
||||||
trunk:
|
trunk:
|
||||||
@ -104,6 +106,7 @@ SPEC REPOS:
|
|||||||
- SnapKit
|
- SnapKit
|
||||||
- SVProgressHUD
|
- SVProgressHUD
|
||||||
- SwiftyJSON
|
- SwiftyJSON
|
||||||
|
- SwiftyStoreKit
|
||||||
|
|
||||||
EXTERNAL SOURCES:
|
EXTERNAL SOURCES:
|
||||||
DefaultsKit:
|
DefaultsKit:
|
||||||
@ -148,7 +151,8 @@ SPEC CHECKSUMS:
|
|||||||
SnapKit: d612e99e678a2d3b95bf60b0705ed0a35c03484a
|
SnapKit: d612e99e678a2d3b95bf60b0705ed0a35c03484a
|
||||||
SVProgressHUD: 4837c74bdfe2e51e8821c397825996a8d7de6e22
|
SVProgressHUD: 4837c74bdfe2e51e8821c397825996a8d7de6e22
|
||||||
SwiftyJSON: f5b1bf1cd8dd53cd25887ac0eabcfd92301c6a5a
|
SwiftyJSON: f5b1bf1cd8dd53cd25887ac0eabcfd92301c6a5a
|
||||||
|
SwiftyStoreKit: 6b9c08810269f030586dac1fae8e75871a82e84a
|
||||||
|
|
||||||
PODFILE CHECKSUM: c9560d9c6653dd0da638d1f49876c91a02632de6
|
PODFILE CHECKSUM: c61d77544f2f3b62338f3ccb60fa5e617632a6c0
|
||||||
|
|
||||||
COCOAPODS: 1.16.2
|
COCOAPODS: 1.16.2
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
// Copyright © 2024 Fin. All rights reserved.
|
// Copyright © 2024 Fin. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
import SwiftyStoreKit
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class DonateCell: UITableViewCell {
|
class DonateCell: UITableViewCell {
|
||||||
@ -17,7 +18,19 @@ class DonateCell: UITableViewCell {
|
|||||||
|
|
||||||
var productId: String? = nil {
|
var productId: String? = nil {
|
||||||
didSet {
|
didSet {
|
||||||
self.detailTextLabel?.text = ""
|
guard let productId else { return }
|
||||||
|
if let cachePriceStr = Settings["bark.price.\(productId)"] {
|
||||||
|
self.detailTextLabel?.text = cachePriceStr
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 查询价格
|
||||||
|
SwiftyStoreKit.retrieveProductsInfo([productId]) { result in
|
||||||
|
if let product = result.retrievedProducts.first, let price = product.localizedPrice {
|
||||||
|
let priceStr = price + (product.localizedSubscriptionPeriod.isEmpty ? "" : " / \(product.localizedSubscriptionPeriod)")
|
||||||
|
Settings["bark.price.\(productId)"] = priceStr
|
||||||
|
self.detailTextLabel?.text = priceStr
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user