gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 13:15:14 24 4
gpt4 key购买 nike

我按照 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com