-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[in_app_purchase_storekit] Replace deprecated offer code API #11223
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
base: main
Are you sure you want to change the base?
Changes from all commits
3496422
6ec5914
f0a9d80
48af768
11818fb
d9658ba
8a57827
c18ff02
efa76e8
9669800
bc17eb1
5e7298d
32410be
002b7cb
5175c34
9df0f03
e6da7b7
67ff0df
19f0689
8d0e282
27b7ec8
fe92118
7e640b7
17351ee
5e04355
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -321,6 +321,67 @@ extension InAppPurchasePlugin: InAppPurchase2API { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| func presentOfferCodeRedeemSheet(completion: @escaping (Result<Void, Error>) -> Void) { | ||||||
| #if os(iOS) | ||||||
| if #available(iOS 16.0, *) { | ||||||
| guard let windowScene = self.registrar?.viewController?.view.window?.windowScene else { | ||||||
| let error = PigeonError( | ||||||
| code: "storekit2_missing_key_window_scene", | ||||||
| message: "Failed to fetch key window scene", | ||||||
| details: "registrar.viewController.view.window.windowScene returned nil." | ||||||
| ) | ||||||
| completion(.failure(error)) | ||||||
| return | ||||||
| } | ||||||
| Task { @MainActor in | ||||||
| do { | ||||||
| try await AppStore.presentOfferCodeRedeemSheet(in: windowScene) | ||||||
| completion(.success(())) | ||||||
| } catch { | ||||||
| completion(.failure(error)) | ||||||
| } | ||||||
| } | ||||||
| } else { | ||||||
| completion( | ||||||
| .failure( | ||||||
| PigeonError( | ||||||
| code: "storekit2_unsupported_platform_version", | ||||||
| message: "Offer code redemption requires iOS 16+", | ||||||
| details: nil | ||||||
| ))) | ||||||
| } | ||||||
| #elseif os(macOS) | ||||||
| if #available(macOS 15.0, *) { | ||||||
| guard let viewController = self.registrar?.viewController else { | ||||||
| let error = PigeonError( | ||||||
| code: "storekit2_missing_view_controller", | ||||||
| message: "Failed to fetch view controller", | ||||||
| details: "registrar.viewController returned nil." | ||||||
| ) | ||||||
| completion(.failure(error)) | ||||||
| return | ||||||
| } | ||||||
|
|
||||||
| Task { @MainActor in | ||||||
| do { | ||||||
| try await AppStore.presentOfferCodeRedeemSheet(from: viewController) | ||||||
| completion(.success(())) | ||||||
| } catch { | ||||||
| completion(.failure(error)) | ||||||
| } | ||||||
| } | ||||||
| } else { | ||||||
| completion( | ||||||
| .failure( | ||||||
| PigeonError( | ||||||
| code: "storekit2_unsupported_platform_version", | ||||||
| message: "Offer code redemption requires macOS 15+", | ||||||
| details: nil | ||||||
| ))) | ||||||
| } | ||||||
| #endif | ||||||
| } | ||||||
|
Comment on lines
+324
to
+383
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The func presentOfferCodeRedeemSheet(completion: @escaping (Result<Void, Error>) -> Void) {
#if os(iOS)
if #available(iOS 16.0, *) {
guard let windowScene = self.registrar?.viewController?.view.window?.windowScene else {
let error = PigeonError(
code: "storekit2_missing_key_window_scene",
message: "Failed to fetch key window scene",
details: "registrar.viewController.view.window.windowScene returned nil."
)
completion(.failure(error))
return
}
Task { @MainActor in
do {
try await AppStore.presentOfferCodeRedeemSheet(in: windowScene)
completion(.success(()))
} catch {
completion(.failure(error))
}
}
} else {
completion(.failure(PigeonError(
code: "storekit2_unsupported_version",
message: "Offer code redemption via StoreKit 2 requires iOS 16.0 or later.",
details: nil
)))
}
#elseif os(macOS)
if #available(macOS 15.0, *) {
guard let viewController = self.registrar?.viewController else {
let error = PigeonError(
code: "storekit2_missing_view_controller",
message: "Failed to fetch view controller",
details: "registrar.viewController returned nil."
)
completion(.failure(error))
return
}
Task { @MainActor in
do {
try await AppStore.presentOfferCodeRedeemSheet(from: viewController)
completion(.success(()))
} catch {
completion(.failure(error))
}
}
} else {
completion(.failure(PigeonError(
code: "storekit2_unsupported_version",
message: "Offer code redemption via StoreKit 2 requires macOS 15.0 or later.",
details: nil
)))
}
#else
completion(.failure(PigeonError(
code: "storekit2_unsupported_platform",
message: "Offer code redemption via StoreKit 2 is not supported on this platform.",
details: nil
)))
#endif
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is fine bc users should not be on storekit 2 below ios 15
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it looks like the availability check is checking for iOS 16 and macOS 15? The extension availability: Lines 7 to 8 in 23280da
|
||||||
|
|
||||||
| /// Wrapper method around StoreKit2's sync() method | ||||||
| /// https://developer.apple.com/documentation/storekit/appstore/sync() | ||||||
| /// When called, a system prompt will ask users to enter their authentication details | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the
#availablecheck fails, thecompletionhandler is never called. This will cause the calling Dart code to hang indefinitely. You should addelseblocks to handle cases where the API is not available on the current OS version and call the completion handler with an appropriate error.