IPhone: in-app purchase status

As you know, In-App Purchase can be turned on and off in Settings β†’ General β†’ Restrictions. Now I'm wondering if there is a way to check the status of the in-app purchase programmatically before we actually make any payment.

+4
source share
2 answers

I have a solution in the SKPaymentQueue class. I use the canMakePayments method to check in-app purchase restrictions.

From the Apple documentation:

Link to the SKPaymentQueue class: canMakePayments

β€œThe iPhone may be restricted by access to the Apple App Store, for example, parents may restrict the ability of their children to purchase additional content. Your application must confirm that the user is allowed to allow payments before the payment is added to the queue. Your application may also want to change its behavior or appearance if the user is not allowed to authorize payments. "

Code example:

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

Most user settings can be accessed by reading property lists stored in /User/Library/Preferences/. . But there is a possibility that you will not be able to access some of them due to limitations in the sandbox. So you have to try it through the code.

0
source

Source: https://habr.com/ru/post/1390424/


All Articles