Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft. #8088

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

draft. #8088

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.20+1

* Disallow enabling StoreKit2 on devices below iOS 15, or OSX 15.

## 0.3.20

* Fixes manual invocation of `finishTransaction` causing a fatal crash.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,16 @@ public class InAppPurchasePlugin: NSObject, FlutterPlugin, FIAInAppPurchaseAPI {
NSLog("Received an updatedDownloads callback, but downloads are not supported.")
}

public func supportsStoreKit2WithError(_ error: AutoreleasingUnsafeMutablePointer<FlutterError?>)
-> NSNumber?
{
if #available(iOS 15, macOS 15, *) {
return true
}
NSLog("This device does not support StoreKit2. Falling back to the original StoreKit.")
return false
}

// MARK: - Methods exposed for testing
func getProduct(productID: String) -> SKProduct? {
return self.productsCache[productID] as? SKProduct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class PigeonError: Error {
var localizedDescription: String {
return
"PigeonError(code: \(code), message: \(message ?? "<nil>"), details: \(details ?? "<nil>")"
}
}
}

private func wrapResult(_ result: Any?) -> [Any?] {
Expand Down Expand Up @@ -59,9 +59,7 @@ private func wrapError(_ error: Any) -> [Any?] {
}

private func createConnectionError(withChannelName channelName: String) -> PigeonError {
return PigeonError(
code: "channel-error", message: "Unable to establish connection on channel: '\(channelName)'.",
details: "")
return PigeonError(code: "channel-error", message: "Unable to establish connection on channel: '\(channelName)'.", details: "")
}

private func isNullish(_ value: Any?) -> Bool {
Expand Down Expand Up @@ -117,6 +115,8 @@ struct SK2SubscriptionOfferMessage {
var periodCount: Int64
var paymentMode: SK2SubscriptionOfferPaymentModeMessage



// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> SK2SubscriptionOfferMessage? {
let id: String? = nilOrValue(pigeonVar_list[0])
Expand Down Expand Up @@ -154,6 +154,8 @@ struct SK2SubscriptionPeriodMessage {
/// The unit of time that this period represents.
var unit: SK2SubscriptionPeriodUnitMessage



// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> SK2SubscriptionPeriodMessage? {
let value = pigeonVar_list[0] as! Int64
Expand Down Expand Up @@ -181,6 +183,8 @@ struct SK2SubscriptionInfoMessage {
/// The duration that this subscription lasts before auto-renewing.
var subscriptionPeriod: SK2SubscriptionPeriodMessage



// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> SK2SubscriptionInfoMessage? {
let promotionalOffers = pigeonVar_list[0] as! [SK2SubscriptionOfferMessage]
Expand Down Expand Up @@ -224,6 +228,8 @@ struct SK2ProductMessage {
/// The currency and locale information for this product
var priceLocale: SK2PriceLocaleMessage



// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> SK2ProductMessage? {
let id = pigeonVar_list[0] as! String
Expand Down Expand Up @@ -265,6 +271,8 @@ struct SK2PriceLocaleMessage {
var currencyCode: String
var currencySymbol: String



// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> SK2PriceLocaleMessage? {
let currencyCode = pigeonVar_list[0] as! String
Expand All @@ -288,6 +296,8 @@ struct SK2ProductPurchaseOptionsMessage {
var appAccountToken: String? = nil
var quantity: Int64? = nil



// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> SK2ProductPurchaseOptionsMessage? {
let appAccountToken: String? = nilOrValue(pigeonVar_list[0])
Expand Down Expand Up @@ -319,6 +329,8 @@ struct SK2TransactionMessage {
var receiptData: String? = nil
var error: SK2ErrorMessage? = nil



// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> SK2TransactionMessage? {
let id = pigeonVar_list[0] as! Int64
Expand Down Expand Up @@ -367,6 +379,8 @@ struct SK2ErrorMessage {
var domain: String
var userInfo: [String: Any]? = nil



// swift-format-ignore: AlwaysUseLowerCamelCase
static func fromList(_ pigeonVar_list: [Any?]) -> SK2ErrorMessage? {
let code = pigeonVar_list[0] as! Int64
Expand Down Expand Up @@ -504,34 +518,27 @@ class sk2_pigeonPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable {
static let shared = sk2_pigeonPigeonCodec(readerWriter: sk2_pigeonPigeonCodecReaderWriter())
}


/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
protocol InAppPurchase2API {
func canMakePayments() throws -> Bool
func products(
identifiers: [String], completion: @escaping (Result<[SK2ProductMessage], Error>) -> Void)
func purchase(
id: String, options: SK2ProductPurchaseOptionsMessage?,
completion: @escaping (Result<SK2ProductPurchaseResultMessage, Error>) -> Void)
func products(identifiers: [String], completion: @escaping (Result<[SK2ProductMessage], Error>) -> Void)
func purchase(id: String, options: SK2ProductPurchaseOptionsMessage?, completion: @escaping (Result<SK2ProductPurchaseResultMessage, Error>) -> Void)
func transactions(completion: @escaping (Result<[SK2TransactionMessage], Error>) -> Void)
func finish(id: Int64, completion: @escaping (Result<Void, Error>) -> Void)
func startListeningToTransactions() throws
func stopListeningToTransactions() throws
func restorePurchases(completion: @escaping (Result<Void, Error>) -> Void)
func supportsStoreKit2() throws -> Bool
}

/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
class InAppPurchase2APISetup {
static var codec: FlutterStandardMessageCodec { sk2_pigeonPigeonCodec.shared }
/// Sets up an instance of `InAppPurchase2API` to handle messages through the `binaryMessenger`.
static func setUp(
binaryMessenger: FlutterBinaryMessenger, api: InAppPurchase2API?,
messageChannelSuffix: String = ""
) {
static func setUp(binaryMessenger: FlutterBinaryMessenger, api: InAppPurchase2API?, messageChannelSuffix: String = "") {
let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : ""
let canMakePaymentsChannel = FlutterBasicMessageChannel(
name:
"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.canMakePayments\(channelSuffix)",
binaryMessenger: binaryMessenger, codec: codec)
let canMakePaymentsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.canMakePayments\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
canMakePaymentsChannel.setMessageHandler { _, reply in
do {
Expand All @@ -544,10 +551,7 @@ class InAppPurchase2APISetup {
} else {
canMakePaymentsChannel.setMessageHandler(nil)
}
let productsChannel = FlutterBasicMessageChannel(
name:
"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.products\(channelSuffix)",
binaryMessenger: binaryMessenger, codec: codec)
let productsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.products\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
productsChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
Expand All @@ -564,10 +568,7 @@ class InAppPurchase2APISetup {
} else {
productsChannel.setMessageHandler(nil)
}
let purchaseChannel = FlutterBasicMessageChannel(
name:
"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.purchase\(channelSuffix)",
binaryMessenger: binaryMessenger, codec: codec)
let purchaseChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.purchase\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
purchaseChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
Expand All @@ -585,10 +586,7 @@ class InAppPurchase2APISetup {
} else {
purchaseChannel.setMessageHandler(nil)
}
let transactionsChannel = FlutterBasicMessageChannel(
name:
"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.transactions\(channelSuffix)",
binaryMessenger: binaryMessenger, codec: codec)
let transactionsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.transactions\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
transactionsChannel.setMessageHandler { _, reply in
api.transactions { result in
Expand All @@ -603,9 +601,7 @@ class InAppPurchase2APISetup {
} else {
transactionsChannel.setMessageHandler(nil)
}
let finishChannel = FlutterBasicMessageChannel(
name: "dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.finish\(channelSuffix)",
binaryMessenger: binaryMessenger, codec: codec)
let finishChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.finish\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
finishChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
Expand All @@ -622,10 +618,7 @@ class InAppPurchase2APISetup {
} else {
finishChannel.setMessageHandler(nil)
}
let startListeningToTransactionsChannel = FlutterBasicMessageChannel(
name:
"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.startListeningToTransactions\(channelSuffix)",
binaryMessenger: binaryMessenger, codec: codec)
let startListeningToTransactionsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.startListeningToTransactions\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
startListeningToTransactionsChannel.setMessageHandler { _, reply in
do {
Expand All @@ -638,10 +631,7 @@ class InAppPurchase2APISetup {
} else {
startListeningToTransactionsChannel.setMessageHandler(nil)
}
let stopListeningToTransactionsChannel = FlutterBasicMessageChannel(
name:
"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.stopListeningToTransactions\(channelSuffix)",
binaryMessenger: binaryMessenger, codec: codec)
let stopListeningToTransactionsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.stopListeningToTransactions\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
stopListeningToTransactionsChannel.setMessageHandler { _, reply in
do {
Expand All @@ -654,10 +644,7 @@ class InAppPurchase2APISetup {
} else {
stopListeningToTransactionsChannel.setMessageHandler(nil)
}
let restorePurchasesChannel = FlutterBasicMessageChannel(
name:
"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.restorePurchases\(channelSuffix)",
binaryMessenger: binaryMessenger, codec: codec)
let restorePurchasesChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.restorePurchases\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
restorePurchasesChannel.setMessageHandler { _, reply in
api.restorePurchases { result in
Expand All @@ -672,13 +659,24 @@ class InAppPurchase2APISetup {
} else {
restorePurchasesChannel.setMessageHandler(nil)
}
let supportsStoreKit2Channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2API.supportsStoreKit2\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
supportsStoreKit2Channel.setMessageHandler { _, reply in
do {
let result = try api.supportsStoreKit2()
reply(wrapResult(result))
} catch {
reply(wrapError(error))
}
}
} else {
supportsStoreKit2Channel.setMessageHandler(nil)
}
}
}
/// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift.
protocol InAppPurchase2CallbackAPIProtocol {
func onTransactionsUpdated(
newTransactions newTransactionsArg: [SK2TransactionMessage],
completion: @escaping (Result<Void, PigeonError>) -> Void)
func onTransactionsUpdated(newTransactions newTransactionsArg: [SK2TransactionMessage], completion: @escaping (Result<Void, PigeonError>) -> Void)
}
class InAppPurchase2CallbackAPI: InAppPurchase2CallbackAPIProtocol {
private let binaryMessenger: FlutterBinaryMessenger
Expand All @@ -690,14 +688,9 @@ class InAppPurchase2CallbackAPI: InAppPurchase2CallbackAPIProtocol {
var codec: sk2_pigeonPigeonCodec {
return sk2_pigeonPigeonCodec.shared
}
func onTransactionsUpdated(
newTransactions newTransactionsArg: [SK2TransactionMessage],
completion: @escaping (Result<Void, PigeonError>) -> Void
) {
let channelName: String =
"dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2CallbackAPI.onTransactionsUpdated\(messageChannelSuffix)"
let channel = FlutterBasicMessageChannel(
name: channelName, binaryMessenger: binaryMessenger, codec: codec)
func onTransactionsUpdated(newTransactions newTransactionsArg: [SK2TransactionMessage], completion: @escaping (Result<Void, PigeonError>) -> Void) {
let channelName: String = "dev.flutter.pigeon.in_app_purchase_storekit.InAppPurchase2CallbackAPI.onTransactionsUpdated\(messageChannelSuffix)"
let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec)
channel.sendMessage([newTransactionsArg] as [Any?]) { response in
guard let listResponse = response as? [Any?] else {
completion(.failure(createConnectionError(withChannelName: channelName)))
Expand Down
Loading