简体   繁体   English

iPhone:以编程方式检查应用内购买状态

[英]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. 现在我想知道,在我们实际付款之前,有没有办法以编程方式检查应用程序内购买的状态。

I've got the solution in SKPaymentQueue class. 我在SKPaymentQueue类中得到了解决方案。 I am using the "canMakePayments" method to check the restrictions on In-App Purchases. 我正在使用“canMakePayments”方法来检查应用内购买的限制。

From Apple Documentation: 来自Apple文档:

SKPaymentQueue Class Reference: canMakePayments SKPaymentQueue类参考: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." “可以限制iPhone访问Apple App Store。例如,父母可以限制孩子购买额外内容的能力。您的应用程序应该确认允许用户在向队列添加付款之前授权付款。您的应用程序可能当用户不被允许授权付款时,也想改变其行为或外观。“

Sample Code: 示例代码:

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

Most of the user settings can be accessed by reading the property lists stored at /User/Library/Preferences/. 通过读取存储在/User/Library/Preferences/.的属性列表,可以访问大多数用户设置/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. 因此,您必须通过代码尝试这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM