iphone - [__NSCFConstantString 产品标识符] : unrecognized selector sent to instance 0x1ac04'

标签 iphone ios in-app-purchase app-store-connect

我使用测试用户帐户来测试我的应用内购买应用。我使用的产品名称如 #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
  1. 是正确的,因为您传递的是 NSString 的 PRODUCT_IDENTIFIER,它需要 NSString

  2. 是错误的,因为您传递的参数是 NSString,因为它需要 SKProduct 而不是 NSString..

要使用SKProduct,您首先需要使用SKProductRequest获取产品,如下所示

SKProductsRequest *req = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:PRODUCT_IDENTIFIER]];
req.delegate = self;
[req start]; 

然后在 SKProductRequestDelegate 中,您必须执行以下操作

- (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/

相关文章:

ios - 从 firebase + iOS 获取数据时加载数据缓慢

android - 在 SharedPreferences 中存储 Android 应用内购买

iOS 应用因解锁内容而被拒绝

iphone - 在 drawRect : 中使用 Core Graphics 绘制图像网格

iphone - 奇怪的图标行为

iphone - iOS 异步 NSURLConnection 在与调用它的 View 不同的 View 上触发行为

ios - 我有一个应用内购买设置,它有效,除了当用户按下 "cancel"它仍然最终购买产品

iphone - 是否有可能(如何)让应用程序在 iPhone 的聚光灯搜索中返回自定义搜索结果?

iphone - 在 iOS 中播放系统声音

ios - 我想打印 soap 对我的 TableViewController 的响应