Search code examples
iphoneobjective-cin-app-purchasemkstorekit

iPhone: Check In-App Purchase status Programmatically


As you know that, In-App Purchase can be turned on and off from Settings->General->Restrictions. Now i am wondering, is there any way to check the status of of In-App Purchase programmatically, before we actually make any payment.


Solution

  • I've got the solution in SKPaymentQueue class. I am using the "canMakePayments" method to check the restrictions on In-App Purchases.

    From Apple Documentation:

    SKPaymentQueue Class Reference: canMakePayments

    "An iPhone can be restricted from accessing the Apple App Store. For example, parents can restrict their children’s ability to purchase additional content. Your application should confirm that the user is allowed to authorize payments before adding a payment to the queue. Your application may also want to alter its behavior or appearance when the user is not allowed to authorize payments."

    Sample Code:

    if ([SKPaymentQueue canMakePayments])
    {
        SKPayment *payment = [SKPayment paymentWithProductIdentifier:identifier];
        [[SKPaymentQueue defaultQueue] addPayment:payment];
    } else {
        NSLog(@"In-App Purchases are not allowed");     
    }