我正在为应用程序购买创建一个示例应用程序。我已经实现了一个产品,我使用了以下代码,其中我可以实现一个产品的购买,但如果有多个产品,那么我如何获得所有可用产品的所有标识符的列表。希望我能清楚地回答这个问题。
我为一个产品使用了下面的代码,如下所示。
- (void)viewDidLoad {
[super viewDidLoad];
if ([SKPaymentQueue canMakePayments]) {
NSLog(@"Parental-controls are disabled");
SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"com.companion.onemonth"]];
productsRequest.delegate = self;
[productsRequest start];
} else {
NSLog(@"Parental-controls are enabled");
//com.companion.onemonth ;
}
}
- (IBAction)purchase {
SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.companion.onemonth"];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}通过这段代码,我可以获得一个产品,但不知道如何在运行时获得多个标识符。
发布于 2011-08-11 20:07:12
将所有已定义的产品硬编码到SKProductsRequest的NSSet中:
[NSSet setWithObjecta:@"com.companion.onemonth", @"com.companion.twomonth"], nil)
您将在委托方法中获得可用产品的NSArray:
(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response;SKProductsResponse将拥有一系列您的产品。
发布于 2011-08-11 20:05:01
Apple没有提供一种方法来获取一个应用程序可用的所有应用程序产品。他们在文档中提到了这一点。要么我们应该在我们的应用程序中对此进行硬编码,要么使用单独的API调用来返回产品列表。
如果我们有标识符列表,我们就可以在一个API调用中获得所有产品的详细信息。
参考:http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/StoreKitGuide/APIOverview/OverviewoftheStoreKitAPI.html#//apple_ref/doc/uid/TP40008267-CH100-SW11
请参阅图解参考,其中显示了指向“开发人员服务器”的链接
https://stackoverflow.com/questions/7025365
复制相似问题