In App Purchase sandbox not prompting for my login/pass

烂漫一生 提交于 2019-12-09 13:24:57

问题


We're developing an app which (ofcourse) uses in app purchases (IAP). I've done everything in the guide to enable iap and everything works fine, untill I want to make purchase.
Some of the code:

MainViewController.m

    -(void)viewDidLoad {
            if ([SKPaymentQueue canMakePayments]) {
                    MyStoreObserver *observer = [[MyStoreObserver alloc] init];     
                    [[SKPaymentQueue defaultQueue] addTransactionObserver:observer];        

                    SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObjects: @"com.company.app.product1", @"com.company.app.product1", nil]];
                    request.delegate = self;
                    [request start];
            }
    };

    -(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
            for (SKProduct *prod in response.products) {
                    NSLog(@"%@ (%@)", prod.localizedTitle, prod.price);
            }
            [request release];
    };

    -(IBAction)clickBuy:(UIButton *)__sender {
            SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.company.app.product1"];
            [[SKPaymentQueue defaultQueue] addPayment:payment];
    };

MyStoreObserver.m

    - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
        for (SKPaymentTransaction *transaction in transactions) {
            switch (transaction.transactionState) {
                case SKPaymentTransactionStatePurchased:
                    NSLog(@"SKPaymentTransactionStatePurchased");
                    break;
                case SKPaymentTransactionStateFailed:               
                    NSLog(@"SKPaymentTransactionStateFailed");
                    break;
                case SKPaymentTransactionStateRestored:
                    NSLog(@"SKPaymentTransactionStateRestored");
                    break;
                case SKPaymentTransactionStatePurchasing:
                    NSLog(@"SKPaymentTransactionStatePurchasing");
                default:
                    break;
            }
        }
    };

The productRequest: delegate method shows 2 products with their name / price. Like I entered in the iTunes connect site.

But once I click the 'buy' button, no dialog pops up or asks me for my credentials. Only "SKPaymentTransactionStatePurchasing" is logged.

And I:
- ... have logged out in the settings/store pane
- ... am using the right provisioning profiles
- ... am desperate

Anyone?


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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 
      }
   }



回答5:


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.



来源:https://stackoverflow.com/questions/8910631/in-app-purchase-sandbox-not-prompting-for-my-login-pass

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