StoreKit

    2011/10/30
    saku2saku
- (void)viewDidLoad {
! if ([SKPaymentQueue canMakePayments]) {

!   !
!   !  NSSet *itemIdentifiersSet = [NSSet setWithObjects:
!   !  ! ! ! ! ! ! !            ITEM_IDENTIFIER_1,ITEM_IDENTIFIER_2,
!   !  ! ! ! ! ! ! !            ITEM_IDENTIFIER_3,ITEM_IDENTIFIER_4,
!   !  ! ! ! ! ! ! !            ITEM_IDENTIFIER_5,
!   !  ! ! ! ! ! ! !            nil];
!   !  SKProductsRequest *request = [[SKProductsRequest alloc]
                      initWithProductIdentifiers:itemIdentifiersSet];
! !    request.delegate = self;
! !    [request start];
! } else {
! !    UIAlertView *alertView = [[[UIAlertView alloc] init]
autorelease];

! !     [alertView show];
! }
}
#pragma mark -
#pragma mark SKProductsRequestDelegate

-   (void) productsRequest:(SKProductsRequest *)request
!      didReceiveResponse:(SKProductsResponse *)response {
!    for (SKProduct *product in response.products) {
!    !   [itemIdentifiers addObject:product];
!    }
!    [request autorelease];
!    [loadingView removeFromSuperview];
!    [self.tableView reloadData];
}
observer = [[ProductBuyingObserver alloc] init];
! [[SKPaymentQueue defaultQueue] addTransactionObserver:observer];


                                 or
! [[SKPaymentQueue defaultQueue] addTransactionObserver: self];
-   (void) pushBuyButton {
!    LOG_DEBUG(@"buy :%@", itemIdentifier);
!    SKPayment *payment = [SKPayment paymentWithProductIdentifier:itemIdentifier];
!    [[SKPaymentQueue defaultQueue] addPayment:payment];
}
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:
(NSArray *)transactions {
! for (SKPaymentTransaction *transaction in transactions) {
! !    switch (transaction.transactionState) {
! !    ! case SKPaymentTransactionStatePurchasing:
             !//
! !     !   ! break;! ! ! !
! !     !   case SKPaymentTransactionStatePurchased:
               !
               //
! !     !   ! break;
! !     !   case SKPaymentTransactionStateFailed:
               !
               //
! !     !   ! break;
! !     !   case SKPaymentTransactionStateRestored:
               !
               //
!   !   !   ! break;
!   !   !   default:
!   !   !   ! break;
!   !   }
!   }
}
!   !   case 2:
!   !   {
!   !   ! if ([SKPaymentQueue canMakePayments]) {
!   !   ! ! [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
!   !   ! ! [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
!   !   ! } else {
!   !   ! ! UIAlertView *alertView = [[[UIAlertView alloc] init] autorelease];

! !     !   !   [alertView show];
! !     !   }

! !     !   break;
! !     }
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:
(NSArray *)transactions {
! for (SKPaymentTransaction *transaction in transactions) {
! !    switch (transaction.transactionState) {
! !    ! case SKPaymentTransactionStatePurchasing:
             !//
! !     !   ! break;! ! ! !
! !     !   case SKPaymentTransactionStatePurchased:
               !
               //
! !     !   ! break;
! !     !   case SKPaymentTransactionStateFailed:
               !
               //
! !     !   ! break;
! !     !   case SKPaymentTransactionStateRestored:
               !
               //
!   !   !   ! break;
!   !   !   default:
!   !   !   ! break;
!   !   }
!   }
}
- (void) paymentQueueRestoreCompletedTransactionsFinished: (SKPaymentQueue *) queue {
! [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

! [alertView show];
! LOG_DEBUG(@"method called!");
}




- (void) paymentQueue:(SKPaymentQueue *)queue
restoreCompletedTransactionsFailedWithError:(NSError *) error {
! [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

! [alertView show];
! LOG_DEBUG(@"method called!");
}
{
! "signature" = "AkWUo       ";
! "purchase-info" = "ewoJI        ";
! "environment" = "Sandbox";
! "pod" = "100";
! "signing-status" = "0";
}
{
!   "item-id" = "471702051";
!   "original-transaction-id" = "1000000010942512";
!   "purchase-date" = "2011-10-23 07:15:02 Etc/GMT";
!   "product-id" = "com.comitter.sampleapp.sample3";
!   "transaction-id" = "1000000010942512";
!   "quantity" = "1";
!   "original-purchase-date" = "2011-10-23 07:15:02 Etc/GMT";
!   "bid" = "com.comitter.sample2";
!   "bvrs" = "1.0";
}
20111030i phonedeveloperworkshoppublished

20111030i phonedeveloperworkshoppublished

  • 1.
    StoreKit 2011/10/30 saku2saku
  • 10.
    - (void)viewDidLoad { !if ([SKPaymentQueue canMakePayments]) { ! ! ! ! NSSet *itemIdentifiersSet = [NSSet setWithObjects: ! ! ! ! ! ! ! ! ! ITEM_IDENTIFIER_1,ITEM_IDENTIFIER_2, ! ! ! ! ! ! ! ! ! ITEM_IDENTIFIER_3,ITEM_IDENTIFIER_4, ! ! ! ! ! ! ! ! ! ITEM_IDENTIFIER_5, ! ! ! ! ! ! ! ! ! nil]; ! ! SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:itemIdentifiersSet]; ! ! request.delegate = self; ! ! [request start]; ! } else { ! ! UIAlertView *alertView = [[[UIAlertView alloc] init] autorelease]; ! ! [alertView show]; ! } }
  • 11.
    #pragma mark - #pragmamark SKProductsRequestDelegate - (void) productsRequest:(SKProductsRequest *)request ! didReceiveResponse:(SKProductsResponse *)response { ! for (SKProduct *product in response.products) { ! ! [itemIdentifiers addObject:product]; ! } ! [request autorelease]; ! [loadingView removeFromSuperview]; ! [self.tableView reloadData]; }
  • 12.
    observer = [[ProductBuyingObserveralloc] init]; ! [[SKPaymentQueue defaultQueue] addTransactionObserver:observer]; or ! [[SKPaymentQueue defaultQueue] addTransactionObserver: self];
  • 13.
    - (void) pushBuyButton { ! LOG_DEBUG(@"buy :%@", itemIdentifier); ! SKPayment *payment = [SKPayment paymentWithProductIdentifier:itemIdentifier]; ! [[SKPaymentQueue defaultQueue] addPayment:payment]; }
  • 14.
    - (void)paymentQueue:(SKPaymentQueue *)queueupdatedTransactions: (NSArray *)transactions { ! for (SKPaymentTransaction *transaction in transactions) { ! ! switch (transaction.transactionState) { ! ! ! case SKPaymentTransactionStatePurchasing: !// ! ! ! ! break;! ! ! ! ! ! ! case SKPaymentTransactionStatePurchased: ! // ! ! ! ! break; ! ! ! case SKPaymentTransactionStateFailed: ! // ! ! ! ! break; ! ! ! case SKPaymentTransactionStateRestored: ! // ! ! ! ! break; ! ! ! default: ! ! ! ! break; ! ! } ! } }
  • 15.
    ! ! case 2: ! ! { ! ! ! if ([SKPaymentQueue canMakePayments]) { ! ! ! ! [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; ! ! ! ! [[SKPaymentQueue defaultQueue] restoreCompletedTransactions]; ! ! ! } else { ! ! ! ! UIAlertView *alertView = [[[UIAlertView alloc] init] autorelease]; ! ! ! ! [alertView show]; ! ! ! } ! ! ! break; ! ! }
  • 16.
    - (void)paymentQueue:(SKPaymentQueue *)queueupdatedTransactions: (NSArray *)transactions { ! for (SKPaymentTransaction *transaction in transactions) { ! ! switch (transaction.transactionState) { ! ! ! case SKPaymentTransactionStatePurchasing: !// ! ! ! ! break;! ! ! ! ! ! ! case SKPaymentTransactionStatePurchased: ! // ! ! ! ! break; ! ! ! case SKPaymentTransactionStateFailed: ! // ! ! ! ! break; ! ! ! case SKPaymentTransactionStateRestored: ! // ! ! ! ! break; ! ! ! default: ! ! ! ! break; ! ! } ! } }
  • 17.
    - (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *) queue { ! [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; ! [alertView show]; ! LOG_DEBUG(@"method called!"); } - (void) paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *) error { ! [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; ! [alertView show]; ! LOG_DEBUG(@"method called!"); }
  • 19.
    { ! "signature" ="AkWUo "; ! "purchase-info" = "ewoJI "; ! "environment" = "Sandbox"; ! "pod" = "100"; ! "signing-status" = "0"; }
  • 20.
    { ! "item-id" = "471702051"; ! "original-transaction-id" = "1000000010942512"; ! "purchase-date" = "2011-10-23 07:15:02 Etc/GMT"; ! "product-id" = "com.comitter.sampleapp.sample3"; ! "transaction-id" = "1000000010942512"; ! "quantity" = "1"; ! "original-purchase-date" = "2011-10-23 07:15:02 Etc/GMT"; ! "bid" = "com.comitter.sample2"; ! "bvrs" = "1.0"; }