20111030i phonedeveloperworkshoppublished

2,619 views

Published on

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,619
On SlideShare
0
From Embeds
0
Number of Embeds
1,546
Actions
Shares
0
Downloads
6
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

20111030i phonedeveloperworkshoppublished

  1. 1. StoreKit 2011/10/30 saku2saku
  2. 2. - (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];! }}
  3. 3. #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];}
  4. 4. observer = [[ProductBuyingObserver alloc] init];! [[SKPaymentQueue defaultQueue] addTransactionObserver:observer]; or! [[SKPaymentQueue defaultQueue] addTransactionObserver: self];
  5. 5. - (void) pushBuyButton {! LOG_DEBUG(@"buy :%@", itemIdentifier);! SKPayment *payment = [SKPayment paymentWithProductIdentifier:itemIdentifier];! [[SKPaymentQueue defaultQueue] addPayment:payment];}
  6. 6. - (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;! ! }! }}
  7. 7. ! ! case 2:! ! {! ! ! if ([SKPaymentQueue canMakePayments]) {! ! ! ! [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;! ! ! ! [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];! ! ! } else {! ! ! ! UIAlertView *alertView = [[[UIAlertView alloc] init] autorelease];! ! ! ! [alertView show];! ! ! }! ! ! break;! ! }
  8. 8. - (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;! ! }! }}
  9. 9. - (void) paymentQueueRestoreCompletedTransactionsFinished: (SKPaymentQueue *) queue {! [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;! [alertView show];! LOG_DEBUG(@"method called!");}- (void) paymentQueue:(SKPaymentQueue *)queuerestoreCompletedTransactionsFailedWithError:(NSError *) error {! [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;! [alertView show];! LOG_DEBUG(@"method called!");}
  10. 10. {! "signature" = "AkWUo ";! "purchase-info" = "ewoJI ";! "environment" = "Sandbox";! "pod" = "100";! "signing-status" = "0";}
  11. 11. {! "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";}

×