ios - 单个产品的消耗品应用内购买?

标签 ios xcode in-app-purchase

我按照 Ray Wenderlichs 创建了一个示例项目它工作得很好。但我只有一种产品,我想要的是单击一个按钮就可以购买该产品。当我用谷歌搜索几个小时后,我得到了一个解决方案 In-App Purchase with an IBAction / Button这与我的要求完全相同。但是当我使用代码时,我不赞成使用“paymentWithProductIdentifier”。 有什么方法可以使用像“com.example.product”这样的应用内购买对象进行购买吗?

最佳答案

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

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

关于ios - 单个产品的消耗品应用内购买?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15998649/

相关文章:

iphone - 创建 iOSOpenDev 应用程序并在同一包中进行调整

ios - 我们在哪里可以注册美国以外的 iOS 开发者计划

ios - 某些字体不适用于 XCode 中的 UIButton

ios - 应用内购买下载托管在哪里?

ios - 为什么此 Objective-C 代码会触发错误购买跟踪

ios - 从 Mac 访问 CloudKit 数据库?

ios - 如何在 Sprite 工具包中使用新的每像素 SkPhysics Bodies

iphone - keysSortedByValueUsingSelector 崩溃但 sortedArrayUsingSelector 运行正常

ios - xxx.png 和 xxx@2x.png 视网膜图形兼容性问题

Android In App Billing 恢复交易