temporarily disable pencil in-app-purchase for iOS14 and lower OS

This commit is contained in:
True Zhuanjia committed 2026-02-09 22:43:02 +08:00
1 parent 3973e13706
commit adbebd23c8
4 files changed
+116 -70

No files matched your search

+15 -11
View File
@@ -658,6 +658,15 @@ class PressureCurveViewController: UIViewController {
if interruption != .learnMore { if interruption != .learnMore {
resetTapped() resetTapped()
} }
if interruption == .lowOSVersion {
AlertControllerUtil.showAlert(
in: self,
title: "",
message: SwiftLocalizationHelper.localizedString(forKey:"PencilProPackLowOSVersionTip"),
withCancel: false,
buttonTitle: SwiftLocalizationHelper.localizedString(forKey: "OK"),
countdown: 0)
}
} }
@objc private func pressureRangeTest() { @objc private func pressureRangeTest() {
@@ -715,18 +724,13 @@ class PressureCurveViewController: UIViewController {
} }
@objc private func saveTapped() { @objc private func saveTapped() {
if #available(iOS 15.0, *) { IAPManager.checkPurchaseInfo(.PencilProPack) { info in
IAPManager.checkPurchaseInfo(.PencilProPack) { info in if info.valid {
if info.valid { self.persistCurve()
self.persistCurve() }
} else{
else{ IAPManager.inAppPurchaseAction(viewController: self, product: .PencilProPack)
IAPManager.inAppPurchaseAction(viewController: self, product: .PencilProPack)
}
} }
}
else {
return
} }
} }
@@ -5056,6 +5056,35 @@
"PencilProPackDescription" : { "PencilProPackDescription" : {
"extractionState" : "manual" "extractionState" : "manual"
}, },
"PencilProPackLowOSVersionTip" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Pencil Pro Pack is coming soon on iOS 12–14."
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "Pencil Pro Pack 即将支持 iOS 12–14。"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "translated",
"value" : "Pencil Pro Pack 即將支援 iOS 12–14。"
}
},
"zh-HK" : {
"stringUnit" : {
"state" : "translated",
"value" : "Pencil Pro Pack 即將支援 iOS 12–14。"
}
}
}
},
"PencilProPackURL" : { "PencilProPackURL" : {
"extractionState" : "manual", "extractionState" : "manual",
"localizations" : { "localizations" : {
+31 -28
View File
@@ -19,6 +19,7 @@ import StoreKit
case unlockNow case unlockNow
case restore case restore
case learnMore case learnMore
case lowOSVersion
} }
@objc public class PurchaseInfo: NSObject { @objc public class PurchaseInfo: NSObject {
@@ -221,21 +222,21 @@ import StoreKit
await transaction.finish() await transaction.finish()
NotificationCenter.default.post(name: product.purchaseSucceededNotification(), object: nil) NotificationCenter.default.post(name: product.purchaseSucceededNotification(), object: nil)
case .unverified(_, let err): case .unverified(_, let err):
NotificationCenter.default.post(name: product.purchaseAbortedNotification(), object: PurchaseInterruption.unlockNow) NotificationCenter.default.post(name: product.purchaseAbortedNotification(), object: PurchaseInterruption.unlockNow, userInfo:["interruption": PurchaseInterruption.unlockNow.rawValue])
await MainActor.run { await MainActor.run {
self.delegate?.iapManagerDidFailWithError(err) self.delegate?.iapManagerDidFailWithError(err)
} }
} }
case .userCancelled: case .userCancelled:
NotificationCenter.default.post(name: product.purchaseAbortedNotification(), object: PurchaseInterruption.unlockNow) NotificationCenter.default.post(name: product.purchaseAbortedNotification(), object: PurchaseInterruption.unlockNow, userInfo:["interruption": PurchaseInterruption.unlockNow.rawValue])
break break
default: default:
NotificationCenter.default.post(name: product.purchaseAbortedNotification(), object: PurchaseInterruption.unlockNow) NotificationCenter.default.post(name: product.purchaseAbortedNotification(), object: PurchaseInterruption.unlockNow, userInfo:["interruption": PurchaseInterruption.unlockNow.rawValue])
break break
} }
} catch { } catch {
await MainActor.run { await MainActor.run {
NotificationCenter.default.post(name: product.purchaseAbortedNotification(), object: PurchaseInterruption.unlockNow) NotificationCenter.default.post(name: product.purchaseAbortedNotification(), object: PurchaseInterruption.unlockNow, userInfo:["interruption": PurchaseInterruption.unlockNow.rawValue])
self.delegate?.iapManagerDidFailWithError(error) self.delegate?.iapManagerDidFailWithError(error)
} }
} }
@@ -301,36 +302,38 @@ import StoreKit
} }
// MARK: Utils // MARK: Utils
@available(iOS 15.0, *)
@objc static public func checkPurchaseInfo( @objc static public func checkPurchaseInfo(
_ product: AddOnProduct, _ product: AddOnProduct,
completion: @escaping (PurchaseInfo) -> Void completion: @escaping (PurchaseInfo) -> Void
) { ) {
let productID = product.productId() let productID = product.productId()
Task { if #available(iOS 15.0, *) {
var status: PurchaseStatus = .notPurchased Task {
var expiration: Date? = nil var status: PurchaseStatus = .notPurchased
var expiration: Date? = nil
for await verificationResult in Transaction.currentEntitlements { for await verificationResult in Transaction.currentEntitlements {
if case .verified(let transaction) = verificationResult, if case .verified(let transaction) = verificationResult,
transaction.productID == productID { transaction.productID == productID {
// 有退款 / 撤销 // 有退款 / 撤销
if transaction.revocationDate != nil { if transaction.revocationDate != nil {
status = .revoked status = .revoked
} else { } else {
status = .purchased status = .purchased
expiration = transaction.expirationDate expiration = transaction.expirationDate
}
break
} }
break }
let info = PurchaseInfo(status: status, expirationDate: expiration as NSDate?)
await MainActor.run {
completion(info)
} }
} }
}
let info = PurchaseInfo(status: status, expirationDate: expiration as NSDate?) else {
NotificationCenter.default.post(name: product.purchaseAbortedNotification(), object: PurchaseInterruption.lowOSVersion, userInfo:["interruption": PurchaseInterruption.lowOSVersion.rawValue])
await MainActor.run {
completion(info)
}
} }
} }
@@ -365,7 +368,7 @@ import StoreKit
// Fallback on earlier versions // Fallback on earlier versions
} }
} catch { } catch {
NotificationCenter.default.post(name: product.purchaseAbortedNotification(), object: PurchaseInterruption.restore) NotificationCenter.default.post(name: product.purchaseAbortedNotification(), object: PurchaseInterruption.restore, userInfo:["interruption": PurchaseInterruption.restore.rawValue])
print("Restore failed: \(error)") print("Restore failed: \(error)")
} }
} }
@@ -375,7 +378,7 @@ import StoreKit
} }
let learnMoreAction = UIAlertAction(title: SwiftLocalizationHelper.localizedString(forKey: "Learn More"), style: .default) { _ in let learnMoreAction = UIAlertAction(title: SwiftLocalizationHelper.localizedString(forKey: "Learn More"), style: .default) { _ in
NotificationCenter.default.post(name: product.purchaseAbortedNotification(), object: PurchaseInterruption.learnMore) NotificationCenter.default.post(name: product.purchaseAbortedNotification(), object: PurchaseInterruption.learnMore, userInfo:["interruption": PurchaseInterruption.learnMore.rawValue])
if let url = URL(string: product.productURL()) { if let url = URL(string: product.productURL()) {
UIApplication.shared.open(url, options: [:], completionHandler: nil) UIApplication.shared.open(url, options: [:], completionHandler: nil)
} }
@@ -475,7 +475,7 @@ BOOL isCustomResolution(int resolutionSelected) {
name:@"OscLayoutCloseNotification" name:@"OscLayoutCloseNotification"
object:nil]; object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(pencilProPurchaseAborted) selector:@selector(pencilProPurchaseAborted:)
name:@"PencilProPurchaseAbortedNotification" name:@"PencilProPurchaseAbortedNotification"
object:nil]; object:nil];
@@ -3381,23 +3381,39 @@ BOOL isCustomResolution(int resolutionSelected) {
if(settingsViewJustExpanded) return; if(settingsViewJustExpanded) return;
if (@available(iOS 15.0, *)) { if(sender.selectedSegmentIndex != ManualTick) return;
if(sender.selectedSegmentIndex != ManualTick) return; [IAPManager checkPurchaseInfo:AddOnProductPencilProPack completion:^(PurchaseInfo* info) {
[IAPManager checkPurchaseInfo:AddOnProductPencilProPack completion:^(PurchaseInfo* info) { if(!info.valid){
if(!info.valid){ [IAPManager inAppPurchaseActionWithViewController:self product:AddOnProductPencilProPack];
[IAPManager inAppPurchaseActionWithViewController:self product:AddOnProductPencilProPack]; }
} }];
}];
}
} }
- (void)pencilProPurchaseAborted{ - (void)pencilProPurchaseAborted:(NSNotification *)notification{
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
self.pencilTickSelector.selectedSegmentIndex = PencilTickDisabled; self.pencilTickSelector.selectedSegmentIndex = PencilTickDisabled;
[self pencilTickModeChanged:self.pencilTickSelector]; [self pencilTickModeChanged:self.pencilTickSelector];
[self.pressureCurveSwitch setOn:false];
[self.doubleTapShortcutSwitch setOn:false]; [self.doubleTapShortcutSwitch setOn:false];
[self.pencilPausesNativeTouchSwitch setOn:false]; [self.pencilPausesNativeTouchSwitch setOn:false];
[self.disablePencilSlideGestureSwitch setOn:false]; [self.disablePencilSlideGestureSwitch setOn:false];
NSNumber *value = notification.userInfo[@"interruption"];
if (!value) return;
PurchaseInterruption interruption = value.intValue;
if(interruption == PurchaseInterruptionLowOSVersion){
[AlertControllerUtil showAlertIn:self
title:@""
message:[LocalizationHelper localizedStringForKey:@"PencilProPackLowOSVersionTip"]
withCancel:NO
buttonTitle:[LocalizationHelper localizedStringForKey:@"OK"]
countdown:0
action:nil
completion:nil];
}
}); });
} }
@@ -3416,37 +3432,31 @@ BOOL isCustomResolution(int resolutionSelected) {
- (void)doubleTapShortcutSwitchFlipped:(UISwitch* )sender{ - (void)doubleTapShortcutSwitchFlipped:(UISwitch* )sender{
if(sender.isOn && !settingsViewJustLoaded){ if(sender.isOn && !settingsViewJustLoaded){
if (@available(iOS 15.0, *)) { [IAPManager checkPurchaseInfo:AddOnProductPencilProPack completion:^(PurchaseInfo* info) {
[IAPManager checkPurchaseInfo:AddOnProductPencilProPack completion:^(PurchaseInfo* info) { if(info.valid) [PencilHandler enterDoubleTapShortcutsIn:self];
if(info.valid) [PencilHandler enterDoubleTapShortcutsIn:self]; else {
else { [IAPManager inAppPurchaseActionWithViewController:self product:AddOnProductPencilProPack];
[IAPManager inAppPurchaseActionWithViewController:self product:AddOnProductPencilProPack]; }
} }];
}];
}
} }
} }
- (void)disablePencilSlideGestureSwitchFlipped:(UISwitch* )sender{ - (void)disablePencilSlideGestureSwitchFlipped:(UISwitch* )sender{
if(sender.isOn && !settingsViewJustLoaded){ if(sender.isOn && !settingsViewJustLoaded){
if (@available(iOS 15.0, *)) { [IAPManager checkPurchaseInfo:AddOnProductPencilProPack completion:^(PurchaseInfo* info) {
[IAPManager checkPurchaseInfo:AddOnProductPencilProPack completion:^(PurchaseInfo* info) { if(info.valid) nil;
if(info.valid) nil; else {
else { [IAPManager inAppPurchaseActionWithViewController:self product:AddOnProductPencilProPack];
[IAPManager inAppPurchaseActionWithViewController:self product:AddOnProductPencilProPack]; }
} }];
}];
}
} }
} }
- (void)pencilPausesNativeTouchSwitchFlipped:(UISwitch* )sender{ - (void)pencilPausesNativeTouchSwitchFlipped:(UISwitch* )sender{
if(sender.isOn && !settingsViewJustLoaded){ if(sender.isOn && !settingsViewJustLoaded){
if (@available(iOS 15.0, *)) { [IAPManager checkPurchaseInfo:AddOnProductPencilProPack completion:^(PurchaseInfo* info) {
[IAPManager checkPurchaseInfo:AddOnProductPencilProPack completion:^(PurchaseInfo* info) { if(!info.valid) [IAPManager inAppPurchaseActionWithViewController:self product:AddOnProductPencilProPack];
if(!info.valid) [IAPManager inAppPurchaseActionWithViewController:self product:AddOnProductPencilProPack]; }];
}];
}
} }
} }