-2

このアプリ内購入全体を機能させようとしていますが、いくつかの問題が発生しました。したがって、テスト ユーザー アカウントで機能を「購入」することはできますが、何度もテストしたいと思います。そのため、生成されたキーチェーンを削除してアプリを終了する削除メソッドを作成し、再度ビルドすると「無料」の状態に戻り、もう一度アプリを購入しようとしましたが、今回は「このアイテムは既に購入済みです。[OK] をタップして再度ダウンロードしてください」と表示されたので、[OK] をタップしましたが、今回は何も起こらず、機能のロックが解除されません。

コード:

 -(void)deleteKeyChain:(id)sender {

NSError *error = nil;
NSLog(@"delete!!!!");
[SFHFKeychainUtils deleteItemForUsername:@"someUser" andServiceName:kStoredData            error:&error];

 }

-(void)doFeature:(id)sender {
[newPlayer pause];
if ([self IAPItemPurchased]) {

    // do the feature 2!
   //       featureLabel.text = @"Feature: 2";

} else {
    // not purchased so show a view to prompt for purchase
    askToPurchase = [[UIAlertView alloc]
                     initWithTitle:@"All Features"
                     message:@"Tap refresh anytime to read latest 5 emails. To read all      emails with no ads and to continue reading in the background, please purchase the full version of this app."
                     delegate:self
                     cancelButtonTitle:nil
                     otherButtonTitles:@"OK",@"Later on", nil];
    askToPurchase.delegate = self;
    [askToPurchase show];
    [askToPurchase release];
     }
   }


   #pragma mark StoreKit Delegate

  -(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions     {
for (SKPaymentTransaction *transaction in transactions) {
    switch (transaction.transactionState) {
        case SKPaymentTransactionStatePurchasing:

            // show wait view here
         //        statusLabel.text = @"Processing...";
            break;

        case SKPaymentTransactionStatePurchased:

            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            // remove wait view and unlock feature 2
    //        statusLabel.text = @"Done!";
            UIAlertView *tmp = [[UIAlertView alloc]
                                initWithTitle:@"Complete"
                                message:@"You now have the full version of Emails Aloud!!"
                                delegate:self
                                cancelButtonTitle:nil
                                otherButtonTitles:@"Ok", nil];
            [tmp show];
            [tmp release];


            NSError *error = nil;
            [SFHFKeychainUtils storeUsername:@"someUser" andPassword:@"pass"   forServiceName:kStoredData updateExisting:YES error:&error];

            // apply purchase action  - hide lock overlay and
         //   [feature2Btn setBackgroundImage:nil forState:UIControlStateNormal];

            // do other thing to enable the features

            break;

        case SKPaymentTransactionStateRestored:
            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            // remove wait view here
            //    statusLabel.text = @"";
            break;

        case SKPaymentTransactionStateFailed:

            if (transaction.error.code != SKErrorPaymentCancelled) {
                NSLog(@"Error payment cancelled=%d",transaction.error.code);
            }
            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            // remove wait view here
         //   statusLabel.text = @"Purchase Error!";
            break;

        default:
            break;
        }
      }
    }






-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse   *)response
 {

   // remove wait view here
   // statusLabel.text = @"";

SKProduct *validProduct = nil;
int count = [response.products count];

if (count>0) {
    validProduct = [response.products objectAtIndex:0];
   [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
    SKPayment *payment = [SKPayment    paymentWithProductIdentifier:@"com.myapp.shit"];
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] addPayment:payment];


} else {
    UIAlertView *tmp = [[UIAlertView alloc]
                        initWithTitle:@"Not Available"
                        message:@"No products to purchase"
                        delegate:self
                        cancelButtonTitle:nil
                        otherButtonTitles:@"Ok", nil];
    [tmp show];
    [tmp release];
}


 }

  -(void)requestDidFinish:(SKRequest *)request
 {
[request release];
 }

-(void)request:(SKRequest *)request didFailWithError:(NSError *)error
{
 NSLog(@"Failed to connect with error: %@", [error localizedDescription]);
}
    -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

if (alertView==askToPurchase) {
    if (buttonIndex==0) {
        // user tapped YES, but we need to check if IAP is enabled or not.
        if ([SKPaymentQueue canMakePayments]) {

            SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"com.myapp.shit"]];

            request.delegate = self;
            [request start];


        } else {
            UIAlertView *tmp = [[UIAlertView alloc]
                                initWithTitle:@"Prohibited"
                                message:@"Parental Control is enabled, cannot make a  purchase!"
                                delegate:self
                                cancelButtonTitle:nil
                                otherButtonTitles:@"Ok", nil];
            [tmp show];
            [tmp release];
           }
       }
    }

}

注: someUser/pass は、誰のユーザー名/パスワードでもありません。これは、アプリ購入のユーザーをデバイスに登録するために選択した単なるテキストです。

4

1 に答える 1

1

すでに iTunes Connect ユーザーからユーザー/パスワードを使用してアプリケーションを購入している場合は、 を探す必要がありSKPaymentTransactionStateRestoredますSKPaymentTransactionStatePurchased

SKPaymentTransactionStatePurchased非消耗品の場合、ユーザーごとに 1 回だけ発生します。iTunes Connect でさらに多くのテスト ユーザーを作成してみてください。

于 2012-08-14T14:56:46.957 に答える