2012-03-07 8 views
-2

У меня есть приложение с покупкой inapp, я завершил кодовую часть inapp, есть кнопка покупки в моем диспетчере просмотра, когда пользователь нажимает эту кнопку, она проходит процесс оплаты, если полученная оплата является достаточной, мне просто нужно включить кнопку рядом с кнопкой buy.i получить предупреждение о том, что платеж будет успешным, если платеж будет достаточным, мне нужно включить кнопку, чтобы я был отключен раньше. в кнопке мышиПокупка Inapp в iphone sdk

if ([SKPaymentQueue canMakePayments]) { 
        // Yes, In-App Purchase is enabled on this device! 
        // Proceed to fetch available In-App Purchase items. 

        // Replace "Your IAP Product ID" with your actual In-App Purchase Product ID, 
        // fetched from either a remote server or stored locally within your app. 
        SKProductsRequest *prodRequest= [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject: @"com.mycompny.myproduct"]]; 
        prodRequest.delegate = self; 
        [prodRequest start]; 
        // Replace "Your IAP Product ID" with your actual In-App Purchase Product ID. 
        SKPayment *paymentRequest = [SKPayment paymentWithProductIdentifier: @"com.mycompny.myproduct"]; 

        // Assign an Observer class to the SKPaymentTransactionObserver, 
        // so that it can monitor the transaction status. 
        [[SKPaymentQueue defaultQueue] addTransactionObserver:inappObserver]; 

        // Request a purchase of the selected item. 
        [[SKPaymentQueue defaultQueue] addPayment:paymentRequest]; 

       } else { 
        // Notify user that In-App Purchase is disabled via button text. 
        [inappButton setTitle:@"In-App Purchase is Disabled" forState:UIControlStateNormal]; 
        inappButton.enabled = NO; 

мне нужно включить кнопку с именем _btnunlockfeature

в inapppurchaseobserver.m

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

      case SKPaymentTransactionStatePurchasing: 
       // Item is still in the process of being purchased 
       break; 

      case SKPaymentTransactionStatePurchased: 
       // Item was successfully purchased! 

       // --- UNLOCK FEATURE OR DOWNLOAD CONTENT HERE --- 
       // The purchased item ID is accessible via 
       // transaction.payment.productIdentifier 

       // After customer has successfully received purchased content, 
       // remove the finished transaction from the payment queue. 
       [[SKPaymentQueue defaultQueue] finishTransaction: transaction]; 
       break; 

      case SKPaymentTransactionStateRestored: 
       // Verified that user has already paid for this item. 
       // Ideal for restoring item across all devices of this customer. 

       // --- UNLOCK FEATURE OR DOWNLOAD CONTENT HERE --- 
       // The purchased item ID is accessible via 
       // transaction.payment.productIdentifier 

       // After customer has restored purchased content on this device, 
       // remove the finished transaction from the payment queue. 
       [[SKPaymentQueue defaultQueue] finishTransaction: transaction]; 
       break; 

      case SKPaymentTransactionStateFailed: 
       // Purchase was either cancelled by user or an error occurred. 

       if (transaction.error.code != SKErrorPaymentCancelled) { 
        // A transaction error occurred, so notify user. 
       } 
       // Finished transactions should be removed from the payment queue. 
       [[SKPaymentQueue defaultQueue] finishTransaction: transaction]; 
       break; 
     } 
    } 
} 

в приведенном выше коде

case SKPaymentTransactionStatePurchased: 
        // Item was successfully purchased! 

        // --- UNLOCK FEATURE OR DOWNLOAD CONTENT HERE --- 
        // The purchased item ID is accessible via 
        // transaction.payment.productIdentifier 

        // After customer has successfully received purchased content, 
        // remove the finished transaction from the payment queue. 
        [[SKPaymentQueue defaultQueue] finishTransaction: transaction]; 

я думаю, что здесь я хотите написать активированный код, этот код находится в NSobject не в sam e viewcontroller.please поможет мне это сделать.

+4

Итак, вы сумели написать в приложение код для совершения покупок и все остальное приложение, но вы не можете решить, как включить кнопку в представлении? –

+0

В чем проблема с button.enabled = YES/NO ??! Слава богу, он еще не устарел! –

+0

@Malek_Jundi вы сказали, что правильно, я знаю, как включить кнопку, но problewm: я просто хочу, чтобы не было сомнений в том, что если покупка завершена, она хочет включить эту кнопку, я ставлю nsuserdefault Bool, но я работаю только тогда, когда страница перезагружается. – stackiphone

ответ

0
// 
- (void)completeTransaction:(SKPaymentTransaction *)transaction 
{ 
    [self recordTransaction:transaction]; 
    [self provideContent:transaction.payment.productIdentifier]; 
    [self finishTransaction:transaction wasSuccessful:YES]; 

} 


- (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) 
    { 

     // send out a notification that we’ve finished the transaction 
     [[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerTransactionSucceededNotification object:self userInfo:userInfo]; 

      UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Content successfully purchased" message:nil delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil]; 
      [alert show]; 
      [alert release]; 
      count = 1; 

    } 
    else 
    { 
     // send out a notification for the failed transaction 
     [[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerTransactionFailedNotification object:self userInfo:userInfo]; 
    } 


} 



- (void)provideContent:(NSString *)productId 
{ 
    if ([productId isEqualToString:kInAppPurchaseProUpgradeProductId]) 
    { 
     // enable the pro features 
     // Save the Value stating user Did purchase Sound Pack 
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
     [defaults setBool:YES forKey:@"SoundPack"]; 
     [defaults synchronize]; 
    } 
} 

Я делаю это как this..Storing в NSUserDefaults ..и извлечения этого в ViewController

+0

где положить вышеуказанный код? – stackiphone

+0

, если вы хотите просто включить кнопку. Просто сохраните BOOL в NSuserDefaults ... и когда другой вид загрузится .. проверьте, что BOOL .. Если текущая загрузка кнопки ... в противном случае ... не загружайте ее .. – Shubhank

Смежные вопросы