1

我已经按照Ray Wenderlichs创建了一个示例项目,它运行良好。但我只有一个产品,我想要的是在一个按钮中单击它应该购买该产品。当我谷歌几个小时时,我得到了一个解决方案应用内购买使用与我的要求完全相同的 IBAction / Button 。但是,当我使用代码时,我会弃用“paymentWithProductIdentifier”。有没有办法使用像“com.example.product”这样的inapp购买对象进行购买?

4

2 回答 2

1

你需要传递 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];

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

于 2013-04-14T14:50:44.767 回答
0

尝试使用MKStoreKit,它会让你的生活更轻松。

于 2013-04-14T12:53:40.027 回答