添加捐赠功能

This commit is contained in:
Fin 2024-11-13 17:34:30 +08:00
parent 1f7360a164
commit 9e1578ed0a
7 changed files with 155 additions and 8 deletions

View File

@ -8,6 +8,7 @@
import CrashReporter
import IQKeyboardManagerSwift
import SwiftyStoreKit
import UIKit
import UserNotifications
@ -114,6 +115,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
bar.backIndicatorTransitionMaskImage = UIImage(named: "back")
bar.tintColor = BKColor.grey.darken4
//
SwiftyStoreKit.completeTransactions { _ in }
return true
}

View File

@ -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" : {
"extractionState" : "manual",
"localizations" : {
@ -2160,12 +2194,12 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : ""
"value" : "Do not enter or enter the old Key"
}
},
"tr" : {
"stringUnit" : {
"state" : "translated",
"state" : "needs_review",
"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" : {
"extractionState" : "manual",
"localizations" : {

View File

@ -10,6 +10,8 @@ import Material
import RxCocoa
import RxDataSources
import RxSwift
import SVProgressHUD
import SwiftyStoreKit
import UIKit
import UniformTypeIdentifiers
@ -36,7 +38,7 @@ class MessageSettingsViewController: BaseViewController<MessageSettingsViewModel
}()
private var headers: [String?] = []
private var footers: [String?] = []
private var footers: [MessageSettingSectionFooterProtocol?] = []
override func makeUI() {
self.title = NSLocalizedString("settings")
@ -45,6 +47,24 @@ class MessageSettingsViewController: BaseViewController<MessageSettingsViewModel
tableView.snp.makeConstraints { make in
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() }
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
}
}

View File

@ -169,7 +169,13 @@ class MessageSettingsViewModel: ViewModel, ViewModelType {
donateSettings.append(.donate(title: NSLocalizedString("continuousSupport"), productId: "bark.continuousSupport.18"))
settings.append(
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
)
)
@ -242,7 +248,27 @@ enum MessageSettingItem {
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 {
var header: String?
var footer: String?
var footer: MessageSettingSectionFooterProtocol?
}

View File

@ -31,6 +31,7 @@ def pods
pod 'DropDown'
pod 'PLCrashReporter'
pod 'SwiftyStoreKit'
end
target 'Bark' do

View File

@ -50,6 +50,7 @@ PODS:
- SVProgressHUD/Core (= 2.3.1)
- SVProgressHUD/Core (2.3.1)
- SwiftyJSON (5.0.2)
- SwiftyStoreKit (0.16.1)
DEPENDENCIES:
- CryptoSwift
@ -75,6 +76,7 @@ DEPENDENCIES:
- SnapKit
- SVProgressHUD
- SwiftyJSON
- SwiftyStoreKit
SPEC REPOS:
trunk:
@ -104,6 +106,7 @@ SPEC REPOS:
- SnapKit
- SVProgressHUD
- SwiftyJSON
- SwiftyStoreKit
EXTERNAL SOURCES:
DefaultsKit:
@ -148,7 +151,8 @@ SPEC CHECKSUMS:
SnapKit: d612e99e678a2d3b95bf60b0705ed0a35c03484a
SVProgressHUD: 4837c74bdfe2e51e8821c397825996a8d7de6e22
SwiftyJSON: f5b1bf1cd8dd53cd25887ac0eabcfd92301c6a5a
SwiftyStoreKit: 6b9c08810269f030586dac1fae8e75871a82e84a
PODFILE CHECKSUM: c9560d9c6653dd0da638d1f49876c91a02632de6
PODFILE CHECKSUM: c61d77544f2f3b62338f3ccb60fa5e617632a6c0
COCOAPODS: 1.16.2

View File

@ -6,6 +6,7 @@
// Copyright © 2024 Fin. All rights reserved.
//
import SwiftyStoreKit
import UIKit
class DonateCell: UITableViewCell {
@ -17,7 +18,19 @@ class DonateCell: UITableViewCell {
var productId: String? = nil {
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
}
}
}
}