gpt4 book ai didi

ios - 应用内购买 swift

转载 作者:行者123 更新时间:2023-11-28 13:20:55 25 4
gpt4 key购买 nike

我第一次尝试在我的应用中添加应用内购买。网上没有使用快速语言的指南。所以我开始将 Obj-c 转换为 swift 但我不知道这行是什么意思以及如何将它转换为 swift。

proUpgradeProduct = [products count] == 1 ? [[products firstObject] retain] : nil;

来自本指南:http://troybrant.net/blog/2010/01/in-app-purchases-a-full-walkthrough/

摘录:

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response    
{
NSArray *products = response.products;
proUpgradeProduct = [products count] == 1 ? [[products firstObject] retain] : nil;
if (proUpgradeProduct)
{
NSLog(@"Product title: %@" , proUpgradeProduct.localizedTitle);
NSLog(@"Product description: %@" , proUpgradeProduct.localizedDescription);
NSLog(@"Product price: %@" , proUpgradeProduct.price);
NSLog(@"Product id: %@" , proUpgradeProduct.productIdentifier);
}

for (NSString *invalidProductId in response.invalidProductIdentifiers)
{
NSLog(@"Invalid product id: %@" , invalidProductId);
}

// finally release the reqest we alloc/init’ed in requestProUpgradeProductData
[productsRequest release];

[[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerProductsFetchedNotification object:self userInfo:nil];
}

如果有人知道 swift 中的应用内购买指南,那就太好了!

最佳答案

诀窍是知道错误在说什么,但它通过使用可选值正确输入内容来修复

var products = response.products
var proUpgradeProductOpt:SKProduct? = products.count == 1 ? products.first as SKProduct? : nil
if let proUpgradeProduct = proUpgradeProductOpt {
println("Product title: \(proUpgradeProduct.localizedTitle)")
println("Product description: \(proUpgradeProduct.localizedDescription)")
println("Product price: \(proUpgradeProduct.price)")
println("Product id: \(proUpgradeProduct.productIdentifier)")
}

关于ios - 应用内购买 swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25852902/

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