我使用测试用户帐户来测试我的应用内购买应用。我使用的产品名称如 #define PRODUCT_IDENTIFIER @"com.companyname.appname.P1"
当我在模拟器中运行我的应用程序时,我在日志中得到以下信息:
是的,你可以付款 2013-04-22 11:37:44.809 appname[2382:c07] -[__NSCFConstantString productIdentifier]: 无法识别的选择器发送到实例 0x1ac04
代码:
-(void)checkForPayments{
if ([SKPaymentQueue canMakePayments])
{
printf("\n YES u can make payments");
// SKPayment *myPayment = [SKPayment paymentWithProductIdentifier:PRODUCT_IDENTIFIER];
SKPayment *myPayment = [SKPayment paymentWithProduct:PRODUCT_IDENTIFIER];
[[SKPaymentQueue defaultQueue] addPayment:myPayment];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
}
最佳答案
1. SKPayment *myPayment = [SKPayment paymentWithProductIdentifier:PRODUCT_IDENTIFIER]; // CORRECT
2. SKPayment *myPayment = [SKPayment paymentWithProduct:PRODUCT_IDENTIFIER]; //WRONG
是正确的,因为您传递的是 NSString 的 PRODUCT_IDENTIFIER,它需要 NSString
是错误的,因为您传递的参数是 NSString,因为它需要
SKProduct
而不是NSString
..
要使用SKProduct
,您首先需要使用SKProductRequest
获取产品,如下所示
SKProductsRequest *req = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:PRODUCT_IDENTIFIER]];
req.delegate = self;
[req start];
然后在 SKProductRequest
的 Delegate
中,您必须执行以下操作
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
for(SKProduct *product in response.products){
SKPayment *myPayment = [SKPayment paymentWithProduct:product];
}
}
关于iphone - [__NSCFConstantString 产品标识符] : unrecognized selector sent to instance 0x1ac04',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16140815/