【问题标题】:In app purchase not getting any product应用内购买未获得任何产品
【发布时间】:2014-03-16 06:52:44
【问题描述】:

我一直在努力让应用内购买发挥作用。目前我在应用商店中有一个应用程序(1.1 版)。我想在我想集成到应用购买的那个版本中发布另一个版本(V 1.2)。我为此创建了一个产品。但是当我尝试加载所有产品时,它显示没有产品。

V1.2 是准备上传二进制文件的形式。我已经关联了应用购买。我只想在应用购买中进行测试。我已经从我的设备(MAC + iPhone)中删除了所有配置文件。目前我只安装了一个配置文件。

这是我的代码:

-(void)fetchAvailableProducts{
    NSSet *productIdentifiers = [NSSet
                                 setWithObjects:bundle_identifier,nil];
    productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
    productsRequest.delegate = self;
    [productsRequest start];
}

- (void)requestDidFinish:(SKRequest *)request {
    NSLog(@"purchase request finished");
}

- (void)request:(SKRequest *)request didFailWithError:(NSError *)error {
    NSLog(@"%@", [error description]);
}

- (BOOL)canMakePurchases
{
    return [SKPaymentQueue canMakePayments];
}
- (void)purchaseMyProduct:(SKProduct*)product{
    if ([self canMakePurchases]) {
        SKPayment *payment = [SKPayment paymentWithProduct:product];
        [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
        [[SKPaymentQueue defaultQueue] addPayment:payment];
    }
    else{
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
                                  @"Purchases are disabled in your device" message:nil delegate:
                                  self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
        [alertView show];
    }
}

#pragma mark StoreKit Delegate

-(void)paymentQueue:(SKPaymentQueue *)queue
updatedTransactions:(NSArray *)transactions {
    for (SKPaymentTransaction *transaction in transactions) {
        switch (transaction.transactionState) {
            case SKPaymentTransactionStatePurchasing:
                NSLog(@"Purchasing");
                break;
            case SKPaymentTransactionStatePurchased:
                if ([transaction.payment.productIdentifier
                     isEqualToString:bundle_identifier]) {
                    NSLog(@"Purchased ");
                    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
                                              @"Purchase is completed succesfully" message:nil delegate:
                                              self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
                    [alertView show];
                }
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                break;
            case SKPaymentTransactionStateRestored:
                NSLog(@"Restored ");
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                break;
            case SKPaymentTransactionStateFailed:
                NSLog(@"Purchase failed ");
                break;
            default:
                break;
        }
    }
}

-(void)productsRequest:(SKProductsRequest *)request
    didReceiveResponse:(SKProductsResponse *)response
{
    SKProduct *validProduct = nil;
    int count = [response.products count];
    NSLog(@"%@",response.products);
    if (count>0) {
        validProducts = response.products;
        validProduct = [response.products objectAtIndex:0];
        if ([validProduct.productIdentifier
             isEqualToString:bundle_identifier]) {
        }
    } else {
        UIAlertView *tmp = [[UIAlertView alloc]
                            initWithTitle:@"Not Available"
                            message:@"No products to purchase"
                            delegate:self
                            cancelButtonTitle:nil
                            otherButtonTitles:@"Ok", nil];
        [tmp show];
    }
}

我想知道启用应用内购买的正确程序是什么以及我做错了什么?应该怎么做?

【问题讨论】:

    标签: ios iphone ios7 in-app-purchase storekit


    【解决方案1】:

    我解决了这个问题,所以我将其添加为答案。

    我混淆了捆绑标识符和产品标识符。我的代码是正确的,我提供了捆绑标识符而不是产品标识符,这就是我没有得到任何产品的原因。

    NSSet *productIdentifiers = [NSSet
                                     setWithObjects:product_identifier,nil];
    productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
    

    在上面的代码中使用 product_identifier(s)。因为我只创建了一个产品,所以我使用单个元素来构建集合。

    【讨论】:

      【解决方案2】:

      您的代码看起来正确。您是否确认您的应用内商品 ID 与 bundle_id 变量中的值完全匹配?

      【讨论】:

      • 你能解释一下吗? bundle_identifier 是我的应用程序的捆绑包 ID。
      • 当您在 iTunesconnect 中添加应用内购买时,您指定一个产品 ID。这是在调用 initWithProductIdentifiers 时必须发送的产品 ID:根据您自己的回答
      【解决方案3】:
       + (RageIAPHelper *)sharedInstance {
      static dispatch_once_t once;
      static RageIAPHelper * sharedInstance;
      dispatch_once(&once, ^{
          NSSet * productIdentifiers = [NSSet       setWithObject:kMDPulseSubscriptionProductIdentifier];
          sharedInstance = [[self alloc] initWithProductIdentifiers:productIdentifiers];
      });
      return sharedInstance;
         }
      

      你得到产品列表, 但你必须在真机上测试它。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-15
        • 1970-01-01
        • 1970-01-01
        • 2015-04-13
        • 1970-01-01
        相关资源
        最近更新 更多