In App Purchase sandbox not prompting for my login/pass

早过忘川 提交于 2019-12-03 16:47:02

I encountered a similar problem, but mine was more of a boneheaded move on my part. I had 'refactored' the call to finishTransaction so that it was being called for every state in transactionState:

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
    for (SKPaymentTransaction *transaction in transactions) {
        switch (transaction.transactionState) {
            case SKPaymentTransactionStatePurchased:
                // do stuff
                break;
            case SKPaymentTransactionStateFailed:
                // do stuff
                break;
            case SKPaymentTransactionStateRestored:
                // do stuff
                break;
            default:
                break;
        }
        [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
    }
}

Turns out™, this will also call finishTransaction on SKPaymentTransactionStatePurchasing, which will cause a crash. Moving finishTransaction back into each case of the switch statement fixed that.

After Pulling my hair out in frustration with a similar problem (instead of not being asked for my credentials it was automatically filling in the email address without the option to change it even when logged out of the store in the settings app). I discovered that I had a failed transaction stuck in the queue from development builds on the same device, I had to clear all of the transactions in the queue on the device and then try to test again.

NSArray *transactions = [[SKPaymentQueue defaultQueue] transactions];
for(id transaction in transactions){
    [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}

I hooked this code upto an IBOutlet and after being run once my in app purchases worked.

I also had been pulling my hair out a bit with this. Turns out a simple reboot of the test device got everything working fine.

An iPhone can be restricted from accessing the Apple App Store. For example, parents can restrict their children’s ability to purchase additional content.

Before placing transaction make sure, can you u buy or not?Check it like this -

  -(IBAction)clickBuy:(UIButton *)__sender {

      if ([SKPaymentQueue canMakePayments]) {
        SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"Product_id"];
        [[SKPaymentQueue defaultQueue] addPayment:payment];
      }
      else {
      //show appropriate message 
      }
   }

Are you testing on iPhone/iPad Simulator 4.2 or something? That might be the problem. Testing on iPhone/iPad Simulator 5.0, or the device, will run storekit correctly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!