1

MKStoreManagerを使用して、アプリケーションの1つにアプリの購入を実装しました。これで、Appleから新しいガイドラインを取得しました。アプリの購入を行う場合は、既に購入したアプリケーションを復元するためのオプションをユーザーに提供する必要があります。このように。「復元」ボタンをクリックすると、このメソッドが呼び出されます。

- (void) checkPurchasedItems
{
   [[SKPaymentQueue defaultQueue] addTransactionObserver:self]; 
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}

そしてここから、このメソッドが実行されます

- (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
    {
     NSMutableArray* purchasableObjects  = [[NSMutableArray alloc] init];

        NSLog(@"received restored transactions: %i", queue.transactions.count);
        for (SKPaymentTransaction *transaction in queue.transactions)
        {
            NSString *productID = transaction.payment.productIdentifier;
            [purchasableObjects addObject:productID];
        }

    }

しかし今、私はこの修復が機能しているかどうかをどのように確認できるのか疑問に思っています。誰かが私を案内してくれますか。事前に感謝します。

4

1 に答える 1

3

復元を実装する方法は次のとおりです

- (void)loadStore
{
// restarts any purchases if they were interrupted last time the app was open
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];

// get the product description (defined in early sections)
[self requestProUpgradeProductData];
}

- (void)requestProUpgradeProductData
{
NSSet *productIdentifiers = [NSSet setWithObject:kInAppPurchaseProUpgradeProductId];
productsRequest = [[SKProductsRequest alloc]     initWithProductIdentifiers:productIdentifiers];
productsRequest.delegate = self;
[productsRequest start];

// we will release the request object in the delegate callback
}

この後、このメソッドを呼び出します

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
NSArray *products = response.products;
proUpgradeProduct = [products count] == 1 ? [[products objectAtIndex:0] retain] : nil;
if (proUpgradeProduct)
{
NSLog(@"Product title: %@" , proUpgradeProduct.localizedTitle);
NSLog(@"Product description: %@" , proUpgradeProduct.localizedDescription);
NSLog(@"Product price: %@" , proUpgradeProduct.price);
NSLog(@"Product id: %@" , proUpgradeProduct.productIdentifier);
if ([self canMakePurchases]) {
    if ([self respondsToSelector:@selector(purchaseProUpgrade)]) {
        [self purchaseProUpgrade];
    }
}
else {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[self languageSelectedStringForKey:@"Error"] message:@"Cannot connect to Store.\n Please Enable the Buying in settings" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
    [alert show];
    [alert release];
}
}

for (NSString *invalidProductId in response.invalidProductIdentifiers)
{
[SVProgressHUD dismiss];
[cancelButton setEnabled:YES];
[buyNowButton setEnabled:YES];
[restoreButton setEnabled:YES];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Error occured" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];
NSLog(@"Invalid product id: %@" , invalidProductId);
}

// finally release the reqest we alloc/init’ed in requestProUpgradeProductData
[productsRequest release];
[[NSNotificationCenter defaultCenter]         postNotificationName:kInAppPurchaseManagerProductsFetchedNotification object:self userInfo:nil];
}
- (void)completeTransaction:(SKPaymentTransaction *)transaction
{
[self recordTransaction:transaction];
[self provideContent:transaction.payment.productIdentifier];
[self finishTransaction:transaction wasSuccessful:YES];
}
- (void)purchaseProUpgrade
{
[SVProgressHUD showInView:self.view status:[self languageSelectedStringForKey:@"Connecting Store"] networkIndicator:YES];
SKPayment *payment = [SKPayment     paymentWithProductIdentifier:kInAppPurchaseProUpgradeProductId];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
- (void)recordTransaction:(SKPaymentTransaction *)transaction
{
if ([transaction.payment.productIdentifier isEqualToString:kInAppPurchaseProUpgradeProductId])
{
// save the transaction receipt to disk
[[NSUserDefaults standardUserDefaults] setValue:transaction.transactionReceipt forKey:@"proUpgradeTransactionReceipt" ];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}

最後にこの方法

- (void)finishTransaction:(SKPaymentTransaction *)transaction wasSuccessful:        (BOOL)wasSuccessful
{
// remove the transaction from the payment queue.
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];

NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:transaction, @"transaction" , nil];
if (wasSuccessful)
{
//Write your transaction complete statement required for your project
}
于 2012-07-03T05:01:28.277 に答える