I have some odd behavior with User canceling in App Purchase (Sandbox Environment) while the app is in background and the user is not yet logged in to the store:
The process is as follows:
- User is no开发者_Go百科t logged in/App Id is not set in Settings > Store
- User clicks buy button. This calls
[[SKPaymentQueue defaultQueue] addPayment:payment];
- User immediatly preses home button (app goes to background)
- Storekit popup appears asking to confirm purchase. User cancels
- App is activated again and would expect to recieve
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
, but does not. The TX is still in state purchasing.
This process is different, if the testuser is logged in to the store already. In that case the above process works as expected.
Another remark: After the above steps, I actually buy another in-App item (inlcuding logging in to the appstore). After this I sent the app to backgrounding and reactivate it and it will process the fomerly missing cancel transaction.
Conclusion: A user canceling a payment tx while the app is in background and not being logged in to the store results in late delivery of the storekit callback. Delivery is done after the user actually logged in to the appstore and the PaymentQueue process gets triggered by reactivating the app.
This behavior seems to be wrong and if it is actually like that in real environment, I might consider this a Storekit bug. Has someone experienced the same behavior or can indicate something to prevent a tx "hanging" in purchasing state?
Thanks, Marcus
I don't believe you can count on ANYTHING when it comes to Store Kit. Rather than "waiting expectantly" for the transaction to be queued after the "Buy" button is pressed, just go on about your business. When you are notified that there are transactions (which could be tomorrow) process them. I believe there's a comment to this effect in the documentation -- that your app should register for SK notifications when it's launched and it should expect to get them at any time. So don't build any awareness of "state" into your app when it comes to Store Kit. Just process the transactions as they arrive.
精彩评论