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
+70 -24

No files matched your search

+9 -5
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,7 +724,6 @@ 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()
@@ -725,10 +733,6 @@ class PressureCurveViewController: UIViewController {
} }
} }
} }
else {
return
}
}
@objc private func exitTapped() { @objc private func exitTapped() {
self.dismiss(animated: true) self.dismiss(animated: true)
@@ -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" : {
+12 -9
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,16 +302,15 @@ 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()
if #available(iOS 15.0, *) {
Task { Task {
var status: PurchaseStatus = .notPurchased var status: PurchaseStatus = .notPurchased
var expiration: Date? = nil 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 {
@@ -325,7 +325,6 @@ import StoreKit
break break
} }
} }
let info = PurchaseInfo(status: status, expirationDate: expiration as NSDate?) let info = PurchaseInfo(status: status, expirationDate: expiration as NSDate?)
await MainActor.run { await MainActor.run {
@@ -333,6 +332,10 @@ import StoreKit
} }
} }
} }
else {
NotificationCenter.default.post(name: product.purchaseAbortedNotification(), object: PurchaseInterruption.lowOSVersion, userInfo:["interruption": PurchaseInterruption.lowOSVersion.rawValue])
}
}
@available(iOS 15.0, *) @available(iOS 15.0, *)
static public func checkPurchaseInfo( static public func checkPurchaseInfo(
@@ -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,7 +3432,6 @@ 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 {
@@ -3424,12 +3439,10 @@ BOOL isCustomResolution(int resolutionSelected) {
} }
}]; }];
} }
}
} }
- (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 {
@@ -3437,17 +3450,14 @@ BOOL isCustomResolution(int resolutionSelected) {
} }
}]; }];
} }
}
} }
- (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];
}]; }];
} }
}
} }
- (void)loadPencilSettings:(TemporarySettings*) tempSettings{ - (void)loadPencilSettings:(TemporarySettings*) tempSettings{