-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[in_app_purchase] add Storefront.countryCode() and AppStore.sync() #8900
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a5b8be6
bonk
LouiseHsu fb336f2
bonk 2
LouiseHsu 3975176
Merge branch 'main' into country-code
LouiseHsu 6e36806
.
LouiseHsu bd28299
Merge branch 'main' of github.com:flutter/packages into country-code
LouiseHsu 6879d20
Merge branch 'country-code' of github.com:LouiseHsu/packages into cou…
LouiseHsu bc47383
format?
LouiseHsu e1d8e4a
FORMART
LouiseHsu 6d4f358
dart format
LouiseHsu 5b225f9
pod spec
LouiseHsu 272fecf
.
LouiseHsu 7751325
.
LouiseHsu cde9e8c
comments!
LouiseHsu b1c712c
commentssssss
LouiseHsu bae45d4
Merge branch 'main' into country-code
LouiseHsu 407752b
commentssss
LouiseHsu 1cbbc14
.
LouiseHsu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
packages/in_app_purchase/in_app_purchase_storekit/CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| ## 0.3.22 | ||
|
|
||
| * Adds `sync()` and `countryCode()`. | ||
|
|
||
| ## 0.3.21 | ||
|
|
||
| * Adds Swift Package Manager compatibility. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,6 @@ import StoreKit | |
|
|
||
| @available(iOS 15.0, macOS 12.0, *) | ||
| extension InAppPurchasePlugin: InAppPurchase2API { | ||
|
|
||
| // MARK: - Pigeon Functions | ||
|
|
||
| /// Wrapper method around StoreKit2's canMakePayments() method | ||
|
|
@@ -146,6 +145,38 @@ extension InAppPurchasePlugin: InAppPurchase2API { | |
| } | ||
| } | ||
|
|
||
| /// Wrapper method around StoreKit2's countryCode() method | ||
| /// https://developer.apple.com/documentation/storekit/storefront/countrycode | ||
| func countryCode(completion: @escaping (Result<String, Error>) -> Void) { | ||
| Task { | ||
| guard let currentStorefront = await Storefront.current else { | ||
| let error = PigeonError( | ||
| code: "storekit2_failed_to_fetch_country_code", | ||
| message: "Storekit has failed to fetch the country code.", | ||
| details: "Storefront.current returned nil.") | ||
| return completion(.failure(error)) | ||
| } | ||
| completion(.success(currentStorefront.countryCode)) | ||
| } | ||
| } | ||
|
|
||
| /// 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 | ||
| func sync(completion: @escaping (Result<Void, Error>) -> Void) { | ||
| Task { | ||
| do { | ||
| try await AppStore.sync() | ||
|
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. missing completion on success. |
||
| } catch { | ||
| let pigeonError = PigeonError( | ||
| code: "storekit2_failed_to_sync_to_app_store", | ||
| message: "Storekit has failed to sync to the app store.", | ||
| details: "\(error)") | ||
| completion(.failure(pigeonError)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// This Task listens to Transation.updates as shown here | ||
| /// https://developer.apple.com/documentation/storekit/transaction/3851206-updates | ||
| /// This function should be called as soon as the app starts to avoid missing any Transactions done outside of the app. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit:
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.
i changed it but whats the difference in practice?
Uh oh!
There was an error while loading. Please reload this page.
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.
Let's say we have a function that doesn't return:
When we call it, we simply do:
And if we want to early return, just do:
Now, what you were trying to do was:
For most languages, this code won't even compile. However, it compiles fine here in Swift, because
Voidis an actual type in Swift. So the above code is equivalent to:Here the
answeris of typeVoid, and of valueVoid(). While it's perfectly valid to writereturn Void(), I have never seen anyone writing it. People just doreturnfor a function that returns void.A fun fact, do you know that
Voidis a typealias of an empty tuple?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.
I see, that makes sense.