-
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 17 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,51 @@ 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)) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| #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)) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| #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. If 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 {
let error = PigeonError(
code: "unavailable",
message: "presentOfferCodeRedeemSheet is only available on iOS 16.0 and newer.",
details: nil)
completion(.failure(error))
}
#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 {
let error = PigeonError(
code: "unavailable",
message: "presentOfferCodeRedeemSheet is only available on macOS 15.0 and newer.",
details: nil)
completion(.failure(error))
}
#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 | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,8 +56,7 @@ | |
| 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; }; | ||
| 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; }; | ||
| 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; }; | ||
| 784666492D4C4C64000A1A5F /* FlutterFramework */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = FlutterFramework; path = Flutter/ephemeral/Packages/.packages/FlutterFramework; sourceTree = "<group>"; }; | ||
| 78DABEA22ED26510000E7860 /* in_app_purchase_storekit */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = in_app_purchase_storekit; path = ../../darwin/in_app_purchase_storekit; sourceTree = "<group>"; }; | ||
| 6458340B2CE3497379F6B389 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; }; | ||
| 78E0A7A72DC9AD7400C4905E /* FlutterGeneratedPluginSwiftPackage */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = FlutterGeneratedPluginSwiftPackage; path = Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage; sourceTree = "<group>"; }; | ||
| 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; }; | ||
| 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; }; | ||
|
|
@@ -85,6 +84,8 @@ | |
| F2D527192C50627500C137C7 /* PaymentQueueTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PaymentQueueTests.swift; path = ../../shared/RunnerTests/PaymentQueueTests.swift; sourceTree = "<group>"; }; | ||
| F2D527292C583C4A00C137C7 /* TranslatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TranslatorTests.swift; path = ../../shared/RunnerTests/TranslatorTests.swift; sourceTree = "<group>"; }; | ||
| F6E5D5F926131C4800C68BED /* Configuration.storekit */ = {isa = PBXFileReference; lastKnownFileType = text; path = Configuration.storekit; sourceTree = "<group>"; }; | ||
| 784666492D4C4C64000A1A5F /* FlutterFramework */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = FlutterFramework; path = Flutter/ephemeral/Packages/.packages/FlutterFramework; sourceTree = "<group>"; }; | ||
| 78DABEA22ED26510000E7860 /* in_app_purchase_storekit */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = in_app_purchase_storekit; path = ../../darwin/in_app_purchase_storekit; sourceTree = "<group>"; }; | ||
| /* End PBXFileReference section */ | ||
|
|
||
| /* Begin PBXFrameworksBuildPhase section */ | ||
|
|
@@ -289,7 +290,7 @@ | |
| ); | ||
| mainGroup = 97C146E51CF9000F007C117D; | ||
| packageReferences = ( | ||
| 781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "FlutterGeneratedPluginSwiftPackage" */, | ||
| 781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage" */, | ||
| ); | ||
| productRefGroup = 97C146EF1CF9000F007C117D /* Products */; | ||
| projectDirPath = ""; | ||
|
|
@@ -526,6 +527,8 @@ | |
| baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; | ||
| buildSettings = { | ||
| ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; | ||
| CODE_SIGN_IDENTITY = "Apple Development"; | ||
| CODE_SIGN_STYLE = Automatic; | ||
| CURRENT_PROJECT_VERSION = 1; | ||
| DEVELOPMENT_TEAM = ""; | ||
| ENABLE_BITCODE = NO; | ||
|
|
@@ -542,8 +545,9 @@ | |
| "$(inherited)", | ||
| "$(PROJECT_DIR)/Flutter", | ||
| ); | ||
| PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.inAppPurchaseExample; | ||
| PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.inAppPurchaseExample9; | ||
|
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.
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. Is this an intended change? I think there's one more bundle id and signing id change below. |
||
| PRODUCT_NAME = "$(TARGET_NAME)"; | ||
| PROVISIONING_PROFILE_SPECIFIER = ""; | ||
| VERSIONING_SYSTEM = "apple-generic"; | ||
| }; | ||
| name = Debug; | ||
|
|
@@ -553,6 +557,8 @@ | |
| baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; | ||
| buildSettings = { | ||
| ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; | ||
| CODE_SIGN_IDENTITY = "Apple Development"; | ||
| CODE_SIGN_STYLE = Automatic; | ||
| CURRENT_PROJECT_VERSION = 1; | ||
| DEVELOPMENT_TEAM = ""; | ||
| ENABLE_BITCODE = NO; | ||
|
|
@@ -569,8 +575,9 @@ | |
| "$(inherited)", | ||
| "$(PROJECT_DIR)/Flutter", | ||
| ); | ||
| PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.inAppPurchaseExample; | ||
| PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.inAppPurchaseExample9; | ||
| PRODUCT_NAME = "$(TARGET_NAME)"; | ||
| PROVISIONING_PROFILE_SPECIFIER = ""; | ||
| VERSIONING_SYSTEM = "apple-generic"; | ||
| }; | ||
| name = Release; | ||
|
|
@@ -586,6 +593,7 @@ | |
| CLANG_WARN_DOCUMENTATION_COMMENTS = YES; | ||
| CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; | ||
| CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; | ||
| "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; | ||
| CODE_SIGN_STYLE = Automatic; | ||
| DEVELOPMENT_TEAM = ""; | ||
| INFOPLIST_FILE = RunnerTests/Info.plist; | ||
|
|
@@ -616,6 +624,7 @@ | |
| CLANG_WARN_DOCUMENTATION_COMMENTS = YES; | ||
| CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; | ||
| CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; | ||
| "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; | ||
| CODE_SIGN_STYLE = Automatic; | ||
| DEVELOPMENT_TEAM = ""; | ||
| INFOPLIST_FILE = RunnerTests/Info.plist; | ||
|
|
@@ -666,7 +675,7 @@ | |
| /* End XCConfigurationList section */ | ||
|
|
||
| /* Begin XCLocalSwiftPackageReference section */ | ||
| 781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "FlutterGeneratedPluginSwiftPackage" */ = { | ||
| 781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage" */ = { | ||
| isa = XCLocalSwiftPackageReference; | ||
| relativePath = Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage; | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| archiveVersion = 1; | ||
| classes = { | ||
| }; | ||
| objectVersion = 60; | ||
| objectVersion = 54; | ||
|
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. |
||
| objects = { | ||
|
|
||
| /* Begin PBXAggregateTarget section */ | ||
|
|
@@ -82,8 +82,8 @@ | |
| 33E51913231747F40026EE4D /* DebugProfile.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DebugProfile.entitlements; sourceTree = "<group>"; }; | ||
| 33E51914231749380026EE4D /* Release.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Release.entitlements; sourceTree = "<group>"; }; | ||
| 33E5194F232828860026EE4D /* AppInfo.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AppInfo.xcconfig; sourceTree = "<group>"; }; | ||
| 784666492D4C4C64000A1A5F /* FlutterFramework */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = FlutterFramework; path = ephemeral/Packages/.packages/FlutterFramework; sourceTree = "<group>"; }; | ||
| 78DABEA22ED26510000E7860 /* in_app_purchase_storekit */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = in_app_purchase_storekit; path = ../../../darwin/in_app_purchase_storekit; sourceTree = "<group>"; }; | ||
| 39C4797E13DFF5FCF1A87568 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; }; | ||
| 46EFB01DD1BBB34F886C33A0 /* Pods-RunnerTests.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.profile.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.profile.xcconfig"; sourceTree = "<group>"; }; | ||
| 78E0A7A72DC9AD7400C4905E /* FlutterGeneratedPluginSwiftPackage */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = FlutterGeneratedPluginSwiftPackage; path = ephemeral/Packages/FlutterGeneratedPluginSwiftPackage; sourceTree = "<group>"; }; | ||
| 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = "<group>"; }; | ||
| 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = "<group>"; }; | ||
|
|
@@ -184,8 +184,6 @@ | |
| 33CEB47122A05771004F2AC0 /* Flutter */ = { | ||
| isa = PBXGroup; | ||
| children = ( | ||
| 78DABEA22ED26510000E7860 /* in_app_purchase_storekit */, | ||
| 784666492D4C4C64000A1A5F /* FlutterFramework */, | ||
| 78E0A7A72DC9AD7400C4905E /* FlutterGeneratedPluginSwiftPackage */, | ||
| 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */, | ||
| 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */, | ||
|
|
||
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.
Looks like these are from UIScene migration, but since the extension is empty I assume the IAP plugin isn't interested in UIScene lifecycle events, are these necessary?
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.
Also gemini pointed out these APIs are new in Flutter 3.38