promisekit / storekit Goto Github PK
View Code? Open in Web Editor NEWPromises for Swift & ObjC
Home Page: http://promisekit.org
License: MIT License
Promises for Swift & ObjC
Home Page: http://promisekit.org
License: MIT License
Showing Recent Messages
invalidManifestFormat("/var/folders/3t/04146p9j1zq58qk668c8_f_40000gn/T/com.apple.appstoreagent/TemporaryFile.lvoms6.swift:10:30: error: cannot convert value of type 'Int' to expected element type 'Array.ArrayLiteralElement' (aka 'SwiftVersion')\npkg.swiftLanguageVersions = [3, 4]\n
^\n/var/folders/3t/04146p9j1zq58qk668c8_f_40000gn/T/com.apple.appstoreagent/TemporaryFile.lvoms6.swift:10:33: error: cannot convert value of type 'Int' to expected element type 'Array.ArrayLiteralElement' (aka 'SwiftVersion')\npkg.swiftLanguageVersions = [3, 4]\n
^", diagnosticFile: Optional(AbsolutePath:"/Users/Adam-Milton-Barker/Library/Developer/Xcode/DerivedData/xxxxxxx-hckynpimisgfqhetportamtfadgo/SourcePackages/ManifestLoading/storekit.dia")) in https://github.com/PromiseKit/StoreKit.git
SKPayment+Promise file sending some errors but .catch closure doesn't receive it
SKPayment+Promise.swift line 36
When using this extension I found edge cases when this extension does not work properly. These are mainly “interrupted purchases”, see the following excerpt from Apple documentation:
It is important to add the observer at launch, in application(_:didFinishLaunchingWithOptions:), to ensure that it persists during all launches of your app, receives all payment queue notifications, and continues transactions that may be processed outside the app, such as:
- Promoted in-app purchases
- Background subscription renewals
- Interrupted purchases
It is clear from this documentation that this extension does not implement observers according the Apple guidance. Due to the nature of PromiseKit it is hard to come up with a solution which would fit.
The thing is, SKPayment
extension currently leaves some transactions unfinished. Even worse, the behavior is different on major iOS versions: 12 works fine and 13+ do not work. They notify about updated transactions at different times.
Steps:
This ends in one unfinished transaction which is persisted during the runs of the app. When using purely this extension you will end up in inconsistent state.
It is not as obvious with non-consumable in-app purchases, but when using with subscriptions the issue becomes clearer.
In the end, I ended up using PromiseKit nevertheless, since it is extensively used in the app where I found this issue.
Firstly, I implemented this class to complete any unfinished transactions:
final class SubscriptionFinisher: NSObject, SKPaymentTransactionObserver {
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
switch transaction.transactionState {
case .purchased, .restored, .failed:
queue.finishTransaction(transaction)
default:
break
}
}
}
}
Secondly, I add this observer on application launch and remove it during StoreKit promise runs. Finishing transactions twice can end in an undefined behavior.
queue.remove(finisher)
let purchase = SKPayment(product: product)
.promise()
.ensure { queue.add(finisher) }
I either propose to update the documentation for this extension or provide guidance how to prevent others from running into this issue. As for now, I hope this issue will serve as some kind of documentation by itself.
TLDR Do not use this extension when working with auto-renewable subscriptions, because sooner or later one of your users will encounter an edge case when the transactions won't be completed properly.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.