Question

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.

Was it helpful?

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");     
}

OTHER TIPS

Most of the user settings can be accessed by reading the property lists stored at /User/Library/Preferences/. But there are chances you might not be able to access some of these due to sandbox restriction. So you will have to try this out via code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top