Home » Swift » In-App Purchase Works on iPhone but not iPad

In-App Purchase Works on iPhone but not iPad

Posted by: admin November 30, 2017 Leave a comment

Questions:

I’m having an issue with In-App purchases on iOS. I have 5 In-App Purchases in a game, all of which work exactly as expected when tested on an iPhone 6 (iOS 8.3). When I go to test on iPad Air 2 (iOS 8.2), all IAPs fail immediately. Has anyone else experienced this problem? Is there some code that is specific to iPad that I have to add?

EDIT: Strangely, updating the iPad to iOS 8.3 fixed the problem. Any ideas as to why this issue is occurring? Should I change my app to only support iOS 8.3 and above?

To test the app, I’m using TestFlight, the same network connection, and the same Apple ID.

The code I’m using for In-App Purchases is Below:

func inApp() {
    if (SKPaymentQueue.canMakePayments())
    {
        var productID:NSSet = NSSet(object: product_id);
        var productsRequest:SKProductsRequest = SKProductsRequest(productIdentifiers: productID as Set<NSObject>);
        productsRequest.delegate = self;
        productsRequest.start();
    }else{
        displayAlert()
    }
}

func buyProduct(product: SKProduct){
    var payment = SKPayment(product: product)
    SKPaymentQueue.defaultQueue().addPayment(payment);

}

func productsRequest (request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) {
    var count : Int = response.products.count
    if (count>0) {
        var validProducts = response.products
        var validProduct: SKProduct = response.products[0] as! SKProduct
        if (validProduct.productIdentifier == product_id) {
            println(validProduct.localizedTitle)
            println(validProduct.localizedDescription)
            println(validProduct.price)
            buyProduct(validProduct);
        } else {
            println(validProduct.productIdentifier)
        }
    } else {
        displayAlert()
    }
}


func request(request: SKRequest!, didFailWithError error: NSError!) {
    self.displayAlert()
}

func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!)    {
    for transaction:AnyObject in transactions {
        if let trans:SKPaymentTransaction = transaction as? SKPaymentTransaction{
            switch trans.transactionState {
            case .Purchased:
                SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
                if product_id == "com.shv.FrenzyTenLives" {
                    defaults.setInteger(10, forKey: "totalLives")
                } else if product_id == "com.shv.FrenzyFiveLives" {
                    defaults.setInteger(5, forKey: "totalLives")
                } else if product_id == "com.shv.FrenzyInfiniteLives" {
                    defaults.setBool(true, forKey: "infiniteLives")
                } else if product_id == "com.shv.FrenzyShield" {
                    defaults.setInteger(5, forKey: "shieldValue")
                } else if product_id == "com.shv.FrenzyRemoveAds" {
                    defaults.setBool(true, forKey: "adsRemoved")
                    adBanner.hidden = true
                }
                break;
            case .Failed:
                SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
                self.displayAlert()
                break;
            case .Restored:
                SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
                if product_id == "com.shv.FrenzyTenLives" {
                    defaults.setInteger(10, forKey: "totalLives")
                } else if product_id == "com.shv.FrenzyFiveLives" {
                    defaults.setInteger(5, forKey: "totalLives")
                } else if product_id == "com.shv.FrenzyInfiniteLives" {
                    defaults.setBool(true, forKey: "infiniteLives")
                } else if product_id == "com.shv.FrenzyRemoveAds" {
                    defaults.setBool(true, forKey: "adsRemoved")
                    adBanner.hidden = true
                }
                break;
            default:
                break;
            }
        }
    }
}
Answers:

Without a definition of “fail immediately” my best guess is that you were not logged in to a valid sandbox testing account on the iPad and in the midst of updating the iOS version this got reconciled, which is why it works on 8.3.

The easiest way to get IAP testing to work is to log out of iTunes:

Settings -> App and iTunes Store -> Tap apple ID and log out.

Once you’ve logged out, try to make an IAP and you will be prompted to log in – once you enter valid test account credentials, the IAP will download – if it doesn’t, post your log files here. Note that you can find or create testing accounts inside iTunes Connect.

IAP is an extremely complicated subject with numerous points of failure – knowing that your IAPs work on one device but not another points to a configuration issue specific to the device on which the IAP failed.

Questions:
Answers:

Usually, when one device will not perform in app purchase, it’s a setting under restrictions.

If you’ve checked and disabled that restriction or all restrictions – you can often fix this by signing out of the App Store entirely and powering down the device. When it starts cleanly, you can log in again. When you sign in, be sure to buy something (a free song of the week, a free app or even a paid app) to get through the verification questions. Once that’s done, recheck an IAP (in-app purchase) to be sure things are functional.

As a last resort, you might need to contact Apple Support for Apple ID – but most times you can fix this without needing their help.

You should check the following things.

Make sure you can answer “Yes” to each of these questions:

  • Have you enabled In-App Purchases for your App ID?
  • Have you checked Cleared for Sale for your product?
  • Does your project’s .plist Bundle ID match your App ID?
  • Have you generated and installed a new provisioning profile for the new App ID?
  • Have you configured your project to code sign using this new provisioning profile?
  • Are you using the full product ID when when making an SKProductRequest?
  • Have you waited several hours since adding your product to iTunes Connect?
  • Have you tried deleting the app from your device and reinstalling?
  • Is your device jailbroken? If so, you need to revert the jailbreak for IAP to work.

If you answered “No” to any one of these questions, there’s your problem.

You should visit following links definitely you will get solution.

https://www.innofied.com/in-app-purchase-working-ios-solution/

Leave a Reply

Your email address will not be published. Required fields are marked *