单个产品的可消费iap



我已经创建了一个示例项目,通过遵循Ray Wenderlichs和它的工作完美。但我只有一个产品,我想要的是在一个单一的按钮点击它应该购买该产品。当我谷歌几个小时,我得到了一个解决方案,在应用程序购买与IBAction/按钮,这是完全相同的我的要求。但是,当我使用的代码,我得到弃用的"paymentWithProductIdentifier"。是否有任何方法可以使用像"com.example"这样的应用内购买对象进行购买?产品"吗?

你需要传递skproduct而不是它的标识符,这并没有太大的不同,你只需要事先请求产品,这样你就可以在付款时使用它。

//This is how you request the products with a list of identifiers
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:self.productIdentifiers];
[request setDelegate:self];
[request start];
//This is the delegate method called after there is a response from apple servers
-(void) productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
    self.products = response.products;
    for (SKProduct *product in self.products)
    {
        if ([product.productIdentifier isEqualToString:MY_PRODUCT_IDENTIFIER])
        {
            self.myProduct = product;
        }
    }
}
//And this is how you do the actual payment after product is retrieved
SKPayment * payment = [SKPayment paymentWithProduct:self.myProduct];
[[SKPaymentQueue defaultQueue] addPayment:payment];

事务部分的工作方式与教程中相同,因为我记得我经历了相同的教程。

尝试使用MKStoreKit,它将使您的生活更轻松。

最新更新