Skip to content
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

Inconsistent purchase and restore purchases results on iOS 10/11 #287

Open
6 tasks
TipToeTiger opened this issue Oct 13, 2017 · 13 comments
Open
6 tasks

Inconsistent purchase and restore purchases results on iOS 10/11 #287

TipToeTiger opened this issue Oct 13, 2017 · 13 comments
Labels
area: purchase flows purchase processes, efficiency and failures

Comments

@TipToeTiger
Copy link

Platform

  • [X ] iOS
  • macOS
  • tvOS

In app purchase type

  • Consumable
  • [X ] Non-consumable
  • Auto-Renewable Subscription
  • Non-Renewing Subscription

Environment

  • Sandbox
  • [ X] Production

Version

0.10.5

Report

Issue summary

In production I am currently having some inconsistent issues.

When a user purchases the IAP in my app the purchases is successful and they get the successful purchase UIAlert. However, the effects of the purchase do not take place. I informed the user to use 'Restore purchases' to make sure that the effects of the purchase happen. However, when the user selects 'Restore Purchases' they receive nothing back, along with my UIAlert that tells them that there is nothing to restore.

This issue only seems to be occurring on iOS 10 devices. I have tried to replicate the issue on iOS 11 test and live devices but I cannot replicate it.

I tried to replicate the issue on an iOS 10 device twice and had one result where the IAP was successful an another where it failed.

Has anyone else come across an issue like this?

Any help would be greatly appreciated.

@TipToeTiger TipToeTiger changed the title Inconsistent purchase and restore purchases results on iOS 10 Inconsistent purchase and restore purchases results on iOS 10/11 Oct 13, 2017
@TipToeTiger
Copy link
Author

UPDATE: The issue has also been seen occurring in iOS 11 builds as well.

@cubong
Copy link

cubong commented Oct 23, 2017

I also have the same problem. I think there is a problem with the Appstore

@bizz84 bizz84 added the area: purchase flows purchase processes, efficiency and failures label Dec 22, 2017
@IamAliSufyan
Copy link

I am facing the exact issue and it is hurting my user base badly. Did you find a way to fix it?

@bizz84
Copy link
Owner

bizz84 commented Jan 12, 2018

@TipToeTiger Apologies for the late reply.

If this is a production-only issue I could suggest adding some analytics or network-logging code to check if the callbacks are made.

Something along these lines this:

// PaymentQueueController.swift
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {

  let purchasedTransactions = transactions.filter { $0.transactionState == .purchased }
  let purchasedProductIds = purchasedTransactions.map { $0.payment.productIdentifier }
  logger.track(event: "purchasedTransactions", customData: ["productIds": purchasedProductIds, date: Date()])
  ...
}    

// in your app
SwiftyStoreKit.purchaseProduct("your-product-id") { result in
  logger.track(event: "purchaseProduct", customData: ["result": result, date: Date()])
}

You could then check your logs by date. You would expect to see "purchasedTransactions" and "purchaseProduct" events always showing up in pairs with almost identical dates.

Hope this helps.

@TipToeTiger
Copy link
Author

TipToeTiger commented Jan 12, 2018

Hi All,

I believe I fixed the issue by adding the following to my didfinshinglaunching function in my App Delegate:

SwiftyStoreKit.completeTransactions(atomically: true) { purchases in for purchase in purchases { if purchase.transaction.transactionState == .purchased || purchase.transaction.transactionState == .restored { if purchase.needsFinishTransaction { // Deliver content from server, then: SwiftyStoreKit.finishTransaction(purchase.transaction) } print("purchased: \(purchase)") } } }

After this the purchases worked correctly.

@bizz84 Thanks for the reply :) I will add the logging anyway 👍

Hopefully this helps!

@TipToeTiger
Copy link
Author

Whoops sorry, didn't mean to close.

@bizz84
Copy link
Owner

bizz84 commented Jan 12, 2018

@TipToeTiger Not calling SwiftyStoreKit.completeTransactions() on startup can cause the purchase confirmation alert to show, but the callback to not be called.

Adding this in your AppDelegate should fix your problem - once you confirm this we can close this issue.

I'm going to add a console log to remind users to call SwiftyStoreKit.completeTransactions().

@goloops
Copy link

goloops commented Jan 28, 2019

hi There,

I have the same problem, my app is an iMessage app extension app. If that's the case where should i insert the above code?
*sorry i am only a beginner in programming. Thank you for the help :)

@TipToeTiger
Copy link
Author

hi There,

I have the same problem, my app is an iMessage app extension app. If that's the case where should i insert the above code?
*sorry i am only a beginner in programming. Thank you for the help :)

You will want to add it into your app delegate. In the didFinishLaunchingWithOptions function.

Hope this helps!

@goloops
Copy link

goloops commented Jan 28, 2019

untitled

untitled1

untitled3

These are what I have in my code. Mine is an iMessage extension, and i only have access to viewdidload function.

@TipToeTiger
Copy link
Author

TipToeTiger commented Jan 28, 2019

This is what I have in my appdelegate. No idea if it will work in your case, but give it a go anyway! Maybe try popping it in viewdidload or viewwillload?

EDIT: The layout keeps screwing up sorry!

SwiftyStoreKit.completeTransactions(atomically: true) { purchases in
for purchase in purchases {

if purchase.transaction.transactionState == .purchased || purchase.transaction.transactionState == .restored {
if purchase.needsFinishTransaction {
// Deliver content from server, then:
SwiftyStoreKit.finishTransaction(purchase.transaction)

                }
                print("purchased: \(purchase)")
            }
        }
    }

@goloops
Copy link

goloops commented Jan 28, 2019

ok thank you, let me give it a try.

@goloops
Copy link

goloops commented Jan 30, 2019

Hi there, it seems that the code can fix the purchase problem. But I still have another problem where every time there is an app update, all the previously bought stickers are locked again and restore button doesn’t do the job. User must press the buy button and grant payment before the “ you have bought it before, do you want to get it for free?” Message pops out. Can anyone help me with this pleaseeee?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: purchase flows purchase processes, efficiency and failures
Projects
None yet
Development

No branches or pull requests

5 participants